Python Group list with pointers rather than names.

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Python Group list with pointers rather than names.

Post by keithsloan52 »

Okay when implementing a Part::FeaturePython or App::FeaturePython

I can add a group
newobj = existingObj.newObject("App::DocumentObjectGroupPython",name)

and can add objects to the list, but all names have to be unique within the document i.e. FreeCAD appends three digits to the end if not unique

Is there a way to create a list that just points to existing objects
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Python Group list with pointers rather than names.

Post by Joel_graff »

Not exactly sure what you mean, but it seems like:

Code: Select all

obj_list = []
obj_list.append(existingObj.newObject("App::DocumentObjectGroupPython",name))
would do it?
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
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Python Group list with pointers rather than names.

Post by keithsloan52 »

Will try to clarify

Trying to improve my handling of GDML materials.

Here is a screen shot of an example.
materials.png
materials.png (39.38 KiB) Viewed 679 times
If you look at the Element Enriched Uranium it has a list of two isotopes each with a fraction value if you expand each item.

The Isotopes in the Isotopes list each have their own properties,

At the moment the list for the Rnriched Uranium has names which FreeCAD has add a unique number so they don't duplicate
those in the Isotope list
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Python Group list with pointers rather than names.

Post by Kunda1 »

keithsloan52 wrote: Thu Apr 09, 2020 3:59 pm Element Enriched Uranium it has a list of two isotopes
Uhmmmmm :?

Image
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Python Group list with pointers rather than names.

Post by keithsloan52 »

Kunda1 wrote: Thu Apr 09, 2020 4:21 pm
keithsloan52 wrote: Thu Apr 09, 2020 3:59 pm Element Enriched Uranium it has a list of two isotopes
Uhmmmmm :?

Image
From a sample file, not who created.
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Python Group list with pointers rather than names.

Post by Joel_graff »

If I understand you correctly, then, you want to duplicate the isotopes in the sublist merely as links to the original objects, and not separate objects in themselves?
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
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Python Group list with pointers rather than names.

Post by keithsloan52 »

Joel_graff wrote: Thu Apr 09, 2020 6:31 pm If I understand you correctly, then, you want to duplicate the isotopes in the sublist merely as links to the original objects, and not separate objects in themselves?
Note quite.

The xml file being parsed has things like the following

Code: Select all

<isotope name="U235" Z="92"   N="235"> <atom type="A" value="235.01"/>
  </isotope>
  <isotope name="U238" Z="92.0" N="238"> <atom type="A" value="238.03"/>
  </isotope>
  <element name="enriched_Uranium">
   <fraction ref="U235" n="0.9"/>
   <fraction ref="U238" n="0.1"/>
  </element>
  <element name="Hydrogen" formula="H" Z="1."> <atom value="1.01"/>
  </element>
  <element name="Oxygen" formula="O" Z="8." N="8"> <atom value="16.0"/>
  <material name="Water" formula="H20">
   <D value="1.0"/>
   <composite n="2" ref="Hydrogen"/>
   <composite n="1" ref="Oxygen"/>
  </material>
  <material name="Air">
   <D value="1.290" unit="mg/cm3"/>
   <fraction n="0.7" ref="Nitrogen"/>
   <fraction n="0.3" ref="Oxygen"/>
  </material>
  
And I would like to create objlists for isotopes, elements and materials with sensible labels.
I have tried creating objects and then trying to update the label but with only limited success.
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Python Group list with pointers rather than names.

Post by Joel_graff »

Quick question:

Have you checked the "Allow duplicate object labels in one document" preference in General->Document->Document Objects?
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
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Python Group list with pointers rather than names.

Post by keithsloan52 »

Joel_graff wrote: Thu Apr 09, 2020 8:04 pm Quick question:

Have you checked the "Allow duplicate object labels in one document" preference in General->Document->Document Objects?
Thanks that is a good shout.

Will need to research if there is a way to check if the option is set when I run an export so that I can check whether to remove the appended numbers or not.
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Python Group list with pointers rather than names.

Post by keithsloan52 »

Joel_graff wrote: Thu Apr 09, 2020 8:04 pm Quick question:

Have you checked the "Allow duplicate object labels in one document" preference in General->Document->Document Objects?
Just tried setting the option. Restarted FreeCAD (freecad-daily) and the repeated names still have numbers appended.
Post Reply