-
Notifications
You must be signed in to change notification settings - Fork 1
Python scripting
This wiki page is a place to put notes currently, but will hopefully evolve towards a proper API description.
Sample Macros Examples of macros using basic TechDraw functionality are located here: Samples
Currently, the plan is to not preserve API compatibility between the old Drawing and the new TechDraw modules. DrawViewSymbol may provide a basis for displaying Drawing module SVG.
Notes on converting Drawing macros to TechDraw
Compatibilty
Should provide at least the level of control as existing Drawing's Python interface, and is eventually intended to provide the full level of control afforded through the FreeCAD GUI.
Currently implemented in Python (doesn't include Properties):
- Hatch - App/DrawHatchPy.xml
- None
- Page - App/DrawPagePy.xml
- addView(DrawView) - Add a View to this Page
- getPageWidth() - Return the width of this page
- getPageHeight() - Return the height of this page
- getPageOrientation() - Return the orientation of this page
- ParametricTemplate - App/DrawParametricTemplatePy.xml
- drawLine - Draw a line
- GeometryCount - Number of geometry in template
- DrawViewPart - App/DrawViewPartPy.xml
- None
- DrawProjGroup - App/DrawProjGroupPy.xml
- addProjection(string projectionType) - Add a new Projection Item to this Group. Returns DocObj.
- removeProjection(string projectionType) - Remove specified Projection Item from this Group. Returns int number of views in Group.
- getItemByLabel(string projectionType) - return specified Projection Item
- DrawProjGroupItem - App/DrawProjGroupItemPy.xml
- None
-
- App/DrawSVGTemplatePy.xml
- None
-
- App/DrawTemplatePy.xml
- None
- DrawViewSection
- DrawViewAnnotation
- DrawViewDimension - App/DrawViewDimensionPy.xml
- None
- DrawViewSymbol - App/DrawViewSymbolPy.xml
- None
- DrawViewClip - App/DrawViewClipPy.xml
- addView(DrawView) - Add a View to this ClipView
- removeView(DrawView) - Remove specified View to this ClipView
- getChildViewNames() - get a list of the DrawViews in this ClipView
- DrawViewCollection - App/DrawViewCollectionPy.xml
- None
- Draw View - App/DrawViewPy.xml
- None
In App/AppDrawingPy.cpp:
-wf: the various "project" routines should move as is. They deal with 3D to 3D or 3D to string. They don't touch actual Drawings at all.
project("O!|O!")
[visiblyG0,visiblyG1,hiddenG0,hiddenG1] = project(TopoShape[,App.Vector Direction, string type])
-- Project a shape and return the visible/invisible parts of it.
projectEx("O!|O!")
[V,V1,VN,VO,VI,H,H1,HN,HO,HI] = projectEx(TopoShape[,App.Vector Direction, string type])
-- Project a shape and return the all parts of it.
projectToSVG("O!|O!sff")
string = projectToSVG(TopoShape[,App.Vector Direction, string type])
-- Project a shape and return the SVG representation as string.
projectToDXF("O!|O!sff")
string = projectToDXF(TopoShape[,App.Vector Direction, string type])
-- Project a shape and return the DXF representation as string.
removeSvgTags("s")
string = removeSvgTags(string) -- Removes the opening and closing svg tags
and other metatags from a svg code, making it embeddable`
In Gui/AppDrawingGuiPy.cpp:
open("et")
No docs
-wf: don't think TechDraw does this. Might use it to open old style Drawings?
insert("et|s")
No docs
-wf: believe this is almost equivalent to DrawViewSymbol with some Py code to get the SVG file from the OS.
export("Oet")
No docs
-wf: this is probably a good place to implement CmdTechDrawExportPage
Views are manipulated through their properties. As an example (from https://github.com/gvoigt/freecad-storage-rack/blob/master/kitchen.FCMacro ):
-wf: we can almost do this now. Rotation is an issue, as TechDraw rotates the View on the Page and Drawing rotates the Part?
doc.addObject('Drawing::FeaturePage','Page')
doc.Page.Template = App.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape_ISO7200.svg'
doc.addObject('Drawing::FeatureViewPart','ViewX')
doc.addObject('Drawing::FeatureViewPart','ViewY')
doc.addObject('Drawing::FeatureViewPart','ViewZ')
doc.addObject('Drawing::FeatureViewPart','ViewIso')
Views = [ doc.ViewX, doc.ViewY, doc.ViewZ, doc.ViewIso ]
ViewsDirection = [(1.0,0.0,0.0), (0.0,1.0,.0), (0.0,0.0,1.0), (1.0,-1.0,0.5)]
ViewsX = [ 460.0, -160.0, -160.0, -25.0]
ViewsY = [ -295.0, -295.0, 240.0, 375.0]
ViewsScale = [ 0.2, 0.2, 0.2, 0.1 ]
ViewsRotation = [ 90.0, 90.0, 0.0, 180.0 ]
ViewsHiddenL = [ True, True, True, True ]
for i in range(len(Views)):
Views[i].Source = doc.complete_rack
Views[i].Direction = ViewsDirection[i]
Views[i].X = ViewsX[i]
Views[i].Y = ViewsY[i]
Views[i].Scale = ViewsScale[i]
Views[i].Rotation = ViewsRotation[i]
Views[i].ShowHiddenLines = ViewsHiddenL[i]
doc.Page.addObject(Views[i])