Unsing Python Features

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
jacknotrealy
Posts: 1
Joined: Tue Dec 08, 2009 8:44 am

Unsing Python Features

Post by jacknotrealy »

hi to all.

I am working on a FreeCAD workbench. I would like to create some own "Python Features".
there are a lot of questions. before i post a list i would like to ask if there are more informations for "Python Features"?
a Trial is done. the only information i found is "src/Mod/TemplatePyMod/FeaturePython.py" on the web.

Cheers, Jack - not really
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Unsing Python Features

Post by jriegel »

At the moment we have no end user docu for such deep integrated stuff.
src/Mod/TemplatePyMod/
is the right place to look. Its a whole FreeCAD module made out of python.

Further questions you can ask on this forum..
Stop whining - start coding!
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Unsing Python Features

Post by yorik »

We actually have this page too:
http://sourceforge.net/apps/mediawiki/f ... ed_objects
But basically it is simply a copy of the file you referred to.
I used a python feature inside the Draft module too, to make dimensions. (Look into src/Mod/Draft/Draft.py at line 604, where the python feature is defined, and at line 1459, where it called from the dimension tool)
Feel free to ask questions here, and if you learn more about the python features, feel very welcome to edit and improve the wiki page above ;)

EDIT: this thread could also interest you: viewtopic.php?f=3&t=166
Jack - not really

Re: Using Python Features

Post by Jack - not really »

thanks for your answers.

I will familiarize myself first in the general features.
But here are my first questions:
1) properties (in Editor) sorted according to the sequence in the creation PY-script (not alphabetically)
2) Parameters of the addProperty () function => addProperty (C-Type,NameToCreate,Group,Hint,int???,Readonly,Boolean????).NametoCreate=python Var => what is int? and the last Boolean?
3) A feature will create a set of other features? (linking between features) => when recompute a feature -> child features have do be recompute
4) deleting a Shape (created by a feature) -> automatic delete the associated feature(s) (if shape <-> feature are 1:1) ?
5) optional -> deleting Shapes -> delete associated feature(s) => maybe nonsense???
6) maybe nonsense, but is it possible to display something else (name) for the property. For power users this is nonsense (because property name and python varname different) , but for normal users?? for translations?

Some ask for the Application Tree => left side "Tree view"
1) is it possible to attach (display) a feature under a Group or subgroup entry?
2) Is it possible to attach (display) Shape(s) under a feature?

Cheers, Jack - not really
jacknotreally
Posts: 75
Joined: Mon Dec 14, 2009 9:49 am

Re: Using Python Features

Post by jacknotreally »

Jack - not really wrote:thanks for your answers.

I will familiarize myself first in the general features.
But here are my first questions:
1) properties (in Editor) sorted according to the sequence in the creation PY-script (not alphabetically)
2) Parameters of the addProperty () function => addProperty (C-Type,NameToCreate,Group,Hint,int???,Readonly,Boolean????).NametoCreate=python Var => what is int? and the last Boolean?
DONE => 3) A feature will create a set of other features? (linking between features) => when recompute a feature -> child features have do be recompute
Maybe not the right way. I have attached a App::PropertyPythonObject that holds the Parent-Feature
OBSOLETE
4) deleting a Shape (created by a feature) -> automatic delete the associated feature(s) (if shape <-> feature are 1:1) ?
5) optional -> deleting Shapes -> delete associated feature(s) => maybe nonsense???
6) maybe nonsense, but is it possible to display something else (name) for the property. For power users this is nonsense (because property name and python varname different) , but for normal users?? for translations?

Some ask for the Application Tree => left side "Tree view"
DONE => 1) is it possible to attach (display) a feature under a Group or subgroup entry?
2) Is it possible to attach (display) Shape(s) under a feature?
I can only add a shape by: feature = doc.addObject("Part::Feature", ShapeName) / feature.Shape = Shape
if i use a addProperty("Part::PropertyPartShape","Shape","QS", "Shape"), i can store the shape, but do not know, how to display it


Cheers, Jack - not really
wmayer
Founder
Posts: 20310
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Unsing Python Features

Post by wmayer »

Hi,
1) properties (in Editor) sorted according to the sequence in the creation PY-script (not alphabetically)
The entries in the property editor are sorted alphabetically. But many of them are part of a group, inside this group they are also sorted.
2) Parameters of the addProperty () function => addProperty (C-Type,NameToCreate,Group,Hint,int???,Readonly,Boolean????).NametoCreate=python Var => what is int? and the last Boolean?
The Int declares the behaviour of the property.
0 == None
1 == not used for dynamic properties
2 == Transient (Doesn't get stored to the project file. It's used for properties that get computed at run-time and where it makes no sense to make persistent)
4 == not used for dynamic properties
8 == Output (This marks the property as "output". This can be used for properties which if modified don't mark the object as touched and thus avoid a recompute of it once the document gets updated)
These values can be OR'ed.

The last Boolean means that the property is "Hidden" which means that it doesn't appear in the property editor. This for instance makes sense if the property is the result of something and stored in a long string and this string shouldn't be visible & editable in the editor.
5) optional -> deleting Shapes -> delete associated feature(s) => maybe nonsense???
Associated features are *not* deleted, only the reference is set to null.
6) maybe nonsense, but is it possible to display something else (name) for the property. For power users this is nonsense (because property name and python varname different) , but for normal users?? for translations?
For the moment there is no further information displayed to the user. Power users almost use the python console anyway.
1) is it possible to attach (display) a feature under a Group or subgroup entry?
You can manually (or via python) create a group item and drag and drop the object into there.
2) Is it possible to attach (display) Shape(s) under a feature?
I'm note quite sure what do you mean here. But for own feature types you can add whatever properties you want. You simply have to adjust the implementation of your view provider class to display these additional properties.

Werner
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Unsing Python Features

Post by jriegel »

Some thoughts from my side:
The property names itself shut/can not be translated.
First of all they stored that way in the document file. That would prevent loading with
different language.

The property editor is a tool for power user. They can see and use the properties of a object
directly, and with the same name in the python interpreter.

The end user sees most likely not much of that. He gets nursed by the commands
and dialogs which fill the properties. The LinkProperty is filled e.g. out of the
selection and other properties result out of the workflow.

So accesing properies directly shut be not neccesary for the end user.....
If nothing goes wrong ;)

In that case its important the objects and property have a worldwide
unique name. Otherwise no one could interpret a log file or a send
document!
Stop whining - start coding!
jacknotreally
Posts: 75
Joined: Mon Dec 14, 2009 9:49 am

Re: Using Python Features

Post by jacknotreally »

Hi Jürgen,
In that case its important the objects and property have a worldwide
unique name. Otherwise no one could interpret a log file or a send
document!
I agree with you. It has become clear during work.

Cheers, Jack - not really
Post Reply