|
[Sponsors] |
[DesignModeler] Refreshing a Curve in Design Modeler Script |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 8, 2020, 10:25 |
Refreshing a Curve in Design Modeler Script
|
#1 |
Member
Join Date: Oct 2017
Posts: 35
Rep Power: 9 |
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? |
|
August 18, 2022, 07:02 |
|
#2 | |
New Member
Fra Bla
Join Date: Aug 2022
Posts: 6
Rep Power: 4 |
Quote:
Hey did you find a solution? |
||
August 18, 2022, 09:23 |
|
#3 |
Member
Join Date: Oct 2017
Posts: 35
Rep Power: 9 |
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(); hope it helps |
|
August 19, 2022, 07:30 |
|
#4 | |
New Member
Fra Bla
Join Date: Aug 2022
Posts: 6
Rep Power: 4 |
Quote:
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! |
||
August 19, 2022, 10:10 |
|
#5 |
Member
Join Date: Oct 2017
Posts: 35
Rep Power: 9 |
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. |
|
August 19, 2022, 10:45 |
|
#6 |
New Member
Fra Bla
Join Date: Aug 2022
Posts: 6
Rep Power: 4 |
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 |
|
August 19, 2022, 11:47 |
|
#7 |
Member
Join Date: Oct 2017
Posts: 35
Rep Power: 9 |
Yes, I guess you can add some lines to your own code. There is no need to write a separate one.
|
|
August 19, 2022, 13:36 |
|
#8 |
New Member
Fra Bla
Join Date: Aug 2022
Posts: 6
Rep Power: 4 |
One last thing... do you know a link to some usefull guide for ansys scripting?
Thank you for everything! |
|
August 20, 2022, 00:03 |
|
#9 |
Member
Join Date: Oct 2017
Posts: 35
Rep Power: 9 |
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. |
|
August 20, 2022, 12:00 |
|
#10 |
New Member
Fra Bla
Join Date: Aug 2022
Posts: 6
Rep Power: 4 |
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() Thank you for your help! |
|
June 2, 2023, 13:15 |
Changing the txt file
|
#11 | |
New Member
Russ
Join Date: Jun 2023
Location: United States
Posts: 2
Rep Power: 0 |
Quote:
Many thanks! |
||
June 2, 2023, 14:57 |
|
#12 |
New Member
Russ
Join Date: Jun 2023
Location: United States
Posts: 2
Rep Power: 0 |
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() |
|
June 2, 2023, 15:07 |
|
#13 |
New Member
Fra Bla
Join Date: Aug 2022
Posts: 6
Rep Power: 4 |
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. |
|
Tags |
design modeler, refresh, script |
|
|
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 |