Skip to content

Latest commit

 

History

History
121 lines (94 loc) · 4.38 KB

Macro_Automatic_drawing.md

File metadata and controls

121 lines (94 loc) · 4.38 KB

Macro Automatic drawing

{{Macro |Name=Automatic drawing |Icon=Macro_Automatic_drawing.png |Description=This code generates a Drawing page with three orthographic views (front, top and right) aligned to each other, and an isometric view placed at the top right of the page. It calculates the scale based on the model size and space available on the sheet. The iso view is scaled to 2/3 of the ortho views. |Author=unknown |Version=1.0 |Date=2016-09-26 |FCVersion=All version using Drawing Workbench |Download=[https://www.freecadweb.org/wiki/images/0/08/Macro_Automatic_drawing.png ToolBar icon] }}

Description

This code generates a Drawing page with three orthographic views (front, top and right) aligned to each other, and an isometric view placed at the top right of the page. It calculates the scale based on the model size and space available on the sheet. The iso view is scaled to 2/3 of the ortho views. It uses the first-angle projection.

Usage

An object needs to be selected before launching the macro.

Limitations

  • Scale is not standard. You may need to change the views manually to a standard scale.
  • It only works with a single object (this is a limitation from the Drawing Workbench)
  • Needs to be modified to work for third-angle projection used in the US and Canada.

The script

ToolBar icon

Macro_Automatic_drawing.FCMacro

{{MacroCode|code=

import FreeCAD, Part, Drawing if len(Gui.Selection.getSelectionEx())>1: App.Console.PrintError("Warning: Only the first item is generate") if len(Gui.Selection.getSelectionEx())==0: App.Console.PrintError("Warning: Need to select one item") Piece=Gui.Selection.getSelectionEx()[0] App.activeDocument().addObject('Drawing::FeaturePage','AutoDrawing') App.activeDocument().AutoDrawing.Template = App.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape.svg' DH=20 DL=30 L=Piece.Object.Shape.BoundBox.XMax H=Piece.Object.Shape.BoundBox.ZMax P=Piece.Object.Shape.BoundBox.YMax Sc=(400-3DL)/(L+H) Sc2=(250-3DH)/(P+H) if Sc>Sc2 : Sc=Sc2 TopX=DL+ScL FrontX=DL+ScL RightX=2DL+ScL IsoX=2DL+Sc(L) TopY=DH+ScP RightY=DH+PSc FrontY=2DH+Sc(P+H) IsoY=2DH+ScP

print TopX,RightX,TopY,FrontY

#Create topView App.activeDocument().addObject('Drawing::FeatureViewPart','topView') App.activeDocument().topView.Source =Piece.Object App.activeDocument().topView.Direction = (0,0,1) App.activeDocument().topView.Rotation=180 App.activeDocument().topView.X = TopX App.activeDocument().topView.Y = TopY App.activeDocument().topView.ShowHiddenLines=True App.activeDocument().AutoDrawing.addObject(App.activeDocument().topView) App.activeDocument().topView.Scale = Sc #Create FrontView App.activeDocument().addObject('Drawing::FeatureViewPart','FrontView') App.activeDocument().FrontView.Source =Piece.Object App.activeDocument().FrontView.Direction = (0,-1,0) App.activeDocument().FrontView.Rotation=90 App.activeDocument().FrontView.Scale = Sc App.activeDocument().FrontView.X = FrontX App.activeDocument().FrontView.Y = FrontY App.activeDocument().FrontView.ShowHiddenLines=True App.activeDocument().AutoDrawing.addObject(App.activeDocument().FrontView) #Create RightView App.activeDocument().addObject('Drawing::FeatureViewPart','RightView') App.activeDocument().RightView.Source =Piece.Object App.activeDocument().RightView.Direction = (1,0,0) App.activeDocument().RightView.Scale = Sc App.activeDocument().RightView.X = RightX App.activeDocument().RightView.Y = RightY App.activeDocument().RightView.ShowHiddenLines=True App.activeDocument().AutoDrawing.addObject(App.activeDocument().RightView) #Create IsotView App.activeDocument().addObject('Drawing::FeatureViewPart','IsoView') App.activeDocument().IsoView.Source =Piece.Object App.activeDocument().IsoView.Direction = (1,1,1) App.activeDocument().IsoView.Rotation=60 App.activeDocument().IsoView.Scale = Sc*.6 App.activeDocument().IsoView.X = IsoX App.activeDocument().IsoView.Y = IsoY App.activeDocument().IsoView.ShowHiddenLines=True App.activeDocument().AutoDrawing.addObject(App.activeDocument().IsoView)

}}

Links

The forum Automatic drawing


documentation index > Macro Automatic drawing