ACT APIs for Mechanical Guide PDF

Title ACT APIs for Mechanical Guide
Author Ken Joe
Course Ansys
Institution 湖南大学
Pages 50
File Size 2.2 MB
File Type PDF
Total Downloads 105
Total Views 159

Summary

A reference for ANSYS...


Description

ANSYS ACT APIs for Mechanical Guide

ANSYS, Inc. Southpointe 2600 ANSYS Drive Canonsburg, PA 15317 [email protected] http://www.ansys.com (T) 724-746-3304 (F) 724-514-9494

Release 19.0 January 2018 ANSYS, Inc. and ANSYS Europe, Ltd. are UL registered ISO 9001: 2008 companies.

Copyright and Trademark Information © 2017 ANSYS, Inc. Unauthorized use, distribution or duplication is prohibited. ANSYS, ANSYS Workbench, AUTODYN, CFX, FLUENT and any and all ANSYS, Inc. brand, product, service and feature names, logos and slogans are registered trademarks or trademarks of ANSYS, Inc. or its subsidiaries located in the United States or other countries. ICEM CFD is a trademark used by ANSYS, Inc. under license. CFX is a trademark of Sony Corporation in Japan. All other brand, product, service and feature names or trademarks are the property of their respective owners. FLEXlm and FLEXnet are trademarks of Flexera Software LLC.

Disclaimer Notice THIS ANSYS SOFTWARE PRODUCT AND PROGRAM DOCUMENTATION INCLUDE TRADE SECRETS AND ARE CONFIDENTIAL AND PROPRIETARY PRODUCTS OF ANSYS, INC., ITS SUBSIDIARIES, OR LICENSORS. The software products and documentation are furnished by ANSYS, Inc., its subsidiaries, or affiliates under a software license agreement that contains provisions concerning non-disclosure, copying, length and nature of use, compliance with exporting laws, warranties, disclaimers, limitations of liability, and remedies, and other provisions. The software products and documentation may be used, disclosed, transferred, or copied only in accordance with the terms and conditions of that software license agreement. ANSYS, Inc. and ANSYS Europe, Ltd. are UL registered ISO 9001: 2008 companies.

U.S. Government Rights For U.S. Government users, except as specifically granted by the ANSYS, Inc. software license agreement, the use, duplication, or disclosure by the United States Government is subject to restrictions stated in the ANSYS, Inc. software license agreement and FAR 12.212 (for non-DOD licenses).

Third-Party Software See the legal information in the product help files for the complete Legal Notice for ANSYS proprietary software and third-party software. If you are unable to access the Legal Notice, contact ANSYS, Inc. Published in the U.S.A.

Table of Contents ACT API Introduction .................................................................................................................................. 1 Object Access .............................................................................................................................................. 3 Property Types ....................................................................................................................................... 3 Tree Objects ........................................................................................................................................... 4 Model Objects ........................................................................................................................................ 6 Accessing and Manipulating the Geometry Object .......................................................................... 6 Accessing and Manipulating the Mesh Object ................................................................................... 7 Accessing and Manipulating the Connections Object ................................................................... 7 Accessing and Manipulating the Analysis Object .......................................................................... 8 Object Traversal ...................................................................................................................................... 9 Traversing the Geometry .................................................................................................................. 9 Traversing the Mesh ........................................................................................................................ 11 Traversing Results ........................................................................................................................... 12 Boundary Conditions ................................................................................................................................ 15 Input and Output Variables ................................................................................................................... 15 Variable Definition Types ...................................................................................................................... 15 Setting Input Loading Data Definitions ................................................................................................. 16 Setting Variable Definition Types ........................................................................................................... 17 Creating a Displacement and Verifying Its Variable Definition Types ................................................. 17 Changing the Y Component from Free to Discrete and Verifying ...................................................... 18 Changing the Y Component Back to Free and Verifying .................................................................... 19 Setting Discrete Values for Variables ...................................................................................................... 20 Getting and Setting Discrete Values for an Input Variable ................................................................. 20 Getting and Setting Discrete Values for an Output Variable .............................................................. 22 Adding a Load ...................................................................................................................................... 23 Extracting Min-Max Tabular Data for a Boundary Condition ................................................................... 25 Worksheets ............................................................................................................................................... 27 Creating and Populating Named Selection Worksheets .......................................................................... 27 Creating the Named Selection Worksheet ....................................................................................... 27 Adding New Rows to the Named Selection Worksheet ..................................................................... 27 Adding Rows to Existing Mesh Order Worksheets .................................................................................. 29 Displaying the Mesh Worksheet ..................................................................................................... 30 Specifying the Mesh Worksheet and Named Selections ................................................................... 31 Adding New Rows in the Mesh Worksheet ....................................................................................... 31 Meshing the Named Selections ....................................................................................................... 32 Using Additional Commands .......................................................................................................... 33 Accessing Layered Section Worksheets .................................................................................................. 34 Displaying the Layered Section Worksheet ..................................................................................... 34 Getting the Layered Section Worksheet and Its Properties ............................................................... 34 Getting and Displaying the Material Property .................................................................................. 34 Getting and Displaying the Thickness Property ................................................................................ 35 Getting and Displaying the Angle Property ..................................................................................... 35 Setting and Displaying the Thickness Property ................................................................................ 35 Setting and Displaying the Angle Property ...................................................................................... 35 Accessing Bushing Joint Worksheets ..................................................................................................... 35 Displaying the Bushing Joint Worksheet ......................................................................................... 35 Getting the Bushing Joint Worksheet and Its Properties ................................................................... 36 Getting the Value for a Specified Unit .............................................................................................. 36 Graphical Views ........................................................................................................................................ 37 Getting the Data Object ModelViewManager ........................................................................................ 37 Release 19.0 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

