Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
28Activity
0 of .
Results for:
No results containing your search query
P. 1
Autodesk Inventor - VBA-api pt1

Autodesk Inventor - VBA-api pt1

Ratings: (0)|Views: 2,352 |Likes:
Published by Ndianabasi Udonkang
This is a continuation of my uploads of any Autodesk Inventor tutorial

file that I lay my hands on. Most of these files are from Autodesk skill

builder site. Datasets are meant to be downloaded for most of the

tutorials here. So kindly go to

http://usa.autodesk.com/adsk/servlet/autoindex?

siteID=123112&id=3365505&linkID=9242016. Browse through the index to

located the corresponding tutorial there.

Kindly subscribe to my profile to receive updates. You can join Autodesk

student community, Autodesk University, and Autodesk Manufacturing

community. If you have comments email me at

ndianabasi.udonkang@gmail.com. Hope to hear from you.
This is a continuation of my uploads of any Autodesk Inventor tutorial

file that I lay my hands on. Most of these files are from Autodesk skill

builder site. Datasets are meant to be downloaded for most of the

tutorials here. So kindly go to

http://usa.autodesk.com/adsk/servlet/autoindex?

siteID=123112&id=3365505&linkID=9242016. Browse through the index to

located the corresponding tutorial there.

Kindly subscribe to my profile to receive updates. You can join Autodesk

student community, Autodesk University, and Autodesk Manufacturing

community. If you have comments email me at

ndianabasi.udonkang@gmail.com. Hope to hear from you.

More info:

Published by: Ndianabasi Udonkang on Jun 18, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

07/11/2013

pdf

text

original

 
VBA/API - Part 1
By Neil MunroAutodesk Inventor™ 5 includes Microsoft's Visual Basic for Applications (VBA) as an embedded customization tool. In this month's andnext month's tutorials we'll introduce a few of the concepts you'll need to understand if you want to extend Autodesk Inventor with VBAmacros. In addition, we'll get our programming hands dirty with a small macro to track the center of gravity of an assembly. In thismonth's tutorial, we'll concentrate on the VBA environment; next month we'll look at accessing the Autodesk Inventor API.
Note:
You can follow these tutorials even if you have no prior programming experience. However, before you begin, read the APIOverview section in the Programming Help file (which is available only if you do a complete or custom installation of Autodesk Inventor5). You don't need to understand the entire file, but the instructions in these tutorials will make more sense if you have some familiaritywith the concepts discussed in it. A good understanding of how Autodesk Inventor software works is a prerequisite to anycustomization effort.
Start with a Plan
As usual, a little planning goes a long way. The macro we want to create must:Track the center of gravity (COG) of the assembly.Present an object that can be used with Autodesk Inventor software's Measure tool to determine the distance between key assemblypoints (rotation axis, mounting points, and so on) and the COG.Not affect the COG calculations.Present a continuous display of the assembly COG coordinates.The Autodesk Inventor API (application programming interface) enables you to create custom objects that could fulfill the aboverequirements, but their creation and manipulation is beyond the scope of these tutorials. We'll use a predefined Marker part (see Figure1) to track the assembly COG. We'll assign the part a material with zero density to exclude it from mass and assembly COG calculations.Because it is a part, we can use the built-in origin geometry as helper objects during distance measurements to the assembly COG. Inaddition, the three orthogonal cylinders through the sphere will align with the X, Y, and Z axes of the assembly. So that we can see thepart in assemblies of varying scales, we'll add the ability to quickly scale the part.Figure 1: Marker.ipt. 
Autodesk - Autodesk Inventor Services & Support - VBA/API - Part 1http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=234582...1 of 111/21/2010 6:36 PM
 
