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

[ANSYS Meshing] Mesh Scripting

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 10, 2019, 14:22
Default Mesh Scripting
  #1
New Member
 
Andrew M
Join Date: Apr 2018
Location: Toronto
Posts: 18
Rep Power: 8
michal28 is on a distinguished road
Hey Guys,

Is anyone familiar with sending commands to the Mesh Editor via the WorkBench Command window or via scripting?

I've done alot of reading on other people attacking this problem but nothing seems to work for me.

- From the command window I try sending actions via "mesh.SendCommand(Command=....." but always get 'command is under defined' errors

- and from the scripting side of things I've tried uploading .js files while the Mesh editor is open that take the style of:
ds.Script.doInsertMeshSize();
ListView.ActivateItem("Scoping Method");
ListView.ItemValue = "Named Selection";
ListView.ActivateItem("Named Selection");
............

but that always gives me an error that states "undefined variable 'ds'".


Any advice or examples on this would be greatly appriciated.
michal28 is offline   Reply With Quote

Old   January 11, 2019, 02:55
Default
  #2
Member
 
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 9
bpulat is on a distinguished road
The reason you get the undefined DS is that because you need to get the DesignSpace object.
var DS = WB.AppletList.Applet("DSApplet").App;
bpulat is offline   Reply With Quote

Old   January 11, 2019, 16:43
Default
  #3
New Member
 
Andrew M
Join Date: Apr 2018
Location: Toronto
Posts: 18
Rep Power: 8
michal28 is on a distinguished road
Dear Baris,

I've tried implementing your suggestion but similarly I just get another error:
" SyntaxError: unexpected token 'DS' "

