Grid access in python

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Grid access in python

Post by onekk »

Writing a workbench I want to be able to access the draft View (but not the draft WorkBench) to draw some entities

I'm using FreeCAD 0.17 (from the official ApppImage)

I've managed after a long search to activate the draft workbench and show the grid with this code.

Code: Select all

	FreeCADGui.activateWorkbench("DraftWorkbench")
                
        Draft.setParam("alwaysShowGrid", True)
        Draft.setParam("gridSize",800)
        #Draft.setParam()
       
        FreeCADGui.SendMsgToActiveView("ViewFit")
        FreeCADGui.activeDocument().activeView().viewTop() 
        
        if hasattr(FreeCADGui,"Snapper"):
                
                FreeCADGui.Snapper.grid.on()
                FreeCADGui.Snapper.forceGridOff=False
                
        FreeCADGui.activateWorkbench(""MyWorkBench)
There is a more "clean manner" to do so, I'm usign the Draft workbench to draw the entities, but all the work is mean to visualize some graphic entities from a CAD-CAM application to use as a base for more refined work.

Plus there is a manner to change the grid color in python?

TIA and Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply