CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   ANSYS Meshing & Geometry (http://www.cfd-online.com/Forums/ansys-meshing/)
-   -   [DesignModeler] Designmodeler java scripting (http://www.cfd-online.com/Forums/ansys-meshing/130382-designmodeler-java-scripting.html)

Herbert2014 February 25, 2014 06:44

Designmodeler java scripting
 
Hello,
i´m new in the cad-world and haven´t got a lot of experiences with java.

I load two txt-Files as 3D-Curves into the Designmodeler, which are the profile for a blade. In general it´s a workbenchproject. My problem is, when the txt-Files change, i want the designmodeler to refresh the 3d-curves automatically. It works the best with a java-script, but i´m not able to build the script.

In short, i want a script, which sets the 3D-Curve-Option ´Refresh´ to Yes and after that, generates the new geometry.

It would be very nice, if someone could give me an introduction into the java-code, which would solve the problem.

Best regards

mvoss February 25, 2014 09:06

Are you using the JScript feature (JavaScript eq JScript????)?
Within wb you can reach down to the DM from the journal-feature via
Code:

system = GetSystem(Name="Geom")
geometry = system.GetContainer(ComponentName= "Geomtry")
SendCommand(Command = ""var ps1=new Object();
***
agb.Regen();"")

I would guess that the agb.Regen() is what you need.
You need to find a function for reading in the txt-files in DM OR you find the tree feature in DM by name e.g. OR you start the above script after checking for the updated txt-files.

Hopefully this will get you on the right track.

Herbert2014 February 25, 2014 10:06

Quote:

Originally Posted by mvoss (Post 476703)
Are you using the JScript feature (JavaScript eq JScript????)?
Within wb you can reach down to the DM from the journal-feature via
Code:

system = GetSystem(Name="Geom")
geometry = system.GetContainer(ComponentName= "Geomtry")
SendCommand(Command = ""var ps1=new Object();
***
agb.Regen();"")

I would guess that the agb.Regen() is what you need.
You need to find a function for reading in the txt-files in DM OR you find the tree feature in DM by name e.g. OR you start the above script after checking for the updated txt-files.

Hopefully this will get you on the right track.

First, thx for quick answer.

Yes, i worked with a pythen-script from the journal-feature, which uses a java script to update the 3d curve. Meanwhile i create a java-script which should work, but it doesn´t.

Folowing error is produced

Error: The object doesn´t run with this method.
Code:800a01b6
Script: varname.Refresh=1 (line 12....

I think there could be an error in the definition of the 3d-Curve, which i want to refresh. For example my 3d Curve is named "Curve 2323", do you know with which command in java i got the correct definition of a 3d-curve? what ist the right command to give the information which feature in the designmodeler i want to refresh?

Thanks for the help

Best regard

Herbert

mvoss February 26, 2014 05:29

finding the correct function for DM scripting is difficult. i have no idea about a specific command - but i would guess the agb.regen() refreshes the whole dm tree from top to bottom.
Just to be clear on the code:
you MUST spell it agb.Regen() --> since agb gives you smth. like a root access to the dm features - and as always, it´s not documented. Looking at your error this makes sense.

aerospace84 November 4, 2014 12:17

same problem! i've to refresh this 3d curve .txt files....and ansys support i'st answering me! have you solved in some way?
i haven't found yet this command to refresh the txt...
any good news??

Kapi November 12, 2014 20:53

to refresh or update the design you need to read the file once again
and then regenerate which updates the design

code something like this will read your geometry.txt file

Quote:

# encoding: utf-8
SetScriptVersion(Version="15.0")
template1 = GetTemplate(TemplateName="Mesh")
system1 = template1.CreateSystem()
geometry1 = system1.GetContainer(ComponentName="Geometry")
geometry1.Edit()
script = open('C:\Users\........\Geometry.txt', 'r')
geometry1.SendCommand(Command=script.read())
script.close();
Inside Geomerty.txt file you can put a code line which regenerates everytime you change code which is given as

Quote:

agb.Regen()

Hope this solves your problem!


Cheers
Kapi

aerospace84 November 18, 2014 05:06

thanks! I'll try this as soon as i can. Working in an industry I haven't so much time to strive following one path so i've managed using ICEM script...
But i'll try this in the spare time (i hope to have it!!) and as soon i get it i'll answer about this successful hint.
Anyway thank you for your answer!! i really appreciate that!

minou April 20, 2015 02:13

Hi everybody!
I know nothing about the scripting in ANSYS! (but i can try to learn :D)
I have the same problem: I want to import 2 texts files to draw 2 3D-curves! and after that continue my geometry (close my gemetry,extrude it, create a new sketch .. ).
For an optimization problem, I want to refresh for every individual the 2 curves only and let the rest.[the 2 texts files are refreshed automatically]
Thank you for your help!

Kapi April 20, 2015 02:24

Hi Minou,

Welcome to the forum!

To start with Scripting, I strongly suggest that you go to Ansys>Help section and go through "Scripting guide" to understand the process of scripting!

It will help you to sketch down steps of designing and optimization you want to achieve and then you can tackle these steps one by one!

Cheers
KAPI

minou April 21, 2015 02:25

1 Attachment(s)
Hi Kapi,

Thank you for you quick answer! However, I just want to know if I can create a macro to change (i.e., refresh) only one part of my geometry, without changing the whole geometry.
Attached in a PDF document, is a snapshot of the tree of my geometry in ANSYS Design Modeler, which illustrates my problem. I would like to only change (i.e., refresh) “Curve1” and “Curve2” in the attached tree by refreshing them automatically every time the Designmodeler is opened during the optimization without changing the rest of the tree, i.e. without changing “Line2”, “Plane5”, “Plane8”, “Extrude3”. The “2parts,2bodies” in the tree will be changed automatically if “Curve1” and “Curve2” are refreshed.
When “Curve1” is selected in the tree, the “Refresh” field in the “Detailed view” window of ANSYS Design modeler in the attached file shows “No”. I would like to change this to a “yes” using a workbench macro. I have not yet succeeded in doing this automatically for each individual during an optimization process, which requires a workbench Macro.

Attachment 38887

Thank you,

Kapi April 21, 2015 19:34

Hi Minou,

Your Line, Plane and Extrude will not be Refreshed if they are not connected to your curve. When you regenerate only your Curve and 2bodies will be updates/refreshed!

After your curve parameters change, you can call macro file (js file) which picks and regenerates your curve.
Code:

agb.Regen()
or when you create curve give this code, it will put refresh as YES!
Code:

var myCurve = ag.gui.CreateCurve();
myCurve.CoordinateFile = "FilePath";
myCurve.Name = "Curve1";
myCurve.CurveRefresh = 1;//if "1" dosent change refresh to yes then change it to "2"

Hope it helps
Cheers
KAPI


All times are GMT -4. The time now is 06:07.