0% found this document useful (0 votes)
363 views

ANSYS Motion 2019 R3 API Tutorial

This document provides a tutorial on how to use the ANSYS Motion API to develop external modules in C# that can interact with and modify the ANSYS Motion application and subsystem files. It covers setting up the development environment in Visual C#, adding references to ANSYS Motion modules, common code structures, creating external modules that can be executed from within ANSYS Motion, and creating modules that add custom operations to the ANSYS Motion ribbon user interface. Sample code is provided to demonstrate modeling operations like creating geometry using the API.

Uploaded by

badaboy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
363 views

ANSYS Motion 2019 R3 API Tutorial

This document provides a tutorial on how to use the ANSYS Motion API to develop external modules in C# that can interact with and modify the ANSYS Motion application and subsystem files. It covers setting up the development environment in Visual C#, adding references to ANSYS Motion modules, common code structures, creating external modules that can be executed from within ANSYS Motion, and creating modules that add custom operations to the ANSYS Motion ribbon user interface. Sample code is provided to demonstrate modeling operations like creating geometry using the API.

Uploaded by

badaboy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Distributed by ANSYS, Inc.

ANSYS Motion
API
Tutorial
ANSYS, Inc.
API Tutorial ANSYS, Inc.

Contents

1. About ANSYS Motion API .................................................................................................. - 2 -


2. Development Environment ................................................................................................ - 4 -
2.1. Development tool .................................................................................................... - 4 -
3. Common Setting ................................................................................................................ - 5 -
3.1. Create C# Project .................................................................................................... - 5 -
3.2. Add References (Motion Modules) .......................................................................... - 5 -
3.3. License setting ........................................................................................................ - 7 -
4. External module ................................................................................................................. - 8 -
4.1. Create project “ ........................................................................................................ - 8 -
4.2. API”.......................................................................................................................... - 8 -
4.3. Main function code .................................................................................................. - 8 -
4.4. Build -> Build Solution ............................................................................................. - 8 -
4.5. Run ANSYS Motion and open any subsystem file .................................................. - 8 -
4.6. Select Motion/API module (“API.dll”) ....................................................................... - 9 -
4.7. Use the sample code............................................................................................... - 9 -
5. Operation ......................................................................................................................... - 14 -
5.1. Create project “OPERATION” ............................................................................... - 14 -
5.2. TestOperation class code ...................................................................................... - 15 -
5.3. Build -> Build Solution ........................................................................................... - 15 -
5.4. Add button to Ribbon UI ........................................................................................ - 16 -
5.5. Add subsystem module ......................................................................................... - 17 -
5.6. Run ANSYS Motion and open any subsystem file ................................................ - 17 -
5.7. Use the sample code............................................................................................. - 19 -

-1-
API Tutorial ANSYS, Inc.

1. About ANSYS Motion API

There are two ways to use ANSYS Motion API.


The first method is to use the “Execute external Motion/API module file” button.

< Excute external Motion/API module file >

The second method is to add a menu to Ribbon UI. This menu can be used just like other
Motion operation menu.

-2-
API Tutorial ANSYS, Inc.

< Register Motion operation >

Some information can be found in “VMAppCore.dll”, “VMDFBase.dll”, “VMObjBase.dll”, etc.


The license setting informs then can be found in “VMLNet.dll”.

-3-
API Tutorial ANSYS, Inc.

2. Development Environment

2.1. Development tool


Microsoft Visual C# 2012(.Net Framework V4.0)

-4-
API Tutorial ANSYS, Inc.

3. Common Setting

3.1. Create C# Project


 File -> New -> Project -> Class Library

< Create C# project >

3.2. Add References (Motion Modules)


 Add reference from “ANSYS installed path\Motion\Pre\VMAppCore.dll”

(Other Motion modules can be used. “VMAppCore.dll” is one of the Motion modules.)

< Add Reference >

-5-
API Tutorial ANSYS, Inc.

< Refer to VMAppCore.dll >

 Set Copy Local property to “False” (Recommended for all Motion module.)

< Copy Local property set to Falsel >

 Add reference “System.Windows.Forms”

-6-
API Tutorial ANSYS, Inc.

< Refer to System.Windows.Forms >