Any Suggestions? (I'm operating on WB 19.1 if that helps)
michal28 is offline   Reply With Quote

Old   January 12, 2019, 14:07
Default
  #4
Member
 
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 9
bpulat is on a distinguished road
Did run that via IronPython or manually inside Meshing ?.
bpulat is offline   Reply With Quote

Old   January 14, 2019, 03:23
Default
  #5
Member
 
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 9
bpulat is on a distinguished road
Also, I just had to chance to try the macro:
Code:
//Get DesignSpace object
var DS = WB.AppletList.Applet("DSApplet").App;
//Get 'Mesh' control group
var Mesh_Mod = DS.Tree.FirstActiveBranch.MeshControlGroup;
//Select 'Mesh' from the tree
DS.Script.SelectItems(""+Mesh_Mod.ID);
DS.Script.doInsertMeshSize();
ListView.ActivateItem("Scoping Method");
ListView.ItemValue = "Named Selection";
ListView.ActivateItem("Named Selection");
This does work manually inside with ANSYS run macro utility.
bpulat is offline   Reply With Quote

Old   January 16, 2019, 16:02
Default
  #6
New Member
 
Andrew M
Join Date: Apr 2018
Location: Toronto
Posts: 18
Rep Power: 8
michal28 is on a distinguished road
Baris,

When implemented from ANSYS Command Window it results in same error:

SyntaxError: Unexpected Token 'DS'
michal28 is offline   Reply With Quote

Old   January 16, 2019, 17:31
Default
  #7
Member
 
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 9
bpulat is on a distinguished road
Yes, it will give you that error in Ironpython because what you write is javascript in the end.
The code I wrote works directly inside Ansys Meshing run macro utility.
bpulat is offline   Reply With Quote

Old   January 25, 2019, 15:57
Default
  #8
New Member
 
Andrew M
Join Date: Apr 2018
Location: Toronto
Posts: 18
Rep Power: 8
michal28 is on a distinguished road
Hi Baris,

I feel like I am missing something. I've tried your script many times.

First I save your code as a .js file
Next I go into ANSYS Meshing and go to Tools>Run Macro
Then I chose the .js file where I saved you code, yet I continually just get "Script Errors"

Am I missing something here?
michal28 is offline   Reply With Quote

Old   January 28, 2019, 06:35
Default
  #9
Member
 
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 9
bpulat is on a distinguished road
That is kind of odd because I just tried it again and it works.
As written the macro adds a Sizing function and Selects Named Selection section of it.
I attached you a screenshot of the resultant.
Can you give more information about the Script Errors?
Attached Images
File Type: png prova.PNG (13.9 KB, 51 views)
bpulat is offline   Reply With Quote

Old   March 18, 2019, 16:49
Default
  #10
New Member
 
Andrew M
Join Date: Apr 2018
Location: Toronto
Posts: 18
Rep Power: 8
michal28 is on a distinguished road
Hi Baris,

Its been a while but I have since gotten the macro's to work with my meshing editor. I was wondering if you had any recommendations towards online resources, as now I am trying to carry out more 'advanced' tasks via Mesh Scripting.

Hopefully these will include things like:
Name Selections via customized Worksheets
Mesh Sizing based on said name selections
Inflation layers, etc

I find there are many on forums that provide examples of how to apply mesh sizing or global parameters, but there is not much content if I am trying to create my own customized scripts. Are there places to find the functions utilized by these scripts that can allow me to apply name selections and so on?
michal28 is offline   Reply With Quote

Old   March 19, 2019, 02:55
Default
  #11
Member
 
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 9
bpulat is on a distinguished road
Unfortunately, there is not much information about the Ansys workbench scripting.

The only online source that is decent that I know are these:
Mesh Scripting 1
Mesh Scripting 2
Mesh Scripting 3
Mesh Scripting 4
Mesh Scripting 5


Also, there is the option to do scripting via ANSYS ACT which has more resources online but on that subject, I can't help much.
bpulat is offline   Reply With Quote

Old   March 19, 2019, 10:01
Default
  #12
New Member
 
Andrew M
Join Date: Apr 2018
Location: Toronto
Posts: 18
Rep Power: 8
michal28 is on a distinguished road
Thankyou very much. These are incredibly helpful.
michal28 is offline   Reply With Quote

Old   April 3, 2019, 22:52
Default
  #13
New Member
 
shufangwang
Join Date: Mar 2019
Posts: 4
Rep Power: 7
user12345678 is on a distinguished road
Quote:
Originally Posted by bpulat View Post
Unfortunately, there is not much information about the Ansys workbench scripting.

The only online source that is decent that I know are these:
Mesh Scripting 1
Mesh Scripting 2
Mesh Scripting 3
Mesh Scripting 4
Mesh Scripting 5


Also, there is the option to do scripting via ANSYS ACT which has more resources online but on that subject, I can't help much.
Hi Baris,
I wrote my script on a .js file. Then running it by the button 'run macro' on the mechanical window.It works.

But when I run the .wbjn file in ansys workbench and send the command to the mechanical window.
At first, I got the error saying that 'DS is undefined'. I solved it by add "var DS= WB.AppletList.Applet("DSApplet").App.Script.ds;". Then there is no problem with the DS. But I got another error say 'ListView is undefined.'
Could you please help me with the problem?
Thank you very much! [IMG]C:\Users\student\Desktop\model.png[/IMG][IMG][IMG]C:\Users\student\Desktop\listview.png[/IMG][/IMG]
user12345678 is offline   Reply With Quote

Old   April 4, 2019, 03:04
Default
  #14
Member
 
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 9
bpulat is on a distinguished road
Hey,
You need to define Listview object.
Here is the code for it:
Code:
var ListView = DS.Script.lv;
bpulat is offline   Reply With Quote

Old   April 4, 2019, 03:21
Default
  #15
New Member
 
shufangwang
Join Date: Mar 2019
Posts: 4
Rep Power: 7
user12345678 is on a distinguished road
Quote:
Originally Posted by bpulat View Post
Hey,
You need to define Listview object.
Here is the code for it:
Code:
var ListView = DS.Script.lv;
Thanks.
But I get another problem.

It is a little difficult to describe it.

After loading the .wbjn file, I find some operations does not do as I except.
The following is part of my code:

var DS= WB.AppletList.Applet("DSApplet").App.Script.ds;

var ListView = DS.Script.lv;

var SC=DS.Script
var SM=SC.sm

// Clear()
// This function resets the selection manager so that no geometry is currently
// selected.


//select all part(bodies)
SC.doGraphicsPartSelect() //always do part selection
SC.doEditsToolbar(8047) //select all according to cursor mode

//Mesh
SC.doModelPreviewMeshSelection()

//insert the gravity
SC.doInsertEnvironmentGravity(1)

//insert fixed support
SC.doInsertEnvironmentFixedDisplacement()

ListView.ActivateItem("Scoping Method")
ListView.ItemValue = "Named Selection"
ListView.ActivateItem("Named Selection")
ListView.ItemValue = "faces_5_2147483650"

//solve
SC.doSolveDefaultHandler()



The first problem is that after loading the .wbjn file and sending the code to the mechanical window, the mechanical window opens, but no mesh generated, no gravity inserted, no fixed support inserted.
I use the 'run macro...' button in the mechanical window again, I find that the problem still exists unless I use the mouse to choose the 'Static Structural (A5)' or 'Solution (A6)' button.

The second problem is that if I use the 'run macro...' button to loade the .js file, I get the error message 'You need at least one structural load to proceed with the solution.
'. I test the 'SC.doSolveDefaultHandler()' sentence. I delete the sentence in the old file and write the 'SC.doSolveDefaultHandler()' in another file and load the two files one by one through 'run macro' again, it works. How it happen.

Sorry for the inconvenience.
Thank you again.
user12345678 is offline   Reply With Quote

Reply

Tags
ansys 19.1, mesh scripting, scripting


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
[snappyHexMesh] Add Mesh Layers doesnt work on the whole surface Kryo OpenFOAM Meshing & Mesh Conversion 13 February 17, 2022 07:34
sliding mesh problem in CFX Saima CFX 46 September 11, 2021 07:38
decomposePar problem: Cell 0contains face labels out of range vaina74 OpenFOAM Pre-Processing 37 July 20, 2020 05:38
[Other] conformed FSI mesh for unstructured fluid region ashish.svm OpenFOAM Meshing & Mesh Conversion 10 August 2, 2019 08:40
[ICEM] surface mesh merging problem everest ANSYS Meshing & Geometry 44 April 14, 2016 06:41


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