Macro Automatic drawing/it: Difference between revisions

From FreeCAD Documentation
(heading)
(Updating to match new version of source page)
Line 1: Line 1:
{{Macro|Icon=Text-x-python|Name=Automatic drawing|Description=This code allow the user to get the view of his object in a drawing with 4 different position(front,top,iso,right). Needs some modification to be perfectly effective.|Author=unknown}}
==Proiezioni Automatiche==


This code generates a [[Drawing Module|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.<br />
{{Macro/it|Icon=Text-x-python|Name=Automatic drawing|Name/it=Automatic drawing|Description=Questo codice consente di ottenere in un disegno 4 viste diverse dell'oggetto (anteriore, superiore, iso, destra). Ha bisogno di qualche modifica per essere completamente efficace.|Author=Normandc}}
It uses the [http://en.wikipedia.org/wiki/Multiview_orthographic_projection#First-angle_projection first-angle projection].


==== How to use ====
Questo codice genera una pagina di [[Drawing Module/it|Drawing]] ( Disegno) con tre viste ortogonali (frontale, dall'alto e laterale destra) allineate, più una vista isometrica posto in alto a destra della pagina. Calcola la scala basandosi sulle dimensioni del modello e sullo spazio disponibile nel foglio. La vista iso viene ridimensionata a 2/3 delle altre.
An object needs to be selected before launching the macro.


==== Limitations ====
Utilizza il [http://en.wikipedia.org/wiki/Multiview_orthographic_projection#First-angle_projection first-angle projection] ovvero il [http://en.wikipedia.org/wiki/Multiview_orthographic_projection#First-angle_projection Sistema di rappresentazione europeo].
* 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 [http://en.wikipedia.org/wiki/Multiview_orthographic_projection#Third-angle_projection third-angle projection] used in the US and Canada.


==== Utilizzo ====
==== The script ====


Prima di lanciare la macro è necessario selezionare un oggetto.


<syntaxhighlight>
==== Limitazioni ====


import FreeCAD, Part, Drawing
* La scala non è standard. Può essere necessario modificare manualmente la vista per adattarla ad una scala standard.
* Funziona solo con un singolo oggetto (questa è una limitazione del Modulo Drawing)
* Richiede delle modifiche per farla funzionare secondo il [http://en.wikipedia.org/wiki/Multiview_orthographic_projection#Third-angle_projection third-angle projection] ovvero il [http://en.wikipedia.org/wiki/Multiview_orthographic_projection#Third-angle_projection Sistema di rappresentazione americano] utilizzato negli Stati Uniti e in Canada.

==== La macro ====

<pre>import FreeCAD, Part, Drawing
if len(Gui.Selection.getSelectionEx())>1:
if len(Gui.Selection.getSelectionEx())>1:
App.Console.PrintError("Warning: Only the first item is generate")
App.Console.PrintError("Warning: Only the first item is generate")
Line 85: Line 83:
App.activeDocument().IsoView.Y = IsoY
App.activeDocument().IsoView.Y = IsoY
App.activeDocument().IsoView.ShowHiddenLines=True
App.activeDocument().IsoView.ShowHiddenLines=True
App.activeDocument().AutoDrawing.addObject(App.activeDocument().IsoView)</pre>
App.activeDocument().AutoDrawing.addObject(App.activeDocument().IsoView)


</syntaxhighlight>
{{languages/it | {{en|Macro_Automatic_drawing}} {{es|Macro_Automatic_drawing/es}} {{fr|Macro_Automatic_drawing/fr}} }}
{{clear}}
<languages/>

Revision as of 17:39, 25 December 2013

File:Text-x-python Automatic drawing

Description
This code allow the user to get the view of his object in a drawing with 4 different position(front,top,iso,right). Needs some modification to be perfectly effective.

Author: unknown
Author
unknown
Download
None
Links
Macro Version
1.0
Date last modified
None
FreeCAD Version(s)
None
Default shortcut
None
See also
None

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.

How to use

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

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-3*DL)/(L+H)
Sc2=(250-3*DH)/(P+H)
if Sc>Sc2 : 
   Sc=Sc2
TopX=DL+Sc*L
FrontX=DL+Sc*L
RightX=2*DL+Sc*L
IsoX=2*DL+Sc*(L)
TopY=DH+Sc*P
RightY=DH+P*Sc
FrontY=2*DH+Sc*(P+H)
IsoY=2*DH+Sc*P

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)