How Do I Access Dependency Info

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
elsordo
Posts: 70
Joined: Sat Jan 30, 2016 6:34 am

How Do I Access Dependency Info

Post by elsordo »

I would like to traverse the dependency graph that is shown in the treeview of the combo view. I'm interested in ARCH related objects.

I know the information is there but how do I get to it? Is there a script that illustrates how to do it?

I created a simple model with four ARCH objects and looked at the document.xml file contained in the FCSTD file. The "objects" element contains the information I need. Here is the element

Code: Select all

    <Objects Count="4" Dependencies="1">
        <ObjectDeps Name="Line" Count="0"/>
        <ObjectDeps Name="Wall" Count="1">
            <Dep Name="Line"/>
        </ObjectDeps>
        <ObjectDeps Name="BuildingPart" Count="1">
            <Dep Name="Wall"/>
        </ObjectDeps>
        <ObjectDeps Name="BuildingPart001" Count="1">
            <Dep Name="BuildingPart"/>
        </ObjectDeps>
        <Object type="Part::Part2DObjectPython" name="Line" id="3680" />
        <Object type="Part::FeaturePython" name="Wall" id="3681" />
        <Object type="App::GeometryPython" name="BuildingPart" id="3682" />
        <Object type="App::GeometryPython" name="BuildingPart001" id="3683" />
    </Objects>
So, given a python object, how do I determine and traverse the dependency graph?

-David

The freecad version info is

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24267 (Git)
Build type: Release
Branch: master
Hash: b2ca86d8d72b636011a73394bf9bcdedb3b109b7
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United States (en_US)

I have also attached the model.
Attachments
SimpleArchHierarchy.FCStd
(16.25 KiB) Downloaded 74 times
walpa
Posts: 65
Joined: Wed Nov 09, 2016 5:22 pm
Location: Brazil

Re: How Do I Access Dependency Info

Post by walpa »

HI,
You can get all objects in the document using:

Code: Select all

import FreeCAD

for obj in FreeCAD.ActiveDocument.Objects:
    if hasattr(obj,"SomeProperty"):
        print(obj.SomeProperty)
greetings
elsordo
Posts: 70
Joined: Sat Jan 30, 2016 6:34 am

Re: How Do I Access Dependency Info

Post by elsordo »

Walpa,
There are plenty of examples for iterating over the objects in a document. What I cannot find is examples of how to determine the dependencies. That is, which objects are contained in a given object and what objects contain the current object.
-David
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: How Do I Access Dependency Info

Post by ickby »

Each object has a OutList and InList which gives you that information.
Did_Fr
Posts: 5
Joined: Fri Oct 01, 2021 1:03 pm

Re: How Do I Access Dependency Info

Post by Did_Fr »

Hello,

I have the exact same problem than elsordo, but when I look at the freecad documentation, it's said that "InList and OutList have nothing to do with the tree view of the document model that is presented in the GUI." (https://wiki.freecadweb.org/PropertyLin ... nd_OutList).

Does anyone know a way to find chidren or parent in the tree ?

Didier
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How Do I Access Dependency Info

Post by openBrain »

Did_Fr wrote: Fri Oct 01, 2021 1:36 pm Does anyone know a way to find chidren or parent in the tree ?
Children are returned by '.ViewObject.claimChildren()' called on the object.
Notice that it only works on GUI mode as tree is just not existing in CLI mode.
Did_Fr
Posts: 5
Joined: Fri Oct 01, 2021 1:03 pm

Re: How Do I Access Dependency Info

Post by Did_Fr »

Hello openBrain,

Thank you for your answer. I will try with this function.

I still think it's strange to use graphical interface to get structural information.

Didier
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: How Do I Access Dependency Info

Post by TheMarkster »

In the ViewObject is where the icon is managed, why not also the tree?

Probably is better to use InList and OutList because not all dependencies are claimed as children in all cases. For example, see Part refine shape copy. It claims nothing in the tree yet obviously has one dependency.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How Do I Access Dependency Info

Post by openBrain »

TheMarkster wrote: Sat Oct 02, 2021 12:34 am Probably is better to use InList and OutList because not all dependencies are claimed as children in all cases.
I agree. InList and OutList are the real topological "dependencies". But I have to admit they can be a bit inconvenient to manipulate when you only know FreeCAD from the GUI. You probably need more time and understanding of FreeCAD to use them proficiently.
For example, see Part refine shape copy. It claims nothing in the tree yet obviously has one dependency.
Just a precision here, Refine copy had become parametric during 0.19 development IIRC.
Did_Fr
Posts: 5
Joined: Fri Oct 01, 2021 1:03 pm

Re: How Do I Access Dependency Info

Post by Did_Fr »

Thank you to both of you. I begin to understand the difference between treeview and dependency graph.

I will work with the graph to make the script I need.
Post Reply