You are on page 1of 17

Lecture 3

Accessing DS Branch Objects in


Mechanical 14. 5 Release

1 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5


Content

• Accessing Branch object and its children


• Specifying parameters in “Details View”
• Summary

2 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5


Tree – Branch – Project -- Model

DS.Tree.FirstActiveBranch
DS.Tree

DS.Tree
DS.Tree.Branches
DS.Tree.Branches(1) == DS.Tree.FirstActiveBranch

DS.Tree.Projects
DS.Tree.Projects(1) == DS.Tree.FirstActiveBranch.Project

DS.Tree.FirstActiveBranch.Project.Models(1)

3 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5


Branch provide access to objects
Branch

Project
Model

PrototypeGroup
CoordinateSystemGroup
MeshControlGroup
ComponentGroup
Environment
AnalysisSettings
Load
AnswerSet
4 © 2011 ANSYS, Inc. November 29, 2012 Result
Release 14.5
Children of Branch Object
branchObj = DS.Tree.FirstActiveBranch
branchObj.Project

branchObj.Model ==
branchObj.Project.Models(1)

branchObj.PrototypeGroup

branchObj.MeshControlGroup
branchObj (model
with current object)
branchObj.ComponentGroup

branchObj.Environment

branchObj.AnswerSet

Branch object provides direct access to other objects

5 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5


PrototypeGroup
• Is the collection point for
Prototypes
• It also provides metadata for
the source of the attached
geometry file
• Allows accessing all bodies
and their properties
– Bodies are accessed using “Item”
property
– Starts at 1 (not 0)
– Some properties
• MaterialName
• Volume
• Mass
• SolidSurfaceArea
• CADParameters
• …
6 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5
MeshControlGroup
• A collection point for
MeshControls applied to the
attached geometry
• Also defines default
meshing settings for parts
that do not have specific
controls assigned
• Allows accessing all mesh
controls and their properties
– Controls are accessed using
“Item” property
– Starts at 1 (not 0)

7 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5


ComponentGroup
• A collection point for Named
Selections applied to the
attached geometry
• Allows accessing all Named
Selections and their
properties
• Components are accessed
using “Item” property
– Starts at 1 (not 0)

8 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5


Environment
• Collection point for loading conditions on
the attached geometry
• Typical methods:
– AddLoad(SM,id_loadType)
• For loads and supports
• id_LoadType is defined in DSConstants.js
– AddCondition(id_CondType)
• For accelerations and rotational speed
• id_CondType is defined in DSConstants.js
Path for DSConstants.js is ~\DSPages\scripts
• Typical properties:
– Name
– AnalysisSettings.NumberOfSteps
– …

9 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5


AnswerSet

• Collection point for user selected results


• Typical methods:
– AddResult(SM,id_ResType)
• id_ResType is defined in DSConstants.js
Path for DSConstants.js is ~\DSPages\scripts

• Typical properties:
– Name
– Results
• Results are accessed using “Item”
property
– Starts at 1 (not 0)
– …

10 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5


Anatomy of a Typical Script

Most of the scripts you will write will probably share this structure:
• Variable initialization
• Main part of the code
• Functions
• Comments wherever needed (highly recommended!)

Update the tree structure when you add entities through scripting
• DS.Script.fillTree();

11 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5


Specifying parameters in Details pane (1)
• Parameters (or Items) in “Details View” can be specified through “List View (lv)”
object
– When running a script in Mechanical, ListView object is directly accessible
– When using SendCommand from WB Python script, the ListView object is not
accessible directly. It should be defined as:
• ListView = DS.Script.lv

• Below example shows procedure for accessing various parameters of “Force” and
specifying appropriate values/options

• DS.Script. doInsertEnvironmentForce(); // command for adding new Force load

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

ListView.ActivateItem("Named Selection");
ListView.ItemValue = “face";
12 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5
Specifying parameters in Details pane (2)
DS.Script.lv.ActivateItem(“Define By");
DS.Script.lv.ItemValue = “Components";

DS.Script.lv.ActivateItem(“Coordinate System");
DS.Script.lv.ItemValue = " Global Coordinate System ";

DS.Script.lv.ActivateItem(“X Component");
DS.Script.lv.ItemValue = “1”;

DS.Script.lv.ActivateItem(“Y Component");
DS.Script.lv.ItemValue = “1";

DS.Script.lv.ActivateItem(“Z Component");
DS.Script.lv.ItemValue = “1”;

DS.Script.lv.ActivateItem(“Suppressed");
DS.Script.lv.ItemValue = “No”;

DS.Script.fillTree();

! One could use: ListView in place of DS.Script.lv


13 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5
Specifying parameters in Details pane (3)

• The “ListView” process described in previous slides uses


actual “strings” as appeared in Details View.
– In other words, this process becomes Language
dependent
– In order to remove this dependency, pass “string ID”
instead of actual string
– A method DS.Script.localString() can be used to get
the desired string in the local language

• Consider the same Force load example


• Instead of using “Scoping Method” string, lets find the ID
of this string and pass it
– Go to ~DSPages\Language\en-us\xml
– Find the ID_** for Menu string “Scoping Method” and
“Named Selection” from dsstringtable.xml

14 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5


Specifying parameters in Details pane (4)
You will get the string “Scoping Method” at
multiple locations. Select the one that is most
reasonable
In this case it is: ID_GeometryDefineBy

For “Named Selection” it is: ID_NamedSelection

15 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5


Specifying parameters in Details pane (5)

Commands to activate “Scoping Method” item


var scpMtd = DS.Script.localString("ID_GeometryDefineBy");
ListView.ActivateItem(scpMtd);

And specify the value as “Named Selection”


var scpVal = DS.Script.localString("ID_NamedSelection");
ListView. ItemValue(scpVal);

Similarly, activate and specify the Named Selection item


ListView.ActivateItem(scpVal);
ListView.ItemValue(“face”);

16 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5


Summary

This presentation highlighted following points:


• How to access branch objects of Tree (Geometry, mesh controls,
Named Selections, etc.)
• How to specify parameters in the Details view

17 © 2011 ANSYS, Inc. November 29, 2012 Release 14.5

You might also like