Figure 2: VBA integrated development environment.
Note:
The COG.IPT will be provided with next month's tutorial.
Macros and the VBA Environment
The criteria for our macro require that we have some form of a user interface (UI). To keep it simple, the Marker part will update itsposition to match the assembly COG only on the user's command. The display of origin geometry and the scale of the COG part arechanges that also require user interaction. Finally, the display of the current assembly COG coordinates will require a user interface.Although our macro will have a UI, it is not a requirement. You can create useful and complex macros that do not require any userinteraction.Autodesk Inventor macros can be stored in three places. A macro can be:Embedded in a document.Defined in a default VBA project.Defined in an external VBA project.The API Overview in the Programming Help file outlines these options. We'll use an external VBA project to maximize transportability ofthe macro.To create a new VBA project:1. From the main menu in Autodesk Inventor, Select Tools > Macro > Visual Basic Editor from the drop-down menu.The VBA IDE (integrated development environment) displays (see Figure 2).Figure 3: Module editing.2. Select Tools > Options from the Visual Basic Editor menu.3. On the Editor tab, place a check mark in the Require Variable Declaration check box. Then click OK. (We'll explain this setting later.)4. Select File > New Project.A new project (UserProject1) is added to the Project Explorer. The project currently has no macros defined, so we'll need to add ourmacro, and then build the UI for the macro.A macro can perform operations that range from a single simple task to a complex application. Adding a subroutine in a moduleattached to the project creates a macro. So, what's a module or subroutine you ask?A VBA module is a container for programming code (more explanation as we progress). A subroutine is a specific set of programminginstructions used to perform a task. Subroutines can be created inside a module, and if the subroutine has no arguments, it isrecognized as a macro. Are you confused yet? It should become much clearer as we go through the following steps.5. Expand UserProject1 in the Project Explorer.6. Expand Modules under UserProject1 (Module1 is included).7. Double-click Module1. The Edit window is filled with the opened Module1 (see Figure 3).
Autodesk - Autodesk Inventor Services & Support - VBA/API - Part 1http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=234582...2 of 111/21/2010 6:36 PM
 
Figure 4: CogTool subroutine.Let's examine the newly displayed tools.The list of procedures enables you to quickly access a particular named procedure in the module (you can define many differentprocedures in a module).The Code window is where you type in the instructions associated with a procedure (a subroutine is one of a number of proceduraltypes). For now, we'll ignore the Option Explicit code shown in the Code window.
Add a Subroutine to the Module
Now, let's create a subroutine in Module1, which Autodesk Inventor will recognize as a macro and which we'll use to start our assemblyCOG tracker.1. From the Visual Basic Editor menu, select Insert > Procedure.2. Enter
CogTool 
in the Name textbox. Note that the default settings are to create a Public subroutine. These are two of the requirementsfor a macro, so click OK to create the subroutine. Your Code window should now match Figure 4.Figure 5: Insert UserForm.A subroutine contains code to perform a specific task and can be called from other code. Other things of interest about subroutine codeinclude:To be recognized as a macro, a subroutine must be public.The subroutine code is typed into the area before the End Sub statement.The parentheses at the end of the subroutine declaration can contain arguments that are passed to (and can be returned from) thesubroutine. To be recognized as a macro, the subroutine must have no arguments.An example of a subroutine with arguments is shown below.
Public Sub AddTwo (Int1 as Integer, Int2 as Integer, Ans as Integer)Ans = Int1 + Int2End Sub
Other program code could call this subroutine using the following syntax:
Call AddTwo (5, 6, MyAns)
The Int1 and Int2 arguments are assigned the values 5 and 6 respectively. The Ans argument is linked to the MyAns variable in atwo-way relationship. MyAns is assigned the value of Ans at the end of the subroutine (11 in this case).
Displaying the UI for Our Macro
We have in place all the elements to define the macro, so let's add some instructions to actually perform something. We are planning tobuild a UI for our macro, so we'll add code to display our user interface. But before we add the code to show our UI, let's add thecontainer (UserForm) for the user interface.1. In the Project Explorer window, right-click UserProject1 and select Insert > UserForm from the shortcut menu that appears (seeFigure 5).
Autodesk - Autodesk Inventor Services & Support - VBA/API - Part 1http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=234582...of 111/21/2010 6:36 PM

Activity (28)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Akhid Rosyidi liked this
Nebojša G. liked this
Akhid Rosyidi liked this
Chulka liked this
woongs73 liked this
safit liked this
Fredy Gomez liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->