3.3. License setting


 Add reference “ANSYS installed path\Motion\Pre\License\VMLNet.dll”

 Add class “LicenseInfo.cs”

 Use this code in “LicenseInfo.cs”

using VM.Managed.License;

[assembly: OpenLicense(“API_User”, null)]

-7-
API Tutorial ANSYS, Inc.

4. External module

4.1. Create project “


4.2. API”
 Create C# project

 Add Reference “System.Windows.Forms”

 License setting

4.3. Main function code


 Open “Class1.cs”

 Use this code in “Class1.cs”

using System;
using System.Collections.Generic;
using System.Text;

namespace API
{
public class Module
{
public static void Main()
{
System.Windows.Forms.MessageBox.Show("This is API sample.");
}
}
}

4.4. Build -> Build Solution


 Project properties -> Build -> Output path “..\bin\$(Configuration Name)”

(Recommended; use output path “..\bin\Release”, if you use Release)

4.5. Run ANSYS Motion and open any subsystem file


 Execute external Motion/API module file

-8-
API Tutorial ANSYS, Inc.

< Execute external Motion/API module file >

4.6. Select Motion/API module (“API.dll”)


 This message is shown.

< Message >

 Next step is to use other modules.

4.7. Use the sample code


 Copy and extract the ‘API Tutorial.zip’ file from “ANSYS installed

path\Motion\Document\” to User folder (prevent the problem of folder access

permissions)

-9-
API Tutorial ANSYS, Inc.

< Sample code >

 Open “API_BallBearinngBuild.sln”, and build (Release configuration)

(As follow figure, if there is error in the reference setting, you have to reset the references
before build.)

< Error in the reference setting >

 Open “API_ContactBuild.sln”, and build as before

 Run ANSYS Motion

 Open “Resource\base.dfsub”

- 10 -
API Tutorial ANSYS, Inc.

< base.dfsub >

 Execute external Motion/API module file

 Select “bin\Release\ API_BallBearingBuild.dll”

< API_BallBearingBuild.dll >

 Execute external Motion/API module file

 Select “bin\Release\ API_ContactBuild.dll”

< API_ContactBuild.dll >

 Sequentially pick the FACESET object of the subsystem navigator according to the

message.

< FS_AXLE >

- 11 -
API Tutorial ANSYS, Inc.

< FS_HUB_LO >

< FS_HUB_LI >

< FS_HUB_RI >

- 12 -
API Tutorial ANSYS, Inc.

< FS_HUB_RO >

 End of modeling using the sample modules

- 13 -
API Tutorial ANSYS, Inc.

5. Operation

5.1. Create project “OPERATION”


 Create C# project

 Add Reference “VMAppCore.dll”, “System.Windows.Forms”

 License setting

- 14 -
API Tutorial ANSYS, Inc.

5.2. TestOperation class code


 Open “Class1.cs”

 Use this code in “Class1.cs”

using System;
using System.Collections.Generic;
using System.Text;

namespace OPERATION
{
public class TestOperation : VM.Managed.Operation.OperationBase
{
public TestOperation(VM.Managed.Document doc)
: base(doc)
{
}

public override void Execute()


{
System.Windows.Forms.MessageBox.Show("This is OPERATION
sample.");
}

public override string Name


{
get { return "TestOperation"; }
}
}
}
F
5.3. Build -> Build Solution
 Project properties -> Build -> Output path “..\bin\$(Configuration Name)”

(Recommended; use output path “..\bin\Release”, if you use Release)

 Output (“OPERATION.dll”) copy to “ANSYS installed path\Motion\ Pre\”

- 15 -
API Tutorial ANSYS, Inc.

5.4. Add button to Ribbon UI


 Create “ANSYS installed path\Motion\Pre\Templates\Resources\TestOpearation.dfresx”

<Resource>
<!--ICON-->
<Data name="ID_ICO_TestOperation">
<Value>337,..\VMRes.dll</Value>
</Data>
<!--TEXT-->
<Data name="ID_TXT_TestOperation">
<Value> Test Operation </Value>
</Data>
<Data name="ID_TOOLTIP_TestOperation" value="This is test operation."/>
<Value> This is test operation. </Value>
</Data>
</Resource>

