DesignModeler Scripting: How to get Full Command Access
I've spent the past several days trying to understand the DesignModeler Script programming interface in order to automate some very iterative geometry generation, which has been quite the difficult process since the Help documentation (DesignModeler User Guide > Scripting API) provides an extremely limited explanation of only a few basic functions. It limits what you can do to only a few batch commands like generating points, planes, sketches, etc., and is missing some pretty essential functions (e.g. how does one generate a Boolean? How does one select objects? How does one create a Named Selection, and how does one choose what goes in the named selection?).
This API also mentions parameters for which the creation/selection commands are undocumented (e.g. explanation of the agb.Sweep(...) command states that it can accept a Named Selection as a Profile or Path parameter, but does not explain how a Named Selection can be specified or generated). Moreover, most tutorials/forum posts on the matter describe only JScript programming for the Workbench/Mechanical environments, which are difficult to follow and simply do not apply to the different API/commands required for DesignModeler.
I noticed that the help documentation instructs users to use the "agc." prefix for "Script Constants" (e.g. agc.Yes, agc.Frozen, agc.TypeEdge3d, etc.) and the "agb." prefix for "application functions":
In the same folder as agInterop.js exists a file called agConstants.js, in which you can see that the 9 script constants are just a small subset of the many, many more that exist.
Searching for "ag." in the ANSYS directory yields the useful file "agEventHandler.js" which is full of useful commands. Below are a few of the categories of these commands:
ag.gb.* --> Graphics Handler/Service ("AgmService") commands
ag.gui.* --> GUI commands (GUIModeler), a command for every button shown in DesignModeler (for example ag.gui.AddSketch() and ag.gui.CreatePlane() ), and some others
ag.m.* --> Modeler, Main, or Menu (?) commands (e.g. ag.m.SuppressBody(), ag.m.DisplayBodyErrors(...), etc.)
Since I just found this, I'm still trying to dig around and learn how to use all of this, but I thought I'd post here since I haven't found anything online that describes these extra functions & where they're at least named within .js files in the ANSYS directory. However, below is an example of a useful way to generate first a separate named selection for each edge in a group (with sequential Face IDs, generated e.g. via AddSegment(...) method on a LinePt() instance; total number defined by numLines, which we assume has been assigned already), and then a named selection that contains all of the edges:
Edit: List of Global Handles (from agMain.js file)
// The most noteworthy global handles are:
// ag.wb ....................... WorkBench object
// ag.silent ................... No popup messages if set to true
// ag.guiScript ................ A pointer to <this> scripting engine
// ag.fs ....................... Scripting.FileSystemObject
// ag.regName .................. Applet's (registry) name
// ag.regNameDS ................ DesignSpace Applet's (registry) name
// ag.installDir ............... InstallDir path
// ag.pagesDir ................. Pages directory
// ag.stringTable .............. Localized stringtable
// ag.imageList* ............... The imagelist(s)
// ag.runnigScriptPath ......... See agRunScript(.)
// ag.m ........................ AGP's Modeler object
// ag.fm ....................... AGP's FeatureMgr object
// ag.b ........................ AGP's BatchMgr object
// ag.WB2....................... True if launched from WB2
// ag.gui ...................... AGP's GUIModeler object
// ag.gb ....................... AGP's GfxService object
// ag.fromDS ................... true iff started from DS
// ag.cursorWaitCounter......... counter, 0 when not waiting
// ag.printPreviewTabClicked.... true when user clicks Print Preview tab
// ag.printPreviewActive........ true when Print Preview Window is active
Searching within files in the ANSYS install directory with selections from this (like "ag.gui." or "ag.m.") will probably get you some useful results.
Edit 2: This file (agMain.js) also includes:
some more "revrse engineering"....
I've used "ole/com object viewer" from Microsoft Visual Studio SDK (OleView.exe) and inspected Type Libraries from
located at "C:\Program Files\ANSYS Inc\v150\aisol\bin\winx64\"
Refer to IAnsBatchMgr Interface definition for all ag.b functions available.
Same thing with IAnsGUIModeler and its ag.gui JScript analog.
There are sooo many other interesting things (not documented yet)!
But it's good enough source for those who has programmer experience.
It's nice to see a recent update on the most visited page after searches like "Design Modeler Scripting API" . Both contributions help a lot. Thank you very much.
Here is some practical example on DModeler usage:
1) load external CAD body
2) draw the surface under it using its bounds
Design Modeler listing operations of a selected object
Thanks guys for posting these, its valuable for scripting enthuse persons. I have 1 questions in the field of Design Modeler not sure how to get into it. How can we list down all the operations (like Boolean, body operations etc.) performed on a selected object?
In regard to selected objects which were used for the feature creation, I can get the total number (own property in each feature), but not object handles.
you seem to have some experience with JSript quirks of DesignModeler, maybe you can enlighten me :-)
My task is actually pretty simple. I'd like to create a sketch, consisting of three lines (bottom, left, right) and an arc (top). At the intersections of the arc with the left and right line, fillets with a 3mm radius shall be created.
What I have so far:
Do you have any ideas what's causing this behavior?
IAnsSketch::Fillet() fail error
Here is the definition of IAnsSketch::Fillet() from Ans.Modeler.ObjectsCOM.dll :
The following code works good but the second fillet extra edges are not trimmed (do not know why):
As you can also see the special object wrapper around shape construction (as in "WriteScript:Sketches" command) is optional.
command geometry generation based on Ansys functions
Really useful info... :) thanks
Is there any way to get this command geometry generation based on Ansys functions automatically from Ansys? I mean I generate my 3D model in Design Modeler GUI, but I want to export it in text command style not in .agdb format, So I can modify the geometry by modifying the command text file.
unfortunately you can't let ANSYS generate such a file, you will have to write it on your own. The only thing that works automatically are sketches.
1) there is a JScript for DM (let say "geom.js") which creates the model geometry and then export geometry into IGES/STEP.
2) there is the IronPython script (let say "update_geom.wbjn") for WB to open/create a project, insert "geometry" template, open it and run geom.js file there.
3) there is APDL-script (let say "import_geom.inp") to import IGES/STEP in ANSYS APDL.
4) there is system BAT-file to run WB in batch mode with update_geom.wbjn as the parameter and then the ANSYS APDL in GUI mode with import_geom.inp as the parameter.
Here is the wbjn-code snippet
about command line in designmodeler
Helle everyone! I need to use DesignModeler to conduct a multidisciplinary optimiziation for a radial-inflow turbine rotor. But I came across several problems:
This figure shows what I do through the DesignModeler Graphic user interface, I import a .BGD file which is generated from the BladeGen module firstly, and then I conduct Blend and Cut material. I have a lot of different but similar .BGD files, so what I want to do is changing the ImportBGD1 item in the Tree Outline (red rectangle).
And change the ImportBGD1 item to another .BGD file like the figure shows below. And Generate at last, then all the steps will be carried out on the new .BGD object. I have tried through the Graphic user interface and succeed. Now I hope all of these can be conducted through the js script. I look for some command lines for the DesignModeler, but I can not find the command correspond to the “replace the ImportBGD1 item”. I attach the workbench project files below (http://yun.baidu.com/share/link?shar...2&uk=654753982), and hope you guys can help me! Thank you very much!
I thought the command may be ag.GUI.CreateImportBGD('file path'), but it is not.
In the dir: v145\aisol\BladeModeler\BladeEditor\BMPages\script s, there is a bmScriptInt.js file, and a function called CreatImportBGD(), how to use it?
Unfortunately I have no blade generator and corresponded DM import plug-in installed. However, I have found that the BGD-import feature has IAnsFThirdPartyHost object type.
The IAnsFThirdPartyHost does not support any 'source geometry' property (like IAnsImport::SourceName), but, maybe SetParameter() function can be helpfull:
my JScript file generating all the geometric entities and named selections for further use in CFX Pre is done. To get there, I had to implement a variety of ag.gui.CreateXYZ and other ag.gui commands.
I bet you all know the feeling, when, after a long time of trying different things, something is finally working... :)
I'm on Linux, so I run "runwb2 -B -R geometry.wbjn" with the following journalfile:
So far, so good...
Unfortunately, the final project is supposed to be running on a HPC system entirely without GUI. So, when I test the script in Terminal Mode (Ctrl-Alt-F1), apart from the error message "Cannot open x display (not specified)", I get a script error message regarding the ag.gui code snippets. It makes sense to me, because all those ag.gui objects depend on the gui stuff being loaded. And that's not going to happen when there is window.
What I thought about is to pipe the request for a display to another, virtual display which does not need to pop up. Maybe one of you has already run into that wall and figured out how to tear it down ;)
Solved the problem using TightVNC.
Step 1: Create virtual display
|All times are GMT -4. The time now is 23:44.|