A first example to use Sketcher::SketchObjectPython
A Sketch which computes some objects on base of its inner geometry.
https://youtu.be/U31O5vW4UhI
How to extend an part class inside python?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
- microelly2
- Veteran
- Posts: 4688
- Joined: Tue Nov 12, 2013 4:06 pm
- Contact:
Re: How to extend an part class inside python?
wow no rain on weekends for nearly two years
Re: How to extend an part class inside python?
Hi, I am trying to figure out how this works and the possibilities.
(Microelly2 has a number of examples which are currently too advanced for me to understand )
Just have a question in the meantime:
If there is already a sketch done and I want to extend this sketches with features in a Sketcher::SketchObjectPython e.g. the feedback sketch Microelly2 ...
- is that a way to 'upgrade' this sketch?
- or need to 'copy' all the content of this sketch (geometries - normal and construction, constraints - driving and non-driving, expressions etc.) to the new Sketcher::SketchObjectPython object?
I hope my question make sense at all
Thanks !
(Microelly2 has a number of examples which are currently too advanced for me to understand )
Just have a question in the meantime:
If there is already a sketch done and I want to extend this sketches with features in a Sketcher::SketchObjectPython e.g. the feedback sketch Microelly2 ...
- is that a way to 'upgrade' this sketch?
- or need to 'copy' all the content of this sketch (geometries - normal and construction, constraints - driving and non-driving, expressions etc.) to the new Sketcher::SketchObjectPython object?
I hope my question make sense at all
Thanks !
- microelly2
- Veteran
- Posts: 4688
- Joined: Tue Nov 12, 2013 4:06 pm
- Contact:
Re: How to extend an part class inside python?
It is possible to copy the content of a sketch to a new/empty SketchPythonObject and then use the methods of this python object.paullee wrote: ↑Fri Jan 12, 2018 1:01 pm Hi, I am trying to figure out how this works and the possibilities.
(Microelly2 has a number of examples which are currently too advanced for me to understand )
Just have a question in the meantime:
If there is already a sketch done and I want to extend this sketches with features in a Sketcher::SketchObjectPython e.g. the feedback sketch Microelly2 ...
- is that a way to 'upgrade' this sketch?
- or need to 'copy' all the content of this sketch (geometries - normal and construction, constraints - driving and non-driving, expressions etc.) to the new Sketcher::SketchObjectPython object?
I hope my question make sense at all
Thanks !
I do this when I get common sketches and want to add functionality. So old sketches can be reused.
I don't know whether it is possible to upgrade a sketch.
Re: How to extend an part class inside python? [EDIT]
Many thanks!microelly2 wrote: ↑Fri Jan 12, 2018 2:16 pm
It is possible to copy the content of a sketch to a new/empty SketchPythonObject and then use the methods of this python object.
I do this when I get common sketches and want to add functionality. So old sketches can be reused.
I don't know whether it is possible to upgrade a sketch.
A few more questions when I explore a little bit more...
- Following Wmayer's example code https://forum.freecadweb.org/viewtopic. ... 29#p103443 but when it come to App.ActiveDocument.ActiveObject.ViewObj.... the 'ViewObject' is not auto-completed. Seem it is not there but input the whole code return no error. No idea what does it imply.
- I haven't found a method (other than sketch.addCopy... ) to copy all 'contents' from a sketch to another, any exist?
- One of the problem is copying expressions, e.g.:
Sketch A <--- Sketch B has expressions linked to Sketch A
Now,
New 'Sketch A content SketchPythonObject' <--- New 'Sketch B content SketchPythonObject'
Then, all the expressions in original Sketch B needs to 're-interpret' to new 'Sketch A SkethPythonObject' ! - Another problem seems within objects other than Arch. Arch Object (all or mostly?) has a Source property - if Sketch A become Sketch A content SketchPythonObject, the parent 'Source' could now linked to the new object I guess. With Part object like extrusion, it seem it can't.
...
- Original Sketch A (not SketchPythonObject) (full of geometries, expressions, constraints...)
- New 'Sketch X SketchPythonObject' ---> Python 'manipulate the content' of Sketch A (instead of 'geometries' in Sketch X SketchPythonObject)
- So no 'transfer' needed, dependencies on original Sketch A needs not be tracked down and changed...
- (or does it need to be 'SketchPythonObject' at all if after all possible?)
- (and will it be a problem if Sketch A is updated, how 'python in SketchX know... and execute code?...break other parents recompute process?'...
Too many questions...!