-
-
September 5, 2023 at 1:16 pm
Berker Yilmaz
Subscriber
I want to assign different materials to different objects, with a single command.Â
This is the command for assigning a material to an object:
oEditor.ChangeProperty(    [        "NAME:AllTabs",        [            "NAME:Geometry3DAttributeTab",            [                "NAME:PropServers",                "Object_1"            ],            [                "NAME:ChangedProps",                [                    "NAME:Material",                    "Value:="       , "Material_1"                ]            ]        ]    ])
I know that I can add other objects i.e. Object_2, Object_3 etc. to the "NAME:PropServers" part on script above. And "Material_1" will be assigned to multiple objects with a single command. Instead, I want to assign "Material_1" to "Object_1", and "Material_2" to "Object_2", and so on...Â
I have defined object and material name arrays to be assigned. But I have +1000 objects to assign, therefore running this command in a for loop result in a very long time of individual material assignment.
Is there any trick to make all assignments without a for loop on each object? -
September 7, 2023 at 12:57 pm
HDLI
Ansys EmployeeHello Berker,
   We could select all the objects that have same materail and assign material properties at one time, like:
   "NAME:PropServers",Â
   "object1","object2","object3",...
   Thus, we could use use a array here.
   I also suggest you to use pyaedt, that is open source in Github. https://github.com/ansys/pyaedt/releases
   or in https://aedt.docs.pyansys.com/version/stable/, that you could share or submit issues.
   Thanks.
HDLIÂ
Â
Â
Â
-
September 7, 2023 at 1:26 pm
Berker Yilmaz
SubscriberHello HDLI
Thank you for the reply, but I am afraid that is not the answer I was looking for.
As I explained on the question, I know it is possible to add other objects to "NAME:PropServers" section. But that would assign the same material to defined objects.
I want to define individual material definitions, such as material[index1], material[index2] etc. to control the material on each object seperately by indexes. ( There are 1000+ subdomain objects) And as i said, if I use a for loop, that takes a lot of time just for assigning materials.
-
-
September 7, 2023 at 1:45 pm
HDLI
Ansys EmployeeHello Berker,
   There are many loops to run about 1000+, you spend lots of time to assign materials because you want to assign one by one.
   If you group them to assign materials like above, you do not need to run many loops that could save time.
   Do you have 1000+ different materials? If Yes, it is what it is, and there is no way to skip it.
HDLI
-
September 7, 2023 at 1:55 pm
Berker Yilmaz
SubscriberI do not have 1000+ different materials, I only have 2 different materials. But I want to parametrize each object for either assigning or not assigning a certain material to it, and use optimetrics to utilize parallel simulation, for an emag topology optimization.
I also realized even if I assign materials with a for loop, there is a bigger problem. Optimetrics is not good at handling the 1000+ parameter sweep. The simulation slows a lot, I assume due to reading a lot of the variables.
I am not sure if there is any other easier way to do it on pyaedt?
-
-
- The topic ‘How to assign different materials to multiple objects at once in script’ is closed to new replies.
-
3492
-
1057
-
1051
-
965
-
942
© 2025 Copyright ANSYS, Inc. All rights reserved.