|
[Sponsors] |
January 10, 2019, 15:22 |
Mesh Scripting
|
#1 |
New Member
Andrew M
Join Date: Apr 2018
Location: Toronto
Posts: 18
Rep Power: 8 |
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. |
|
January 11, 2019, 03:55 |
|
#2 |
Member
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 10 |
The reason you get the undefined DS is that because you need to get the DesignSpace object.
var DS = WB.AppletList.Applet("DSApplet").App; |
|
January 11, 2019, 17:43 |
|
#3 |
New Member
Andrew M
Join Date: Apr 2018
Location: Toronto
Posts: 18
Rep Power: 8 |
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) |
|
January 12, 2019, 15:07 |
|
#4 |
Member
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 10 |
Did run that via IronPython or manually inside Meshing ?.
|
|
January 14, 2019, 04:23 |
|
#5 |
Member
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 10 |
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"); |
|
January 16, 2019, 17:02 |
|
#6 |
New Member
Andrew M
Join Date: Apr 2018
Location: Toronto
Posts: 18
Rep Power: 8 |
Baris,
When implemented from ANSYS Command Window it results in same error: SyntaxError: Unexpected Token 'DS' |
|
January 16, 2019, 18:31 |
|
#7 |
Member
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 10 |
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. |
|
January 25, 2019, 16:57 |
|
#8 |
New Member
Andrew M
Join Date: Apr 2018
Location: Toronto
Posts: 18
Rep Power: 8 |
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? |
|
January 28, 2019, 07:35 |
|
#9 |
Member
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 10 |
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? |
|
March 18, 2019, 17:49 |
|
#10 |
New Member
Andrew M
Join Date: Apr 2018
Location: Toronto
Posts: 18
Rep Power: 8 |
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? |
|
March 19, 2019, 03:55 |
|
#11 |
Member
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 10 |
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. |
|
March 19, 2019, 11:01 |
|
#12 |
New Member
Andrew M
Join Date: Apr 2018
Location: Toronto
Posts: 18
Rep Power: 8 |
Thankyou very much. These are incredibly helpful.
|
|
April 3, 2019, 23:52 |
|
#13 | |
New Member
shufangwang
Join Date: Mar 2019
Posts: 4
Rep Power: 7 |
Quote:
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] |
||
April 4, 2019, 04:04 |
|
#14 |
Member
Baris PULAT
Join Date: Sep 2016
Location: Italy
Posts: 59
Rep Power: 10 |
Hey,
You need to define Listview object. Here is the code for it: Code:
var ListView = DS.Script.lv; |
|
April 4, 2019, 04:21 |
|
#15 | |
New Member
shufangwang
Join Date: Mar 2019
Posts: 4
Rep Power: 7 |
Quote:
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. |
||
Tags |
ansys 19.1, mesh scripting, scripting |
|
|
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 08:34 |
sliding mesh problem in CFX | Saima | CFX | 46 | September 11, 2021 08:38 |
decomposePar problem: Cell 0contains face labels out of range | vaina74 | OpenFOAM Pre-Processing | 37 | July 20, 2020 06:38 |
[Other] conformed FSI mesh for unstructured fluid region | ashish.svm | OpenFOAM Meshing & Mesh Conversion | 10 | August 2, 2019 09:40 |
[ICEM] surface mesh merging problem | everest | ANSYS Meshing & Geometry | 44 | April 14, 2016 07:41 |