Rebuild the FEM model

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Rebuild the FEM model

Post by bernd »

Each document object has property Name which is unique and can not be changed afterwards and property Label which is NOT unitque and which can be changed afterwards.

Each object can be accessed by

doc.Name whereas doc is inside FreeCAD App.ActiveDocument thus FreeCAD App.ActiveDocument.Name accesses a object.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Rebuild the FEM model

Post by vocx »

S-Y.Chen wrote: Wed Jun 03, 2020 3:28 am ...
App.ActiveDocument.examp104_01.Shape = App.ActiveDocument.getObjectsByLabel("examp104_02")[0].Shape

But I got the following error message :
AttributeError: 'App.Document' object has no attribute 'examp104_01'
...
It means the first object, on the left side, isn't actually named like that. Its Label is "examp104_01" but internally it is called something else. You can use the same method as in the right side to get the object by Label.

Code: Select all

App.ActiveDocument.getObjectsByLabel("examp104_01")[0].Shape = App.ActiveDocument.getObjectsByLabel("examp104_02")[0].Shape
The tree view displays the object label not the object name.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Rebuild the FEM model

Post by bernd »

bernd wrote: Wed Jun 03, 2020 6:23 am Each document object has property Name which is unique and can not be changed afterwards and property Label which is NOT unitque and which can be changed afterwards.

Each object can be accessed by

doc.Name whereas doc is inside FreeCAD App.ActiveDocument thus FreeCAD App.ActiveDocument.Name accesses a object.
in addition https://wiki.freecadweb.org/Property_ed ... properties
S-Y.Chen
Posts: 63
Joined: Tue Aug 27, 2019 4:33 pm

Re: Rebuild the FEM model

Post by S-Y.Chen »

Accessing the object by label works well. Thanks !

But If I am going to do all this in batch model, without viewing the label and attribute window, how do I get the label of the currently active FEM model/object ? And How do I get the label of the CAD/object I just imported on top of the original one ?

Thanks again.

Regards
Chen
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Rebuild the FEM model

Post by bernd »

S-Y.Chen wrote: Wed Jun 03, 2020 4:04 pm Accessing the object by label works well. Thanks !

But If I am going to do all this in batch model, without viewing the label and attribute window, how do I get the label of the currently active FEM model/object ? And How do I get the label of the CAD/object I just imported on top of the original one ?

Thanks again.

Regards
Chen
if you import by Python you do have an identifier to access the object. the Label of the current FEM gemetry you shoul know. BTW the name is not unique it is better to use the object Name to access a object by Python. Just give it a go and start.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Rebuild the FEM model

Post by bernd »

For me it is not 100 % sure what do you want. Would you like to do as much as possible with the Gui, or would you like to script the workflow?
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Rebuild the FEM model

Post by vocx »

bernd wrote: Wed Jun 03, 2020 7:25 pm For me it is not 100 % sure what do you want. Would you like to do as much as possible with the Gui, or would you like to script the workflow?
I think it's clear he wants to do this by a script. Like he wants to open, migrate the shape, and run the simulation.

Something like this.

Code: Select all

obj = import_something("document.FCStd")
App.ActiveDocument.OldObject.Shape = obj.Shape
FEM.run_simulation()
It really depends on how he named his original objects. If he only has a single solid body, maybe he can search the list of all Objects until he finds the one derived from Part::Feature, and replace its Shape with the imported object.

Code: Select all

the_one = None
for obj in App.ActiveDocument.Objects:
    if obj.isDerivedFrom("Part::Feature") and ...:  # other conditions to locate the right object
        the_one = obj
        break

new_obj = import_something("document.FCStd")
the_one.Shape = new_obj.Shape
FEM.run_simulation()
And yes, the Label is not technically unique, but it's fine in most situations because by default it is unique. If this is done in scripting without visual feedback, using the Name or Label is essentially the same.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Post Reply