Help - Walkthrough - Hello World - Autodesk

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

11/10/21, 4:29 PM Help | Walkthrough: Hello World | Autodesk

Walkthrough: Hello World

Use the Advance Steel API and C# to create a Hello World program using the directions provided.

The Hello World walkthrough covers the following topics:

Create a new project


Add references
Add code
Register the addon with Advance Steel
Run the addon

All operations and code in this section were created using Visual Studio 2017.

Create a New Project


The first step in writing a C# program with Visual Studio is to choose a project type and create a new Class
Library.

1. From the File menu, select New Project….


2. In the Installed Templates frame, click Visual C#\Windows Desktop.
3. In the right-hand frame, click Class Library (.NET Framework) (see Figure 1: Add New Project ). This
walkthrough assumes that the project location is: C:\Samples.
4. In the Name field, type HelloWorld as the project name.
5. Verify that the selected .NET Framework is ".NET Framework 4.7".
6. Click OK.
7. Once the project is created, navigate to the project in the Solution Explorer Properties Build
8. In the Build dialog, select All Configurations from the Configurations drop-down list and change the
Platform Target to x64 (see Figure 2: Platform Target).

https://help.autodesk.com/view/ADSTPR/2021/ENU/?guid=GUID-A4DA627E-6680-4388-9C04-79F5F3D9D075 1/10
11/10/21, 4:29 PM Help | Walkthrough: Hello World | Autodesk

Figure 1: Add New Project

https://help.autodesk.com/view/ADSTPR/2021/ENU/?guid=GUID-A4DA627E-6680-4388-9C04-79F5F3D9D075 2/10
11/10/21, 4:29 PM Help | Walkthrough: Hello World | Autodesk

Figure 2: Platform Target

Add References
A number of components make up the Advance Steel API. They are installed with Advance Steel and can be
found in subdirectories of Advance Steel 2021 installation folder. The Advance Steel 2021 installation folder
is stored in the 'BinPath' value of the HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R23.1\ACAD-
3026 registry key. You need to add references to the following components in order to compile the project.

Component Description

ASNetRuntime.dll Required to compile the Addon

ASMgd.dll Main Advance Steel access

ASCADLinkMgd.dll CAD - related objects access (database, object id,


…)

ASGeometryMgd.dll Advance Steel geometry - needed to interact with


Advance Steel objects

ASProfilesMgd.dll Advance Steel profiles database access


https://help.autodesk.com/view/ADSTPR/2021/ENU/?guid=GUID-A4DA627E-6680-4388-9C04-79F5F3D9D075 3/10
11/10/21, 4:29 PM Help | Walkthrough: Hello World | Autodesk

ASModelerMgd.dll Advance Steel modeler access

ASObjectsMgd.dll Main Advance Steel objects access

To add references to the required components, follow these steps:

1. If the Solution Explorer window is not open, select Solution Explorer from the View menu.
2. In the Solution Explorer, right-click References to display a context menu.
3. From the context menu, click Add Reference. The Reference Manager window appears.
4. In the Reference Manager window, click the Browse button. A window to select files appears.
5. Browse to the Advance Steel 2021 installation folder.
6. Click the Add button to select the dll and close the window.
7. The selected dll should now be listed in the Reference Manager with a checkmark next to it.
8. Repeat steps 4-8 until all components in the table above are added. Note that when selecting dlls to
add, multiple dlls may be selected at one time.
9. In the Reference Manager, click OK to close the window.
10. The selected components will now appear in the Solution Explorer under the References folder.
11. Select the newly added references and change their Copy Local property to False.

https://help.autodesk.com/view/ADSTPR/2021/ENU/?guid=GUID-A4DA627E-6680-4388-9C04-79F5F3D9D075 4/10
11/10/21, 4:29 PM Help | Walkthrough: Hello World | Autodesk

Figure 3: Set Copy Local to False for Advance Steel references

Since this example also uses a Windows MessageBox, you will need to add a reference to the
System.Windows.Forms assembly. To do this:

1. Return to the Reference Manager window.


2. Click Assemblies in the left-hand pane.
3. Scroll down the list in the right-hand pane to find System.Windows.Forms.
4. Click the checkbox next to System.Windows.Forms.
5. Click OK to close the Reference Manager window.

