Writing a workbench 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:

Writing a workbench in Python

Post by onekk »

Hello to All.

I'm trying to write a workbench for freecad.

It scope is to import and visualize a file created by CamBam (a simple but powerful CAD CAM written in C#).


I've some problems:

I have found some tutorials and I've set up a skeleton for the workbench, but I'have not found a way to:

1) Add a Tab in teh ComBo View when I activate the workbench, so I can load the file and operate on it, as in this tab I've to lad the structure of the xml document and operate on it. (The scope is to visualize and copy the entity from and existing xml file to another xml file compatible with CamBam)

2) Access some python module outside the AppImage as outside Freecad the modules are accesible but in the Appimage the modules are reported as not found.

Running Devuan Linux (Debian Stretch without systemd) I could not find a package that fit my distribution (Ubuntu is supported but is slightly different from Debian, so the AppImage is the only viable solution)

I'm using FreeCAD 0.17 fAppImage downloaded from the official repository on github.

Many Thanks 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/
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Writing a workbench in Python

Post by onekk »

For the question number 2 I've tryied

Code: Select all

import sys
sys.path.append("/usr/lib/python2.7/dist-packages/")
but I wonder if there will be some conflicts in doing this?

I have resolved also the problem number 1.

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/
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Writing a workbench in Python

Post by sgrogan »

onekk wrote: Sun Sep 23, 2018 2:20 pm but I wonder if there will be some conflicts in doing this?
Could very well be. The AppImage uses Ubuntu 14.04 (Trusty) assets ie PY3.4

Some work being done in this regard here: https://forum.freecadweb.org/viewtopic. ... 4&start=30
"fight the good fight"
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Writing a workbench in Python

Post by onekk »

So there is a safe way to integrate the AppImage with the missing libraries?

I have some troubles finding the API documentation,

My actual problem is:

I have created my workbench

I have found the way to create a document and add the draft object to it, but:

1) how to activate the grid in the Draft view in the window, doing Draft.show(object) the object is shown but the grid is not and the object is not centered

2) there is a manner to obtain the API, looking maybe at the github sources?

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/
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Writing a workbench in Python

Post by onekk »

Ok Now I've managed to get the grid, using an hack:

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)
I wonder if there is a more clean manner.

The color of the grid is fixed or it could be changed in python?

And I've added a tab in the comboview, but i couldn't make it the tab on top (so it is viewable).

I have saved the widget in a variable and I thought it would be able to be retrieved with

Code: Select all

Comboview.IndexOf("widget saved")
but it gave an error about the original widget is destroyed.

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