I have thought that it will work, so I've put together this code to show the control points:
Code: Select all
import FreeCAD
import FreeCADGui
import Sketcher
import Part
from FreeCAD import Vector, Rotation
DOC_NAME = "test_sketch"
DOC = FreeCAD.activeDocument()
# CMPN_NAME = "Components"
# DOC.addObject("App::DocumentObjectGroup",CMPN_NAME)
def clear_doc():
"""
Clear the active document deleting all the objects
"""
for obj in DOC.Objects:
DOC.removeObject(obj.Name)
if DOC is None:
FreeCAD.newDocument(DOC_NAME)
FreeCAD.setActiveDocument(DOC_NAME)
DOC = FreeCAD.activeDocument()
VIEW = FreeCAD.Gui.ActiveDocument.ActiveView
else:
clear_doc()
VIEW = FreeCAD.Gui.ActiveDocument.ActiveView
def setview():
"""Rearrange View"""
DOC.recompute()
VIEW.viewAxometric()
VIEW.setAxisCross(True)
VIEW.fitAll()
# BSPLINE
p1 = Vector(-371.377228,250.588409,0)
p2 = Vector(-381.755615,175.192322,0)
p3 = Vector(-346.957428,157.182724,0)
p4 = Vector(-320.400909,212.432480,0)
p5 = Vector(-330.474060,269.513733,0)
spline = Part.BSplineCurve([p1, p2, p3, p4, p5],None,None,False,3,None,False)
sk = DOC.addObject('Sketcher::SketchObject','Sketch')
sk.Placement = App.Placement(App.Vector(0.000000, 0.000000, 0.000000), App.Rotation(0.000000, 0.000000, 0.000000, 1.000000))
FreeCADGui.ActiveDocument.setEdit(sk.Name)
sk.addGeometry(spline, False)
# Sketcher magic function :
sk.exposeInternalGeometry(0)
DOC.recompute()
#print(dir(sk))
#FreeCADGui.Selection.addSelection(DOC.Name,sk.Name)
VIEW.viewTop()
VIEW.setAxisCross(True)
#VIEW.fitSelection()
the result is:
Now from the code above, i have tried to select the shape and then show (fit selection), but I haven't found a way to visualize the curve with the control points in "edit mode" enlarged to fit the screen:
sadly a:
Code: Select all
print(dir(FreeCADGui.ActiveDocument.ActiveView)
So I have some questions about sketcher:
1) how to select the curve and fit it to the screen
2) eventually toggle the grid off?
TIA and Regards
Carlo D.