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": Quote:
Quote:
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: Code:
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: Quote:
|
some more "revrse engineering"....
I've used "ole/com object viewer" from Microsoft Visual Studio SDK (OleView.exe) and inspected Type Libraries from
Ans.Modeler.AppletCOM.dll Ans.Modeler.ObjectsCOM.dll 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. And....it works! Some examples: Code:
// ag.wb........................IWB |
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.
|
Sample script
Here is some practical example on DModeler usage:
Task is: 1) load external CAD body 2) draw the surface under it using its bounds Code:
// start from clear scratch |
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?
|
Quote:
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. |
Hello Alexander,
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: Code:
function planeSketch (p) Do you have any ideas what's causing this behavior? Best regards, Victor |
IAnsSketch::Fillet() fail error
Here is the definition of IAnsSketch::Fillet() from Ans.Modeler.ObjectsCOM.dll :
Code:
[id(0x0000006c), helpstring("Creates a round corner between two curves. Locations and switches determine if and how to trim")] The following code works good but the second fillet extra edges are not trimmed (do not know why): Code:
// Plane sketch 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
Hello Guys,
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. Thanks |
Hello HA11,
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. Greets Nigirim |
JScript-Python-APDL interconnection
Quote:
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 Code:
# encoding: utf-8 |
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). http://i57.tinypic.com/2vn1ci0.png 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! http://i60.tinypic.com/28vvtbn.png http://i59.tinypic.com/2ue1wcz.png 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: Code:
HRESULT SetParameter( |
Hello all,
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: Code:
# encoding: utf-8 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 ;) Best regards ================= Solution: Solved the problem using TightVNC. Step 1: Create virtual display Code:
vncserver -geometry 1920x1080 :10 Code:
export DISPLAY=:10 Code:
runwb2 -B -R geometry.wbjn |
3D curve
Hi.
Do you know if it is possible to write a script to import a 3D curve? EDIT: This seems to do the job: var NL1 = ag.gui.CreateCurve(); NL1.Name = "Name"; NL1.CoordinateFile = "FilePath"; But now I have a problem as I am trying to script a skin feature between the curves. Does anyone know how to select 3D curves with the script? I guess I can use this command to create the feature: agb.Skin(agc.Add, agc.No, 0.0, 0.0), but I haven't figured out how to select the profiles. |
Hi SG,
Please don't post same question in different Threads. Check other thread for reply. Cheers KAPI |
Hey guys,
does anybody happen to know how to access the entities stored in a Named Selection within DesignModeler? All I've been able to accomplish sofar was to get the count of stored entities. Have a nice weekend! |
Hi Victor,
Yes, You can access entities stored in NS Could you please elaborate your question bit more? and also post your code you have got so far? Cheers KAPI |
Hello KAPI,
I processed all faces in my multi part model and assigned them to their respective NSs, i.e. Part1ToPart2 and Part2ToPart1 which contain faces Part1 and Part2 have in common. In a further step I'd like to refine this selection, like Part1ToPart2Axial (and vice versa) and Part1ToPart2Circumferential (and vice versa). For that, I'd like to consider only the faces already assigned to the base selections Part1ToPart2 (and vice versa). But I lack the knowledge how to "grab" the items of one NS. This is how I create the NS objects: Code:
Part1ToPart2 = ag.gui.CreateSelectionSet(); Thanks for your input. Best regards, Victor |
Hi Victor,
Try to use the below code to pick NS and see if it works Code:
agb.AddSelect(agc.TypeFace, Part1ToPart2); Code:
ag.facePick; Cheers KAPI |
All times are GMT -4. The time now is 04:50. |