CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > ANSYS Meshing & Geometry

[DesignModeler] Designmodeler java scripting

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 25, 2014, 06:44
Default Designmodeler java scripting
  #1
New Member
 
Join Date: Feb 2014
Posts: 2
Rep Power: 0
Herbert2014 is on a distinguished road
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
Herbert2014 is offline   Reply With Quote

Old   February 25, 2014, 09:06
Default
  #2
Senior Member
 
Matthias Voß
Join Date: Mar 2009
Location: Berlin, Germany
Posts: 449
Rep Power: 20
mvoss is on a distinguished road
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.
mvoss is offline   Reply With Quote

Old   February 25, 2014, 10:06
Default
  #3
New Member
 
Join Date: Feb 2014
Posts: 2
Rep Power: 0
Herbert2014 is on a distinguished road
Quote:
Originally Posted by mvoss View Post
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
Herbert2014 is offline   Reply With Quote

Old   February 26, 2014, 05:29
Default
  #4
Senior Member
 
Matthias Voß
Join Date: Mar 2009
Location: Berlin, Germany
Posts: 449
Rep Power: 20
mvoss is on a distinguished road
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.
mvoss is offline   Reply With Quote

Old   November 4, 2014, 12:17
Default
  #5
New Member
 
Luke
Join Date: Nov 2012
Location: italy
Posts: 24
Rep Power: 14
aerospace84 is on a distinguished road
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??
aerospace84 is offline   Reply With Quote

Old   November 12, 2014, 20:53
Default
  #6
Senior Member
 
Join Date: Apr 2014
Location: Melbourne
Posts: 584
Rep Power: 14
Kapi is on a distinguished road
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
Kapi is offline   Reply With Quote

Old   November 18, 2014, 05:06
Default
  #7
New Member
 
Luke
Join Date: Nov 2012
Location: italy
Posts: 24
Rep Power: 14
aerospace84 is on a distinguished road
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!
aerospace84 is offline   Reply With Quote

Old   April 20, 2015, 03:13
Default
  #8
New Member
 
narjisse
Join Date: Apr 2015
Posts: 5
Rep Power: 11
minou is on a distinguished road
Hi everybody!
I know nothing about the scripting in ANSYS! (but i can try to learn )
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!
minou is offline   Reply With Quote

Old   April 20, 2015, 03:24
Default
  #9
Senior Member
 
Join Date: Apr 2014
Location: Melbourne
Posts: 584
Rep Power: 14
Kapi is on a distinguished road
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
Kapi is offline   Reply With Quote

Old   April 21, 2015, 03:25
Default
  #10
New Member
 
narjisse
Join Date: Apr 2015
Posts: 5
Rep Power: 11
minou is on a distinguished road
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.

question.pdf

Thank you,
minou is offline   Reply With Quote

Old   April 21, 2015, 20:34
Default
  #11
Senior Member
 
Join Date: Apr 2014
Location: Melbourne
Posts: 584
Rep Power: 14
Kapi is on a distinguished road
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
Kapi is offline   Reply With Quote

Old   September 11, 2019, 19:17
Default
  #12
New Member
 
Vishal Chauhan
Join Date: Jan 2012
Posts: 14
Rep Power: 14
vishu343 is on a distinguished road
Hi Kapi,

your suggestions really helped me a lot for my work.

As of now, I have implemented what you have suggested to create 3D curve from scratch (using its coordinates) using script.

But, now what I am trying to do is to open existing .wbpj file then open Design modeler and then edit coordinates of existing 3D curve (everything using script). I have tried to do some tricks like trial and error but till now no success.

Would you please give some suggestions on this?

Thanks a lot.


Quote:
Originally Posted by Kapi View Post
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
vishu343 is offline   Reply With Quote

Old   September 13, 2019, 09:25
Default
  #13
Member
 
Dimitrios S. P.
Join Date: Jan 2018
Posts: 63
Rep Power: 8
Pled is on a distinguished road
Good day everyone,
is there a good guide for the design modeler scripting? I need one that describes functions that do not exist in Ansys HELP. I have tried to reverse enginnering some .dll files of design modeler, but the effrot was unsuccessful.
Pled is offline   Reply With Quote

Old   October 16, 2019, 17:19
Talking
  #14
New Member
 
Justin
Join Date: Jan 2015
Posts: 28
Rep Power: 11
DA6righthand is on a distinguished road
Quote:
Originally Posted by Kapi View Post
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
Kapi,

You saved me much frustration! I manually setup DM that has an external CAD file import along with 2 3D curves (by file). During my iterative process, the initial CAD and curve files get overwritten and I then I simply need to refresh them to reload the new file contents. Here is what I ended up with that worked:

Code:
var NodeName = "Import1"; // Name of the import feature
var NodeName2 = "Curve1"; //Name of 3d curve feature
var NodeName3 = "Curve2"; //Name of 3d curve feature

// Loop through the existing features and select the required ones
var count = ag.fm.FeatureCount;
var num1 = 0;
var Yes = agc.Yes;
for (var i = 0; i < count; i++) {

  var current = ag.fm.Feature(i);
  var Name = current.Name;

  if (Name.toLowerCase() == NodeName.toLowerCase()) { // found the match
    current.Refresh = Yes; // Refresh the Geometry
    num1 += 1;
  } else if (Name.toLowerCase() == NodeName2.toLowerCase()) {
    current.CurveRefresh = Yes;
    num1 += 1;
  } else if (Name.toLowerCase() == NodeName3.toLowerCase()) {
    current.CurveRefresh = Yes;
    num1 += 1;
  } else if (num1 == 3) {
    break;
  }
}

agb.regen();
The section of my script that was having a problem was refreshing the 3D curves. I kept trying to use
Code:
current.Refresh = Yes;
for the two curve features which did not work. But then I saw your post to use
Code:
current.CurveRefresh = Yes;
and now everything works! I just wish there was better documentation on scripting with DM. Similarly to how SolidWorks has their scripting well-documented with example scripts to show how each command/function is used. Thanks for posting!
DA6righthand is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro scripting in netbeans, importing star libraries laurensvd STAR-CCM+ 3 October 31, 2020 23:06
[DesignModeler] DesignModeler Scripting: How to get Full Command Access ANT ANSYS Meshing & Geometry 53 February 16, 2020 16:13
record actions via scripting Marabelle ANSYS 0 July 31, 2013 12:57
Macro to access java files in sub-directory abraum STAR-CCM+ 3 July 11, 2012 03:46
Getting OpenFOAM to coexist with an existing JAVA VM nik777 OpenFOAM Installation 5 February 22, 2007 08:21


All times are GMT -4. The time now is 16:20.