This repository was archived by the owner on Sep 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Python scripting
Ian edited this page Jan 29, 2016
·
12 revisions
The Python API is eventually intended to provide the full level of control afforded by the FreeCAD GUI. This wiki page is a place to put notes currently, but will hopefully evolve towards a proper API description.
Should provide at least the level of control as existing Drawing's Python interface. Would be nice to preserve compatibility with it, but I suspect that the document model is different enough that it won't be possible.
In App/AppDrawingPy.cpp:
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
insert("et|s")
No docs
export("Oet")
No docs
Views are manipulated through their properties. As an example (from https://github.com/gvoigt/freecad-storage-rack/blob/master/kitchen.FCMacro ):
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])