Manipulating InList and OutList

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Hermit
Posts: 27
Joined: Sat Sep 30, 2017 12:00 am
Location: Victoria, Canada
Contact:

Manipulating InList and OutList

Post by Hermit »

I have two FeaturePython classes: Box and BoxDimensions.

I'd like to make BoxDimensions part of Box's InList. I've search high and low for a method of doing this in the Wiki, API docs, and forums, and have only found ways to read and iterate InList/OutList, but not how to write/insert/append to these lists.

The intuitive way, obj.InList.append(sobj) doesn't work.

Since I'm now delving into application code to try to find an answer, I figured I should ask in here to try and save some time.

Does anyone know what the appropriate API calls to modify InList and OutList are?
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Manipulating InList and OutList

Post by Chris_G »

I think all the *List properties need to be set "as a whole".
append(), extend(), ... don't work directly :

Code: Select all

tmpList = myObj.InList
tmpList.append(item)
myObj.InList = tmpList
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Manipulating InList and OutList

Post by onekk »

Chris_G wrote: Thu Mar 11, 2021 8:18 am I think all the *List properties need to be set "as a whole".
append(), extend(), ... don't work directly :

Code: Select all

tmpList = myObj.InList
tmpList.append(item)
myObj.InList = tmpList
They are stored internally as tuples?

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
Hermit
Posts: 27
Joined: Sat Sep 30, 2017 12:00 am
Location: Victoria, Canada
Contact:

Re: Manipulating InList and OutList

Post by Hermit »

I get an error trying to set the list directly:

Code: Select all

>>> il = obj.InList
>>> il.append(sobj)
>>> obj.InList = il
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: Attribute 'InList' of object 'DocumentObject' is read-only
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Manipulating InList and OutList

Post by wmayer »

You cannot directly manipulate the InList and OutList of a feature because this is a collection of all link properties used by the features and you can't know which link properties to modify in the end.

The OutList gives you the features a given feature depends on and it must have a link property of a sub-type of PropertyLinkBase. The InList gives you the features that depend on the given feature.

So, you can only indirectly modify the InList/OutList by manipulating the corresponding link properties of the features.
User avatar
Hermit
Posts: 27
Joined: Sat Sep 30, 2017 12:00 am
Location: Victoria, Canada
Contact:

Re: Manipulating InList and OutList

Post by Hermit »

Hello wmayer, Thank you for your prompt reply.

I was also looking at the link properties and wasn't sure what role they played in the dependency graph. I will experiment with these a bit more. Where's the best place to find documentation for them? I find the wiki and forums to be a bit sparse at best, and these seem like core features...

Would you allow a relative newcomer like me to help update the documentation or contribute a mini-tutorial once I've uncovered a solution?
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Manipulating InList and OutList

Post by Chris_G »

Oops, sorry for the mis-information.
I have never used InList / OutList specifically and thought they were simply behaving like other *List properties. :oops:
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Manipulating InList and OutList

Post by onekk »

No problem, it was only curiosity (not the lander on Mars).

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: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Manipulating InList and OutList

Post by onekk »

Hermit wrote: Thu Mar 11, 2021 9:14 am Hello wmayer, Thank you for your prompt reply.

I was also looking at the link properties and wasn't sure what role they played in the dependency graph. I will experiment with these a bit more. Where's the best place to find documentation for them? I find the wiki and forums to be a bit sparse at best, and these seem like core features...

Would you allow a relative newcomer like me to help update the documentation or contribute a mini-tutorial once I've uncovered a solution?
Maybe a real case will be useful.

Some code with one can work on to test some solutions, in many other "help forums" they ask for a MWE (Minimal Working Example) or to be more precise:

A minimal unworking example and some information about:

1) what you intend to achieve
2) how the actual solution is wrong or subotpimal
3) what you expect the program will do

In this manner and with a MWE someone could test and maybe find a solution

This post is not to criticize, only to help to find a solution.

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
Hermit
Posts: 27
Joined: Sat Sep 30, 2017 12:00 am
Location: Victoria, Canada
Contact:

Re: Manipulating InList and OutList

Post by Hermit »

My original post answers these three points.

I have two FeaturePython classes, Box and BoxDimension. I would like BoxDimension's InList to contain a Box object. Similarly, I would like Box's OutList to contain the corresponding BoxDimension object.

Maybe I had the semantics for InList and OutList reversed in my OP, but this entirely describes the conditions that I am trying to achieve.
Post Reply