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 (“[Link]”) ....................................................................... - 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 “[Link]”, “[Link]”, “[Link]”, etc.
The license setting informs then can be found in “[Link]”.
-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\[Link]”
(Other Motion modules can be used. “[Link]” is one of the Motion modules.)
< Add Reference >
-5-
API Tutorial ANSYS, Inc.
< Refer to [Link] >
Set Copy Local property to “False” (Recommended for all Motion module.)
< Copy Local property set to Falsel >
Add reference “[Link]”
-6-
API Tutorial ANSYS, Inc.
< Refer to [Link] >
3.3. License setting
Add reference “ANSYS installed path\Motion\Pre\License\[Link]”
Add class “[Link]”
Use this code in “[Link]”
using [Link];
[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 “[Link]”
License setting
4.3. Main function code
Open “[Link]”
Use this code in “[Link]”
using System;
using [Link];
using [Link];
namespace API
{
public class Module
{
public static void Main()
{
[Link]("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 (“[Link]”)
This message is shown.
< Message >
Next step is to use other modules.
4.7. Use the sample code
Copy and extract the ‘API [Link]’ 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\[Link]”
- 10 -
API Tutorial ANSYS, Inc.
< [Link] >
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 “[Link]”, “[Link]”
License setting
- 14 -
API Tutorial ANSYS, Inc.
5.2. TestOperation class code
Open “[Link]”
Use this code in “[Link]”
using System;
using [Link];
using [Link];
namespace OPERATION
{
public class TestOperation : [Link]
{
public TestOperation([Link] doc)
: base(doc)
{
}
public override void Execute()
{
[Link]("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 (“[Link]”) 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\[Link]”
<Resource>
<!--ICON-->
<Data name="ID_ICO_TestOperation">
<Value>337,..\[Link]</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\[Link]”
<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\[Link]”
<Module name="Subsystem" toolkit="General" is_overlap="true">
<DocumentCommands>
<!--Test Operation-->
<Command command="TEST_OPERATION"
operation="[Link],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\[Link]”
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 -