iii

ACT APIs for Mechanical Guide Setting the View ................................................................................................................................... 37 Creating a View .................................................................................................................................... 38 Applying a View .................................................................................................................................... 38 Renaming a View .................................................................................................................................. 39 Deleting a View .................................................................................................................................... 39 Rotating a View .................................................................................................................................... 39 Saving a View ....................................................................................................................................... 40 Saving an Object .................................................................................................................................. 40 Exporting an Object .............................................................................................................................. 41 Exporting a Saved View List .................................................................................................................. 41 Importing a Saved View List .................................................................................................................. 41 Results ...................................................................................................................................................... 43 Other APIs ................................................................................................................................................. 45 Mechanical Interface and Toolbar Manipulation .................................................................................... 45 Command Snippets .............................................................................................................................. 45

iv

Release 19.0 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

ACT API Introduction The ACT API (Application Programming Interface) provides access to the native functionality of ANSYS Mechanical. Using APIs, you can access all objects in the Mechanical tree (Project, Model, and Analysis). With APIs, you can write scripts to not only manipulate existing objects and their properties but also create new ones.

Note When you create an object, Mechanical initializes its property values in the Details window to the same default values used when you add an object via standard mouse-click operations. Some properties, such as scoping or the mass of a point mass, can be invalid until you enter a value. Other ANSYS guides provides related information in which you might be interested: • For an introduction to writing scripts for Mechanical, see the Scripting in Mechanical Quick Start Guide. • For descriptions of all ACT API objects, methods, and properties, see the ANSYS ACT API Reference Guide. • For information on how to use ACT to create apps (extensions) that customize and automate ANSYS products, see the ANSYS ACT Developer's Guide. • For ACT usage, customization, and automation information specific to Mechanical, see the ANSYS ACT Customization Guide for Mechanical. Release 19.0 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

1

2

Release 19.0 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Object Access Using the ACT API, you can programmatically navigate the Mechanical tree to access objects. The root node of the tree is ExtAPI.DataModel.Project. Each tree node has children that you can access by calling the property Children. This returns all child nodes in the project. You can also call nested objects, such as Model, Geometry, Mesh, or Solution, to access all instances of a given object or tree level. Mesh = ExtAPI.DataModel.Project.Model.Mesh Connection = ExtAPI.DataModel.Project.Model.Children[3]

Property Types Each object in the tree has its own set of properties. Descriptions and examples of supported property types follow: Quantity: A unit-based value typically related to a physical quantity. Example: my_object.ElementSize = Quantity("0.1 [m]")

Numerical Value (float and integer): A property, such as Relevance or Rate, expecting a numerical value. No unit is specified for this number. Example: my_object.TetraGrowthRate = 2

Boolean: A property expecting a True or False value. Example: my_object.WriteICEMCFDFiles = True