https://help.autodesk.com/view/ADSTPR/2021/ENU/?guid=GUID-A4DA627E-6680-4388-9C04-79F5F3D9D075 5/10
11/10/21, 4:29 PM Help | Walkthrough: Hello World | Autodesk

Add Code
There are three main steps to adding code to an Advance Steel Addon:

Implement the IExtensionApplication interface


Create your command class
Edit the AssemblyInfo.cs file

Implement IExtensionApplication

A default class called Class1 should have been created with the new project.

1. Right-click on Class1.cs in the Solution Explorer and select Rename from the context menu.
2. Rename the file Plugin.cs (and select 'Yes' when Visual Studio prompts you to perform a renaming in
your project of all references to the code element 'Class1') .
3. Replace the text in Plugin.cs with the sample code below.

Code Region: Implement IExtensionApplication

using Autodesk.AdvanceSteel.Runtime;

namespace HelloWorld

public sealed class Plugin : IExtensionApplication

void IExtensionApplication.Initialize()

void IExtensionApplication.Terminate()

Tip: The Visual Studio Intellisense feature can create a skeleton implementation of an interface for you,
adding stubs for all the required methods. When creating a class that implements IExtensionApplication as
in the example above, you can right-click on the IExtensionApplication text and select Implement Interface
Implement Interface from the Intellisense menu to have code added for the IExtensionApplication
methods Initialize() and Terminate().

Figure 4: Use Intellisense to implement the interface

https://help.autodesk.com/view/ADSTPR/2021/ENU/?guid=GUID-A4DA627E-6680-4388-9C04-79F5F3D9D075 6/10
11/10/21, 4:29 PM Help | Walkthrough: Hello World | Autodesk

Create a command class


1. Add a new class to the project called TestClass.
2. Place the following code in TestClass.cs:

Code Region: Create a command class

using Autodesk.AdvanceSteel.CADAccess;

using Autodesk.AdvanceSteel.DocumentManagement;

using Autodesk.AdvanceSteel.Runtime;

using System.Windows.Forms;

namespace HelloWorld

public class TestClass

[CommandMethodAttribute("TEST_GROUP", "HelloWorld", "HelloWorld",


CommandFlags.Modal)]

public void SayHelloWorld()

MessageBox.Show("Hello World!");

An Advance Steel addon must have a method with the CommandMethodAttribute as shown in the sample
code above. The parameters for the CommandMethodAttribute are:

groupName - The name of the group to which the command will be added. If the group does not exist,
it will be created before the command is added.
globalName - The command name to add. This name represents the global or untranslated name.
localizedNameId - The command name to add. This name represents the local or translated name.
flags - Flags associated with the command.

Note that the options for CommandFlags are the same as for the AutoCAD Managed .NET API and the full
list of options can be found here (http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-F77E8FE0-8034-
4704-93BD-F717608F8223) .

Edit the AssemblyInfo.cs file

An Advance Steel addon must include certain Informational Attribute directives. These belong in the
AssemblyInfo.cs files.

1. In the Solution Explorer, click on the Properties folder to expose the AssemblyInfo.cs file.
2. Open the AssemblyInfo.cs file. This file already contains some assembly attributes such as the title
and copyright.
3. Add a using statement at the top of the file for Autodesk.AdvanceSteel.Runtime.
https://help.autodesk.com/view/ADSTPR/2021/ENU/?guid=GUID-A4DA627E-6680-4388-9C04-79F5F3D9D075 7/10
11/10/21, 4:29 PM Help | Walkthrough: Hello World | Autodesk

4. Add a new informational attribute directive called ExtensionApplicationAttribute as shown below.


Note that it takes as a parameter the type of the class which implements IExtensionApplication. This
is what makes your .Net Framework DLL an Advance Steel addon.

Code Region: Add an ExtensionApplicationAttribute

[assembly: ExtensionApplicationAttribute(typeof(HelloWorld.Plugin))]

5. Add a new informational attribute directive called CommandClassAttribute as shown below. Note that
it takes as a parameter the type of the class which implements a command. This is required to be able
to register the command with Advance Steel.

