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

[DesignModeler] Refreshing a Curve in Design Modeler Script

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By speedy11wwe
  • 1 Post By speedy11wwe

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 8, 2020, 10:25
Default Refreshing a Curve in Design Modeler Script
  #1
Member
 
Join Date: Oct 2017
Posts: 35
Rep Power: 9
Safasml is on a distinguished road
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?
Safasml is offline   Reply With Quote

Old   August 18, 2022, 07:02
Lightbulb
  #2
New Member
 
Fra Bla
Join Date: Aug 2022
Posts: 6
Rep Power: 4
speedy11wwe is on a distinguished road
Quote:
Originally Posted by Safasml View Post
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?
speedy11wwe is offline   Reply With Quote

Old   August 18, 2022, 09:23
Default
  #3
Member
 
Join Date: Oct 2017
Posts: 35
Rep Power: 9
Safasml is on a distinguished road
Quote:
Originally Posted by speedy11wwe View Post
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
Safasml is offline   Reply With Quote

Old   August 19, 2022, 07:30
Default
  #4
New Member
 
Fra Bla
Join Date: Aug 2022
Posts: 6
Rep Power: 4
speedy11wwe is on a distinguished road
Quote:
Originally Posted by Safasml View Post
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!
speedy11wwe is offline   Reply With Quote

Old   August 19, 2022, 10:10
Default
  #5
Member
 
Join Date: Oct 2017
Posts: 35
Rep Power: 9
Safasml is on a distinguished road
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.
Safasml is offline   Reply With Quote

Old   August 19, 2022, 10:45
Default
  #6
New Member
 
Fra Bla
Join Date: Aug 2022
Posts: 6
Rep Power: 4
speedy11wwe is on a distinguished road
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
speedy11wwe is offline   Reply With Quote

Old   August 19, 2022, 11:47
Default
  #7
Member
 
Join Date: Oct 2017
Posts: 35
Rep Power: 9
Safasml is on a distinguished road
Yes, I guess you can add some lines to your own code. There is no need to write a separate one.
Safasml is offline   Reply With Quote

Old   August 19, 2022, 13:36
Smile
  #8
New Member
 
Fra Bla
Join Date: Aug 2022
Posts: 6
Rep Power: 4
speedy11wwe is on a distinguished road
One last thing... do you know a link to some usefull guide for ansys scripting?

Thank you for everything!
speedy11wwe is offline   Reply With Quote

Old   August 20, 2022, 00:03
Default
  #9
Member
 
Join Date: Oct 2017
Posts: 35
Rep Power: 9
Safasml is on a distinguished road
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.
Safasml is offline   Reply With Quote

Old   August 20, 2022, 12:00
Default
  #10
New Member
 
Fra Bla
Join Date: Aug 2022
Posts: 6
Rep Power: 4
speedy11wwe is on a distinguished road
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 likes this.
speedy11wwe is offline   Reply With Quote

Old   June 2, 2023, 13:15
Default Changing the txt file
  #11
New Member
 
Russ
Join Date: Jun 2023
Location: United States
Posts: 2
Rep Power: 0
RussUTU is on a distinguished road
Quote:
Originally Posted by speedy11wwe View Post

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 is offline   Reply With Quote

Old   June 2, 2023, 14:57
Default
  #12
New Member
 
Russ
Join Date: Jun 2023
Location: United States
Posts: 2
Rep Power: 0
RussUTU is on a distinguished road
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()
RussUTU is offline   Reply With Quote

Old   June 2, 2023, 15:07
Default
  #13
New Member
 
Fra Bla
Join Date: Aug 2022
Posts: 6
Rep Power: 4
speedy11wwe is on a distinguished road
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.
RussUTU likes this.
speedy11wwe is offline   Reply With Quote

Reply

Tags
design modeler, refresh, script


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
[DesignModeler] Rotating an imported part in Design Modeler mikko ANSYS Meshing & Geometry 2 November 30, 2015 01:23
[DesignModeler] How to write the script in the ansys design modeler? deddy1973 ANSYS Meshing & Geometry 3 October 4, 2013 06:08
Problem Regarding Importing Carbon Nanotube Structure IN design modeler rhythm_saini ANSYS 0 July 4, 2012 04:34
design modeler zikozaki01 FLUENT 4 May 30, 2012 18:17
Info: Short Course On Thermal Design of Electronic Equipment Arnold Free Main CFD Forum 0 August 10, 1999 11:18


All times are GMT -4. The time now is 13:59.