Geometry Scoping: A property whose value is one or more geometric entities. In this case, you must: 1. Create selection information and specify the IDs of the entities that you want to manipulate. 2. Assign this list of IDs to location or source geometry properties. Example: my_selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) my_selection.Ids= [28,25] My_object.Location = my_selection

Release 19.0 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

3

Object Access

Tree Objects The API Ansys.ACT.Automation.Mechanical.Tree provides access to data contained within the Mechanical tree. To access the object Tree, you use ExtAPI.DataModel.Tree. The following table provides a sampling of the APIs available for querying the tree for contained objects. Some usage examples appear after the table. For a comprehensive list of API members, see the ANSYS ACT API Reference Guide. Member

Description

ActiveObjects

Lists all selected objects. Read-only.

AllObjects

Lists all of the objects available in the tree. Read-only.

GetObjectsByName

Lists all objects that match the specified name.

GetObjectsByType

Lists all objects that match the specified type. To do so, use the method GetObjectsByType and pass the type (such as Force) as an argument. The whole namespace of the type must be specified.

GetPathToFirstActiveObject

Shows the full statement that must be typed to get the selected object.

Refresh

Refreshes the tree.

In the ACT Console, you enter commands to query the tree for contained objects. To list all objects selected in the tree: ExtAPI.DataModel.Tree.ActiveObjects

To list all objects available in the tree: ExtAPI.DataModel.Tree.AllObjects

4

Release 19.0 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Tree Objects

To access objects by type: ExtAPI.DataModel.Tree.GetObjectsByType(Ansys.ACT.Mechanical.BoundaryConditions.Force)

To show the command to get the selected object, type: ExtAPI.DataModel.Tree.GetPathToFirstActiveObject()

Note Refreshing the tree can cause performance issues when executing a script that adds many objects, such as in a loop. To prevent a refresh until the loop completes, use the object Transaction() as shown in this sample code: with Transaction(): for i in range(5): ExtAPI.DataModel.Project.AddComment()

Release 19.0 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

5

Object Access

Model Objects In the Mechanical tree, you can access and manipulate model objects. The following topics describe the objects Geometry, Mesh, Connections, and Analysis: Accessing and Manipulating the Geometry Object Accessing and Manipulating the Mesh Object Accessing and Manipulating the Connections Object Accessing and Manipulating the Analysis Object

Accessing and Manipulating the Geometry Object The Geometry object provides you with direct access to the model's geometry information. To access the Geometry object: geometry = ExtAPI.DataModel.Project.Model.Geometry

The Geometry object exposes several convenient methods to define new child objects. For example, you can add a point mass to the Geometry object by calling the method AddPointMass. point_mass = geometry.AddPointMass()

Child Geometry objects often require a valid location assignment. You can satisfy this requirement by creating a new selection and setting the property Location: my_selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) my_selection.Ids = [22] point_mass.Location = my_selection

Each child object exposes a variety of important properties. For the point mass created above, a subset of accessible properties includes: point_mass.Mass = Quantity("12 [kg]") point_mass.MassMomentOfInertiaX = Quantity("1.1 [kg m m]") point_mass.MassMomentOfInertiaY = Quantity("1.2 [kg m m]") point_mass.MassMomentOfInertiaZ = Quantity("1.3 [kg m m]") point_mass.Behavior = LoadBehavior.Coupled point_mass.PinballRegion = Quantity("0.2 [m]")

Combining the three previous actions, the geometry now contains a fully described point mass.

6

Release 19.0 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.

Model Objects You can export the Geometry object to an STL (STereoLithography) file, which is the most commonly used file format in 3D printing. The following commands get the project model object and geometry object and then export the geometry object to an STL file. mymodel = ExtAPI.DataModel.Project.Model geo = mymodel.Geometry geo.ExportToSTL("C:\Temp\geoasstl.stl")

The result is the creation of a geometry file (geoasst1.stl) to the fully qualified directory path (C:\Temp).

Accessing and Manipulating the Mesh Object The Mesh object provides you with direct access to the model's mesh information. To access the Mesh object: mesh = ExtAPI.DataModel.Project.Model.Mesh

The Mesh object exposes several convenient methods to create new meshing controls. For example, you can create a meshing control that applies a patch-independent algorithm to the mesh by calling the method AddAutomaticMethod. mesh_method...


Similar Free PDFs