Code Region: Add a CommandClassAttribute

[assembly: CommandClassAttribute(typeof(HelloWorld.TestClass))]

After following these steps, the AssemblyInfo.cs file will look something like this:

Code Region: Sample AssemblyInfo.cs

using Autodesk.AdvanceSteel.Runtime;

using System.Reflection;

using System.Runtime.CompilerServices;

using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following

// set of attributes. Change these attribute values to modify the information

// associated with an assembly.

[assembly: AssemblyTitle("HelloWorld")]

[assembly: AssemblyDescription("")]

[assembly: AssemblyConfiguration("")]

[assembly: AssemblyCompany("")]

[assembly: AssemblyProduct("HelloWorld")]

[assembly: AssemblyCopyright("Copyright © 2015")]

[assembly: AssemblyTrademark("")]

[assembly: AssemblyCulture("")]

[assembly: ExtensionApplicationAttribute(typeof(HelloWorld.Plugin))]

[assembly: CommandClassAttribute(typeof(HelloWorld.TestClass))]

// Setting ComVisible to false makes the types in this assembly not visible

// to COM components. If you need to access a type in this assembly from

// COM, set the ComVisible attribute to true on that type.

[assembly: ComVisible(false)]

https://help.autodesk.com/view/ADSTPR/2021/ENU/?guid=GUID-A4DA627E-6680-4388-9C04-79F5F3D9D075 8/10
11/10/21, 4:29 PM Help | Walkthrough: Hello World | Autodesk

// The following GUID is for the ID of the typelib if this project is exposed to COM

[assembly: Guid("85900596-22ee-4873-bbd6-7f970d32b5af")]

// Version information for an assembly consists of the following four values:

//

// Major Version

// Minor Version

// Build Number

// Revision

//

// You can specify all the values or you can default the Build and Revision Numbers

// by using the '*' as shown below:

// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.0.0.0")]

[assembly: AssemblyFileVersion("1.0.0.0")]

Register the addon


Third party addons will be loaded according to information read from a configuration xml, which should be
placed in the Addons folder: The Addons folder has to be a direct subfolder of the Advance Steel install
folder. If the Addons folder is not there it should be created. A sample configuration xml can be found
below (see MyAddons.xml):

<?xml version="1.0" encoding="utf-8"?>

<AddonsData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<Addons>

<Addon>

<Name>HelloWorld</Name>


<FullPath>C:\Samples\HelloWorld\HelloWorld\Bin\Debug\HelloWorld.dll</FullPath>

</Addon>

<Addon>

<Name>MyAddon1</Name>

<FullPath>C:Samples\MyAddon1.dll</FullPath>
</Addon>

<Addon>

<Name>MyAddon2</Name>

<FullPath>C:Samples\MyAddon1.dll</FullPath>
</Addon>

</Addons>

</AddonsData>

This only needs to be done once per addon .dll. Any new commands added to the assembly designated by
the " CommandMethodAttribute" attribute will be automatically recognized as a separate command that
can be run when Advance Steel is loaded.

Run the addon

https://help.autodesk.com/view/ADSTPR/2021/ENU/?guid=GUID-A4DA627E-6680-4388-9C04-79F5F3D9D075 9/10
11/10/21, 4:29 PM Help | Walkthrough: Hello World | Autodesk

To run the addon command, start Advance Steel. Then simply type in the name of the command, in this
case, HelloWorld, and hit enter.

If you need to debug your addon, you can follow these steps:

1. Start Advance Steel.


2. In Visual Studio, put a breakpoint where you would like to stop the code in your command.
3. From the Debug menu, select Attach to Process...
4. Select the acad.exe process.
5. Run your command in Advance Steel and your breakpoint will be triggered in Visual Studio.

Parent topic: Walkthroughs

Except where otherwise noted, this work is licensed under a Creative Commons Attribution-
NonCommercial-ShareAlike 3.0 Unported License. Please see the Autodesk Creative Commons FAQ
for more information.
© 2021 Autodesk Inc. All rights reserved

https://help.autodesk.com/view/ADSTPR/2021/ENU/?guid=GUID-A4DA627E-6680-4388-9C04-79F5F3D9D075 10/10

You might also like