Scripting Sketcher and Spreadsheet

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
OakLD
Posts: 131
Joined: Fri Jan 12, 2018 7:38 pm
Location: Brno

Scripting Sketcher and Spreadsheet

Post by OakLD »

Hello,

pardon my greenishness, I browsed tons of docs and the forum, but haven't been able to find more info about this specific procedure.

I'd like to add a spreadsheet to a model using Python, uset this spreadsheet to parametrically drive sketch, which would make pocket features. Nothing serious, I'm just fiddling around to explore possibilities for contribution to FC. I followed Spreadsheet_Create documentation and tried:

Code: Select all

import Spreadsheet
mySpreadsheet = Spreadsheet.makeSpreadsheet()
...however the 2nd command results in an error:

Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'module' object has no attribute 'makeSpreadsheet'


When I list the Spreadsheet class, I see nothing usable for working with spreadsheets:
FCspreadsheet.PNG
FCspreadsheet.PNG (7.83 KiB) Viewed 1938 times

Analogically, similar happens with importing Sketcher. With a difference, that I haven't been able to find a single line about scripting sketches...

Am I doing something wrong? Or is support of Python for those removed and the 'makeSpreadsheet' is not exposed anymore?
Regards,

Oak
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Scripting Sketcher and Spreadsheet

Post by ulrich1a »

OakLD wrote: Thu Mar 29, 2018 2:44 pm I'd like to add a spreadsheet to a model using Python,
There is little information about python commands related to spreadsheets. The one you found is from an now not used spreadsheet module.
Here is a link to some forum posts with python code, used in the beginning to test the actual spreadsheet functionality.

https://forum.freecadweb.org/viewtopic. ... =30#p79461

But I did not use python to create sketches with constraints. Others have to answer this part. You may look here: https://forum.freecadweb.org/viewtopic.php?f=22&t=27554

Ulrich
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Scripting Sketcher and Spreadsheet

Post by DeepSOIC »

Code: Select all

import Spreadsheet
sheet = App.ActiveDocument.addObject("Spreadsheet::Sheet")
User avatar
OakLD
Posts: 131
Joined: Fri Jan 12, 2018 7:38 pm
Location: Brno

Re: Scripting Sketcher and Spreadsheet

Post by OakLD »

Thanks for both answers, that set me back on track, the spreadsheet did work. The Sketcher analogy dindn't, but I was able to locate this fraction of a code in sourcecodes in Hexagon.py and it works this way:

Code: Select all

sketch = App.ActiveDocument.addObject("Sketcher::SketchObject")
Hopefully this will keep me going some time... :-)
Regards,

Oak
User avatar
OakLD
Posts: 131
Joined: Fri Jan 12, 2018 7:38 pm
Location: Brno

Re: Scripting Sketcher and Spreadsheet

Post by OakLD »

Added this tiny bit of information to the Spreadsheet_Workbench WIKI.
Regards,

Oak
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Scripting Sketcher and Spreadsheet

Post by Kunda1 »

OakLD wrote: Thu Mar 29, 2018 4:31 pm Added this tiny bit of information to the Spreadsheet_Workbench WIKI.
Thanks for add in that to the wiki. Can you put it in a code box and also comment it explaining what each line does?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
OakLD
Posts: 131
Joined: Fri Jan 12, 2018 7:38 pm
Location: Brno

Re: Scripting Sketcher and Spreadsheet

Post by OakLD »

Kunda1 wrote: Thu Mar 29, 2018 4:37 pm Thanks for add in that to the wiki. Can you put it in a code box and also comment it explaining what each line does?
Sure I can, I'll do that. I was confused by a missing panel and no mentioning of code blocks in the basic wiki help page for a moment, but then I saw code blocks elsewhere and thought I'll have to get back and edit it. Sorry for that, now I'll remember :-)
Regards,

Oak
Post Reply