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] Refreshing a Curve in Design Modeler Script (https://www.cfd-online.com/Forums/ansys-meshing/223381-refreshing-curve-design-modeler-script.html)

Safasml January 8, 2020 09:25

Refreshing a Curve in Design Modeler Script
 
Hi all,
I created geometry in design modeler that includes a 3d curve. Now the points that generate the 3d curve are changed and I want to refresh the curve. I can easily refresh it inside the design modeler. But I want to refresh it using a script that can be run from ANSYS WB.
“Refresh project” doesn’t refresh the curve.
Can anyone guide me about the script?

speedy11wwe August 18, 2022 06:02

Quote:

Originally Posted by Safasml (Post 754098)
Hi all,
I created geometry in design modeler that includes a 3d curve. Now the points that generate the 3d curve are changed and I want to refresh the curve. I can easily refresh it inside the design modeler. But I want to refresh it using a script that can be run from ANSYS WB.
“Refresh project” doesn’t refresh the curve.
Can anyone guide me about the script?


Hey did you find a solution?

Safasml August 18, 2022 08:23

Quote:

Originally Posted by speedy11wwe (Post 834032)
Hey did you find a solution?

Hi
Yes. Just copy the following code into a .js file and then run the script.
Here is the code:

Code:

var NodeName = "Curve1"; //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.CurveRefresh = Yes; // Refresh the Geometry

    num1 += 1;
 
  } else if (num1 == 3) {
    break;
  }
}

agb.regen();

you can change the name of the curve or anything if needed.
hope it helps

speedy11wwe August 19, 2022 06:30

Quote:

Originally Posted by Safasml (Post 834041)
Hi
Yes. Just copy the following code into a .js file and then run the script.
Here is the code:

Code:

var NodeName = "Curve1"; //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.CurveRefresh = Yes; // Refresh the Geometry

    num1 += 1;
 
  } else if (num1 == 3) {
    break;
  }
}

agb.regen();

you can change the name of the curve or anything if needed.
hope it helps



Hi and thank you for your reply!

I've only used ansys through the GUI, so I'm sorry if my questions annoy you, I'm very new to ansys scripting.

So, I'm trying to couple ansys fluent with a third software used for optimization.
This software has a python node (the python node directly links with a workbench node, in a block system) which changes the points in a txt file that is then used by design modeler to create the 3d curve.
Unfortunately, in the process, I've noticed that when building the geometry only some other ansys parameters are changed, as they should, but the curve rimains the same.

So i was wondering: is there a way to run this .js script iteratively, every time my third software asks to run a simluation, so that the js script runs before the meshing etc and refreshes the curve?

Thank you in advanced, I'm sorry to bother but I'm a bit stuck at the moment

Have a nice day!

Safasml August 19, 2022 09:10

Dear Fra Bla
The code I sent works only in the design modeler. So when you open the design modeler and run the .js file the curve must be updated.
For the .js file to run automatically, you would need to write another script in WorkBench (of course in Python). This means you need to write a script to read and run the .js file, then update the mesh, then update the solver, etc.
For doing this process iteratively I guess you should use your third software that you mentioned, in my case it was MATLAB. I don't know yours.
If you think I can help you further, feel free to ask more questions.

speedy11wwe August 19, 2022 09:45

Dear Safasml,
I'm using modeFrontier for the optimization process.

Do you think i can add some lines (that read and run your .js script) in the python node I already have working, the one which also changes the txt file? This way it could then update the workbench "normally".
Or do I need to write a macro which tells to run separetely every step of the simumlation and add some lines of code to run your js script before e.g. the meshing?
Thank you

Safasml August 19, 2022 10:47

Yes, I guess you can add some lines to your own code. There is no need to write a separate one.

speedy11wwe August 19, 2022 12:36

One last thing... do you know a link to some usefull guide for ansys scripting?

Thank you for everything!

Safasml August 19, 2022 23:03

There are many YouTube videos about ansys scripting. Google it and you'll find what you're looking for.
WorkBench also allows you to record scripts. So there is no need to write anything. You can start recording and then do anything you want in the WB GUI. The script is then saved in .wbjn format after you stop recording.

speedy11wwe August 20, 2022 11:00

Hi!
In the end I managed to get it working, I had to use a macro written in python language which literally passes your .js script to the geometry:

Code:

# encoding: utf-8
# 2020 R2
SetScriptVersion(Version="20.2.221")
system1 = GetSystem(Name="FFF")
geometry1 = system1.GetContainer(ComponentName="Geometry")
geometry1.Edit()
geometry1.SendCommand( Command = """var NodeName1 = "flap"; //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() == NodeName1.toLowerCase()) { // found the match
    current.CurveRefresh = Yes; // Refresh the Geometry

    num1 += 1;
 
  } else if (num1 == 3) {
    break;
  }
}

agb.regen();""")
geometry1.Exit()

The macro is run immediately after initializing the workbench but before building the geometry (the txt file has already been changed at this point), all automatized in modeFrontier. :)

Thank you for your help!

RussUTU June 2, 2023 12:15

Changing the txt file
 
Quote:

Originally Posted by speedy11wwe (Post 834163)

The macro is run immediately after initializing the workbench but before building the geometry (the txt file has already been changed at this point), all automatized in modeFrontier. :)

Would you mind sharing how you programmatically changed the text file? I'm struggling to programmatically select the curve I've already created and then to update the txt file to the new location.

Many thanks!

RussUTU June 2, 2023 13:57

I figured it out. Here's the part of my Workbench journal file from where it opens DesignModeler to when it closes it.

geometry1.Edit()

#--- The following is performed in DesignModeler ---#
# Locate the airfoil curve and set it equal to a variable named Crv1
geometry1.SendCommand(Command = """var Crv1 = ag.fm.Feature(3); // The curve is the 4th item in the feature tree

// Change the airfoil coordinate file location
Crv1.CoordinateFile = "file path";""")
#--- After this, DesignModeler closes and we return to Workbench ---#

geometry1.Exit()

speedy11wwe June 2, 2023 14:07

Well done!

In my case I was using another python block to change the coordinates of the txt file, so the workbench was always reading the same txt file, but with different values in it.


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