 Create “ANSYS installed path\Motion\Pre\Templates\Ribbons\TestOperation.dfrbbx”

<Ribbon>
<Documents>
<Document name="SubSystem" toolkit="General">
<Tabs>
<Tab name="TestOperation" text="ID_TXT_TestOperation"
access_key="T">
<Panels>
<PrePanel name="SimpleViewPanel"/>
<Panel name="TestOperation" text="ID_TXT_TestOperation"
icon="ID_ICO_TestOperation">
<Buttons>
<Button name="Test Operation"
text="ID_TXT_TestOperation" tooltip="ID_TOOLTIP_TestOperation"
icon_small="ID_ICO_TestOperation" icon_large="ID_ICO_TestOperation"
command="TEST_OPERATION" access_key="S"/>
</Buttons>
</Panel>
</Panels>
</Tab>
- 16 -
API Tutorial ANSYS, Inc.

<Removes/>
</Tabs>
</Document>
</Documents>
</Ribbon>

5.5. Add subsystem module


 Create “ANSYS installed path\Motion\Pre\Templates\Modules\TestOperation.dfmdx”

<Module name="Subsystem" toolkit="General" is_overlap="true">


<DocumentCommands>
<!--Test Operation-->
<Command command="TEST_OPERATION"
operation="OPERATION.TestOperation,OPERATION"/>
</DocumentCommands>
<ViewCommands>
</ViewCommands>
</Module>

5.6. Run ANSYS Motion and open any subsystem file


 Execute added operation button

< Execute new operation >

 You can see this message.

- 17 -
API Tutorial ANSYS, Inc.

< Message >

- 18 -
API Tutorial ANSYS, Inc.

5.7. Use the sample code


 Go to “ANSYS installed path\Motion\Document\API Tutorial” folder

 Copy “Bring_To_Product\Pre”

 Paste to “ANSYS installed path\ Motion\”

 Run ANSYS Motion

 Open “Resource\base.dfsub”

 You can use pre-defined sample operation in “Test Operation” tab

< Test Operation >

 example : Create Ball Bearing

< BallBearing_LO_001 ~ BallBearing_LO_012 >

- 19 -
API Tutorial ANSYS, Inc.

< BallBearing_LI_001 ~ BallBearing_LI_012 >

< BallBearing_RI_001 ~ BallBearing_RI_012 >

< BallBearing_RO_001 ~ BallBearing_RO_012 >

- 20 -
API Tutorial ANSYS, Inc.

 example : Create Ball Bearing Face

< FS_BallBearing_LO_001 ~ FS_BallBearing_LO_012 >

< FS_BallBearing_LI_001 ~ FS_BallBearing_LI_012 >

< FS_BallBearing_RI_001 ~ FS_BallBearing_RI_012 >

< FS_BallBearing_RO_001 ~ FS_BallBearing_RO_012 >

- 21 -
API Tutorial ANSYS, Inc.

 example : Create 1-N Contact

< AxleToBall_LO_001 ~ AxleToBall_LO_012 >

- 22 -
API Tutorial ANSYS, Inc.

< AxleToBall_LI_001 ~ AxleToBall_LI_012 >

< AxleToBall_RI_001 ~ AxleToBall_RI_012 >

- 23 -
API Tutorial ANSYS, Inc.

< AxleToBall_RO_001 ~ AxleToBall_RO_01 >

- 24 -
API Tutorial ANSYS, Inc.

< HubToBall_LO_001 ~ HubToBall_LO_012 >

< HubToBall_LI_001 ~ HubToBall_LI_012 >

- 25 -
API Tutorial ANSYS, Inc.

< HubToBall_RI_001 ~ HubToBall_RI_012 >

< HubToBall_RO_001 ~ HubToBall_RO_012 >

- 26 -
API Tutorial ANSYS, Inc.

 example : Create Chained Contact

< BallToBall_LO_001 ~ AxleToBall_LO_012 >

< BallToBall_LI_001 ~ AxleToBall_LI_012 >

< BallToBall_RI_001 ~ AxleToBall_RI_012 >


- 27 -
API Tutorial ANSYS, Inc.

< BallToBall_RO_001 ~ AxleToBall_RO_012 >

- 28 -

You might also like