Scripted Object documentation

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Scripted Object documentation

Post by Joel_graff »

So I've been toying with the idea of rewriting the scripted object documentation. https://www.freecadweb.org/wiki/Scripted_objects

What got me thinking about it was the 'basic example' at the very top of the page is a bit complex and appears outdated. It doesn't really match the actual linked file by @wmayer and relies heavily on coin-pivy manipulation, which is probably beyond most beginners who want to learn FeaturePython objects.

It also doesn't really explain how FeaturePython objects work in a way that helps someone who doesn't understand the concept of a scripted object - it took me a while to get my head wrapped around the fact that I wasn't creating a real object, per-se, as much as I was just dressing up another one... Nevermind the fact that property assignments (and how certain property types work) is a but of a mystery until you go digging in the forums or learn by trial and error.

That said, I think it could be much more valuable with some key changes, though I think it might require more than one page (I personally detest long webpages). In fact, I would propose two or possibly three: A page for the basic scripted object documentation, a page for recipes, and a page that details the use of object properties.

It would also be nice to change the title to include 'FeaturePython', to make it easier to find. I didn't realize it was there for a while because I never thought of them as 'Scripted Objects'.

Anyway, I don't mind at least drafting an outline of the content, but I'd like some input first before I put a lot of time into it. It's also a great opportunity to acquire some better examples / recipes from the forums or personal code, refine them, and make them available to the community.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Scripted Object documentation

Post by DeepSOIC »

Yes please. Please cover extensions if possible. (one of the major things about extensions I had to find out by trial-and-error, is that it's best to add extensions before assigning Proxy properties)
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Scripted Object documentation

Post by Joel_graff »

DeepSOIC wrote: Thu Mar 21, 2019 12:46 pm Yes please. Please cover extensions if possible. (one of the major things about extensions I had to find out by trial-and-error, is that it's best to add extensions before assigning Proxy properties)
Happily!

If you have examples, sample code, or links to better clarify what that should include, I'd appreciate it.

And I know @microelly2 would certainly have something to contribute to this...

The less I have to invent myself, the better. ;)
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Scripted Object documentation

Post by DeepSOIC »

Here I have an example of an object using AttachExtension, in Lattice2:
https://github.com/DeepSOIC/Lattice2/bl ... acement.py

It's messy. It has to be cleaned up to become an example.

Here, in Part-o-magic, Module container uses OriginGroupExtension. It's more self-contained, but still has to be cleaned up to become an example.
https://github.com/DeepSOIC/Part-o-magi ... /Module.py
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Scripted Object documentation

Post by Joel_graff »

DeepSOIC wrote: Thu Mar 21, 2019 1:23 pm Here, in Part-o-magic, Module container uses OriginGroupExtension. It's more self-contained, but still has to be cleaned up to become an example.
https://github.com/DeepSOIC/Part-o-magi ... /Module.py
Ok, so I took a look at it and have a basic understanding, but I haven't really dealt with these before, so this will be a good starting point for examples and use cases.

It also occurred to me, I have no idea just how many different Python scripted object types there are. I've used the Sketcher one, and Part / App::FeaturePython, but that's it.

Looks like documenting the unique features of each type of object, along with use cases seems like it will be in order. I'd like to distinguish examples from how they differ from a basic App::FeaturePython. That is, they basically implement the all same core methods / functions, but to use each one obvious requires a variance in the basic implementation.

Oh yeah... and ViewProviders.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Scripted Object documentation

Post by microelly2 »

I started an implementation of a wrapper for the core python objects.
There are some ideas to make the use more comfortable like hide/unhide property groups, add context menues the simple way and so on.
https://github.com/microelly2/freecad-n ... wb/pyob.py
I will write a little about all these things and how to use them.
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Scripted Object documentation

Post by Joel_graff »

microelly2 wrote: Thu Mar 21, 2019 3:08 pm I started an implementation of a wrapper for the core python objects.
There are some ideas to make the use more comfortable like hide/unhide property groups, add context menues the simple way and so on.
https://github.com/microelly2/freecad-n ... wb/pyob.py
I will write a little about all these things and how to use them.
That looks like a good starting point. I think maybe a tutorial in the wiki that steps through the essential elements to a scripted object - what they are and why they're there, that results in a complete 'starter' object would be useful.

Then maybe review other types like Part::FeaturePython, App::DocumentObjectPython, the extension object, the sketcher object, etc... and discuss how they vary, when they should be used, and so on. Think maybe showing how to use a scripted object to inherit / overload a standard FC object (like Part.Wire) would be handy, too.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Scripted Object documentation

Post by triplus »

Developer documentation is currently rather sparse. Improving it in any way therefore has my vote.
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Scripted Object documentation

Post by Joel_graff »

https://www.freecadweb.org/wiki/Feature ... nvironment

So I took the original page and copied it into a new one. I'm slowly rewriting it, so most of it is still the original content. However, you can get a feel for the direction I want to take things if you read the first couple of sections...
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Scripted Object documentation

Post by triplus »

Looking good!
Post Reply