CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ANSYS Meshing & Geometry (https://www.cfd-online.com/Forums/ansys-meshing/)
-   -   [DesignModeler] Macro / Script for automatic geometry import (https://www.cfd-online.com/Forums/ansys-meshing/119269-macro-script-automatic-geometry-import.html)

Allen Latt September 5, 2016 05:06

Thank you so much ,Kapi !
I will think about it.
:)

Quote:

Originally Posted by Kapi (Post 616182)
as suggested by PSYMN

so I suggest u to use other format firstly.
Secondly I am not sure if there is any function to replace your geometry file.
You may have to delete the old file and import the new one.

Kapi


Allen Latt September 5, 2016 05:08

Thanks Elketonis
I didn't know about it.
I will try for this.:)

Quote:

Originally Posted by elketonis (Post 616415)
Hi all,

I'm trying to import a .prt geometry file as multiple parts. They are currently being imported as only 1 part with 3 bodies.

I have identified several possible solutions -
1. I need to explode the imported geometry file in DM
2. Import multiple parts with named selections
3. Form a new part for each of the solid bodies

I have not been able to find a command for 1.

Using the import code:
Code:

...
newGeom = "D:/.....prt"
geometry1.SetFile(FilePath=newGeom)
geometry1.Edit()
geometry1.SendCommand(Command="""ag.m.NewSession (1);
ag.gui.CreateImport("D:\....1.prt");
agb.regen();
ag.gui.CreateImport("D:\....2.prt");
agb.regen();
ag.gui.CreateImport("D:\....3.prt");
agb.regen();""")

Creates imports that are not actual solid geometry since it's originally added as a material. Even when I change these manually to add frozen, none of the normal "import geometry" options are available, such as named selections etc.

I'm not sure how to use the
Code:

body1 = ag.fm.Body(ag.fm.BodyCount-1);
that Kapi posted. How do I call body1 to form a new part? Am completely unfamiliar with OOP and JScript.

Any help is appreciated... This is the last step holding me back from automation.


elketonis September 5, 2016 10:51

Thanks for the reply Kapi!

So, when I import a geometry file and UpdateFromCAD, I have one part with three bodies. What I need is three bodies as separate parts. I can import the three files separately (but I am not sure how to do this) or I can import the geometry file and then form a new part from each body, so that I end up with three parts and three bodies.

Do you know how to select body 1 and form a new part and select body 2 and form a new part in JScript? That should give me what I'm after.

Quote:

Originally Posted by Kapi (Post 616564)
you will not be able to "explode" in DM
bring in each geometry separately if u wish!

care to explain more what u want?


the code which I posted is used once you have regenerated your geometry as solid body.
Once created you can call the bodies and use functions on them.
What functions do u want to use?


Kapi September 5, 2016 20:51

you may try this code for exploding part after Regen.
All i could find was this code!
Code:

agTreeExplodePart();
Hope it works for you!

elketonis September 6, 2016 09:27

Selecting the part before exploding
 
Kapi,

When I try to run a script in DesignModeler with the command
Code:

agTreeExplodePart();
I get an error "object expected."

If I have the following geometry structure:
Part1
_Body1
_Body2
_Body3
How do I select the part that is to be exploded? I tried the select all bodies code
Code:

ag.gui.PickFilter(5, true);
ag.gui.SelectAll();
agTreeExplodePart();

and received the same error.

Also, I cannot use the following code
Code:

geometry1.SendCommand(Command="""ag.m.NewSession (1);
var imp1 = ag.b.Import("D:/....prt");
imp1.Name="Name";
imp1.Operation=ag.c.Frozen;
ag.b.Regen();""")

since I have a .prt file, and it needs to use the NX interface to generate the geometry. When the above script is run, it imports three empty bodies into the model. So my only option is to import one geometry file via WB script, updatefromCAD, and explode the part tree.

Kapi September 6, 2016 20:07

give object as Part1
may be try this then!

Code:

agTreeExplodePart(Part1);
I havent used this code so I am not 100% sure about it.

Luiz Pancini August 25, 2018 20:03

Quote:

Originally Posted by ICS (Post 445407)
Thanks for your help!

I understand that I cannot use the "journaling" for the DM. But I can call a JScript from the wokbench journal... so what i'm trying to do is:

WB journal:

system1 = GetSystem(Name="FFF")
geometry1 = system1.GetContainer(ComponentName="Geometry")
geometry1.SetFile(FilePath="C:...........x_t")
geometry1.Edit()
script = open('C:...............js', 'r')
geometry1.SendCommand(Command=script.read())

This code changes the .x_t geometry, opens the DM and runs the JScript file... but how would it be the JScript code to select all bodies in the geometry and form a single part?

I couldn't find how to read a JScript from the journal, your information has saved me, thanks!


All times are GMT -4. The time now is 08:10.