100% found this document useful (1 vote)
2K views

Autodesk Inventor Programming in C++

This document is the table of contents for a book titled "Autodesk Inventor Programming in C++" by Owen Ransen. It lists 37 chapter titles that provide information and examples for programming Autodesk Inventor using C++. The chapters cover topics such as opening and modifying Inventor documents programmatically, working with dimensions, views, and sheets in drawings, adding constraints, and handling errors when programming with the Inventor API. The book is intended to teach programmers how to use the Autodesk Inventor API from C++ code.

Uploaded by

Duy Nguyen Duc
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views

Autodesk Inventor Programming in C++

This document is the table of contents for a book titled "Autodesk Inventor Programming in C++" by Owen Ransen. It lists 37 chapter titles that provide information and examples for programming Autodesk Inventor using C++. The chapters cover topics such as opening and modifying Inventor documents programmatically, working with dimensions, views, and sheets in drawings, adding constraints, and handling errors when programming with the Inventor API. The book is intended to teach programmers how to use the Autodesk Inventor API from C++ code.

Uploaded by

Duy Nguyen Duc
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 273

Autodesk

Inventor Programming in C++ by Owen Ransen


Autodesk Inventor Programming in C++ by
Owen Ransen
(c) Owen Ransen 2016

All rights reserved. No parts of this work may be reproduced in any form or by any means - graphic, electronic, or
mechanical, including photocopying, recording, taping, or information storage and retrieval systems - without the written
permission of the publisher.

Products that are referred to in this document may be either trademarks and/or registered trademarks of the respective owners.
The publisher and the author make no claim to these trademarks.

While every precaution has been taken in the preparation of this document, the publisher and the author assume no responsibility
for errors or omissions, or for damages resulting from the use of information contained in this document or from the use of
programs and source code that may accompany it. In no event shall the publisher and the author be liable for any loss of profit
or any other commercial damage caused or alleged to have been caused directly or indirectly by this document.

Printed: dicembre 2016 in (whereever you are located)


Table of Contents
Foreword 11

Part I Autodesk Inventor Programming in C++ 13


Part II 1) How to use this book 15
Part III 2) Introduction 17
Part IV 3) AutoDesk Inventor Book Source Code 19
Part V 4) The Inventor Project and Project Fiolder 21
Part VI 5) The basic architecture of the program 23

Part VII 6) MakeInventorGlobals and


DestroyInventorGlobals 26

Part VIII 7) Running Inventor programatically 28


Part IX 8) Creating a part document and a sketch 30
Part X 9) Creating a solid object inside a part 36
Part XI 10) Load a part and change its parameters 39

Part XII 11) Insert two parts into an assembly at


specified positions 42 Part XIII X) Some tips for Autodesk Inventor C++
programmers 44 Part XIV Programming Inventor 46
1 Compile/Link Errors and how to correct
them................................................................................................................................... 46

_WIN32_WINNT e rror .......................................................................................................................................................... 46


e rror MSB3075: The command re g s vr32 /s /c... .......................................................................................................................................................... 46
Error MK_E_UNAVAILABLE 0x800401e 3 .......................................................................................................................................................... 46
Include file paths .......................................................................................................................................................... 47
CLSIDFromProg ID e rror re s olution .......................................................................................................................................................... 49
C2064: te rm doe s not e valuate to a function taking 0 arg ume nts .......................................................................................................................................................... 49
C2774 compile e rror .......................................................................................................................................................... 50
Faile d to re g is te r .......................................................................................................................................................... 50
Four API me thods warning whe n compiling for MFC .......................................................................................................................................................... 50
2 Open an Inventor part
prog ramatically................................................................................................................................... 51
3 Referenced Document of a View................................................................................................................................... 53

4 Retrievable Dimensions................................................................................................................................... 54
5 Show a dimension prog ramatically...................................................................................................................................
59
6 Dimensions in a drawing sheet................................................................................................................................... 63
7 g etType and ObjectTypeEnum................................................................................................................................... 64
8 Listing types of dimensions in a
view................................................................................................................................... 66
9 Getting the version of Inventor
prog ramatically................................................................................................................................... 67
10 QueryInterface and Release Etc...................................................................................................................................
68
11 CComQIPtr is better than
QueryInterface................................................................................................................................... 69
12 Counting the number of documents open in
Inventor................................................................................................................................... 69
13 CustomTables in Sheets and
Drawing s................................................................................................................................... 71
14 New line within table cells................................................................................................................................... 73
15 CreateDoubleVariantArray................................................................................................................................... 73
16 CreateSafeString Array................................................................................................................................... 74
17 Open an assembly part
prog ramatically................................................................................................................................... 75
18 Create a drawing file (IDW or
DWG)................................................................................................................................... 75
19 How to add views to a drawing sheet (Inventor
API)................................................................................................................................... 76
20 Names of views prog ramatically...................................................................................................................................
80
21 Creating projected views from base
views................................................................................................................................... 80
22 Open an assembly invisibly................................................................................................................................... 82
23 Drawing View Styles................................................................................................................................... 83
24 Close function for Parts and
Assemblies................................................................................................................................... 83
25 GetInventorDocTypeDesc................................................................................................................................... 84
26 Getting the current document of
Inventor................................................................................................................................... 84
27 Adding a sheet to a drawing ................................................................................................................................... 86
28 HRESULT codes................................................................................................................................... 89
29 Add a mate constraint with two planes
prog ramatically................................................................................................................................... 91
30 Proxies, why and what?................................................................................................................................... 92

31 ErrorManag er, errors and warning s, ShowCOMError and


ReturnAndShowCOMError................................................................................................................................... 95

32 Looping over views in sheets................................................................................................................................... 96


33 Listing and checking constraints...................................................................................................................................
97
34 Saving apparently disabled
(SilentOperation)................................................................................................................................... 98
35 WorkAxes in Inventor prog rams...................................................................................................................................
99
36 Wrapping COM and C++................................................................................................................................... 100
37 Units when prog ramming
Inventor................................................................................................................................... 101
38 Exporting Paramenters................................................................................................................................... 102
39 Placing objects in space Vector and
Matrix................................................................................................................................... 102
(c) Owen Ransen 2016
40 ObjectCollections in the Inventor API (transient object
collections)................................................................................................................................... 103

41 Creating a new Part Document...................................................................................................................................


104
42 How to extrude a sketch
prog ramatically................................................................................................................................... 106
43 Transient Geometry................................................................................................................................... 110
44 Chang ing the application visibility...................................................................................................................................
112
45 A matrix to rotate an object................................................................................................................................... 112
46 Proxies, WorkAxes, Vectors and
Points................................................................................................................................... 114
47 WorkFeatures and iParts................................................................................................................................... 115
48 What are PatternElements?................................................................................................................................... 116
49 What sort of WorkFeature is this?...................................................................................................................................
117
50 IDispatch................................................................................................................................... 118
51 Interrog ating rectang ular
patterns................................................................................................................................... 119
52 Name of part in a component
occurrence................................................................................................................................... 121
53 Add an occurrence to an assembly does not
work................................................................................................................................... 123
54 Listing constraints in an assembly
prog ramatically................................................................................................................................... 124
55 Listing members in an iPartFactory
prog ramatically................................................................................................................................... 125
56 PartComponentDefinition from an
occurrence................................................................................................................................... 127
57 AddiPartMember................................................................................................................................... 128
58 Getting the workplanes of a part occurrence in an
assembly................................................................................................................................... 129
59 SubOccurrences................................................................................................................................... 130
60 SaveAs function................................................................................................................................... 130
61 Save prog ramatically................................................................................................................................... 131
62 Close function, Inventor API................................................................................................................................... 132
63 Visibility prog ramatically in
Inventor................................................................................................................................... 132
64 AddCustomiPartMember details and
tips................................................................................................................................... 133
65 Add in the occurrence of a custom iPart into an
assembly................................................................................................................................... 134
66 Occurrences and component
definitions................................................................................................................................... 135
67 How to g et the parameters of an
assembly................................................................................................................................... 137
68 g et_Item and Item, what sort of
parameter?................................................................................................................................... 139
69 Suppression and Unsuppression of
features................................................................................................................................... 140
70 How to g et the value of a user
parameter................................................................................................................................... 142
71 Suppression and Unsuppression of elements in a
pattern................................................................................................................................... 142
72 How to open a document
prog ramatically................................................................................................................................... 144
73 Function calls in Autodesk Inventor C++
prog ramming ................................................................................................................................... 144
74 Names of objects inside sketches...................................................................................................................................
145
75 COM pointers when prog ramming AutoDesk
Inventor................................................................................................................................... 145
76 Create a rectang ular pattern
prog ramatically................................................................................................................................... 149
77 VARIANT_BOOL................................................................................................................................... 153
78 ParameterPtr and g et_XCount...................................................................................................................................
153
79 Model and User parameters
prog ramatically................................................................................................................................... 154
80 Getting s objects by name................................................................................................................................... 157

81 How to g et the Rectang ularPatterns in a


PartComponentDefinition................................................................................................................................... 159

82 ResultFeatures................................................................................................................................... 160
83 ObjectsEnumerator, a list of
objects................................................................................................................................... 161
84 Parameter types................................................................................................................................... 161
85 Face Edg e Edg eProxy................................................................................................................................... 162
86 Attributes................................................................................................................................... 163
87 CreateExtrudeDefinition................................................................................................................................... 167
88 Inserting an extrusion in a Part...................................................................................................................................
168
89 Optional parameters and empty COM
values................................................................................................................................... 169
90 Points and CenterPoints................................................................................................................................... 170
91 GetTemplateFile................................................................................................................................... 171
92 Add a (planar) sketch to a workplane
prog ramatically................................................................................................................................... 172
93 Component Definition................................................................................................................................... 173
94 Adding a workplane to a Part
prog ramatically................................................................................................................................... 176
95 Set the visibility of all workplanes in a
part................................................................................................................................... 178
96 g et_ActiveDocument................................................................................................................................... 178
97 Get and Set the name of an Inventor
document................................................................................................................................... 179
98 The .AddIn file................................................................................................................................... 180
99 Adding a flush constraint
prog ramatically................................................................................................................................... 181
100 Adding a flush constraint using
workplanes................................................................................................................................... 184
101 Constraints and parts from a prog rammer's point of
view................................................................................................................................... 185
102 Loading your DLL................................................................................................................................... 187
103 Sketches in an Inventor Part................................................................................................................................... 187
104 Add a circle to a sketch function...................................................................................................................................
189
105 Default workplanes and default sketches
prog ramatically................................................................................................................................... 190
106 Add a work point at a sketch
point................................................................................................................................... 192
107 Getting and setting the sketch name (as well as other
objects)................................................................................................................................... 194
108 Rectang ular Pattern................................................................................................................................... 195
109 PatternSpacing TypeEnum................................................................................................................................... 197
110 PatternOrientationEnum................................................................................................................................... 198
111 Occurences as Xrefs................................................................................................................................... 198
112 VT_I4 ................................................................................................................................... 198
113 CreateObjectCollection................................................................................................................................... 199
114 rg s file for Inventor AddIns, what is
it?................................................................................................................................... 199
115 BSTR OLECHAR wchar_t................................................................................................................................... 199
(c) Owen Ransen 2016

116 AddForSolid................................................................................................................................... 200


117 VBA, VB.NET, C# or C++................................................................................................................................... 201
118 Profiles in sketches
prog ramatically................................................................................................................................... 201
119 Installing the SDK................................................................................................................................... 201
120 Creating an Assembly................................................................................................................................... 202

121 Getting the project file location and other options


prog ramatically................................................................................................................................... 204

122 reg svr32 ................................................................................................................................... 206


123 What and where is the AddIn
manag er?................................................................................................................................... 207
124 RxInventor.tlb................................................................................................................................... 208
125 Adding a rectang le to a sketch...................................................................................................................................
209
126 g et_ and Get ?................................................................................................................................... 211
127 UserInterfaceVersion................................................................................................................................... 211
128 Difference between CComPtr and
CComQIPtr?................................................................................................................................... 212
129 VARIANT and CComVariant...................................................................................................................................
212
130 Getting items from collections...................................................................................................................................
213
131 Assembly.Document Assembly...................................................................................................................................
214
132 64bit vs 32bit................................................................................................................................... 215
133 Client Graphics................................................................................................................................... 215
134 Hierarchy of objects................................................................................................................................... 215
135 Getting or running an Inventor
Instance................................................................................................................................... 215
136 Add a part to an assembly
prog ramatically................................................................................................................................... 216
137 Getting hold of the surfaces and faces of a solid
object................................................................................................................................... 217
138 Creating a 64 bit plug in using the
Wizard................................................................................................................................... 219
139 Button Definition................................................................................................................................... 220
140 Materials API................................................................................................................................... 223
141 Investig ating Asset Libraries
Prog amatically................................................................................................................................... 224

Part XV Using Inventor manually 227


1 iParts ................................................................................................................................... 227

iParts g e ne ral info .......................................................................................................................................................... 227


iPart - s tandard vs cus tom .......................................................................................................................................................... 227
iPart author .......................................................................................................................................................... 228
iPart Me mbe r and PartNumbe r .......................................................................................................................................................... 228
Cus tom iParts .......................................................................................................................................................... 229
Chang ing Cus tom Ipart Parame te rs .......................................................................................................................................................... 232
Suppre s s ion of fe ature s parame trically us ing the iPart Author .......................................................................................................................................................... 234
Chang ing from iPart back to normal part .......................................................................................................................................................... 234
2 Patterns (arrays) of features................................................................................................................................... 235

3 Problems encountered while executing this


command.................................................................................................................................... 237
4 Suppression and mirrored features...................................................................................................................................
237
5 Filename of referenced doc................................................................................................................................... 238
6 Open a part from a view................................................................................................................................... 238
7 Crash when creating a new
drawing ................................................................................................................................... 239
8 Project files................................................................................................................................... 240
9 File types................................................................................................................................... 241
10 Creating a drawing of an assembly or
part................................................................................................................................... 242
11 Delete a parameter................................................................................................................................... 243
12 FlipNormal and WorkPlane
constraints................................................................................................................................... 244
13 Add a point to the surface of a tube
manually................................................................................................................................... 244
14 Add a feature to an existing
pattern................................................................................................................................... 245
15 Chang e the offset elevation of a
plane................................................................................................................................... 246
16 Removing material with the cut extrusion
command................................................................................................................................... 247
17 Templates and Template files................................................................................................................................... 248
18 Problem when inserting iParts into
Assemblies................................................................................................................................... 250
19 Plane on the surface of a tube at an
ang le................................................................................................................................... 251
20 Add an ang ular dimension................................................................................................................................... 252
21 Editing Model Parameters and how they are
displayed................................................................................................................................... 253
22 Chang ing the default units................................................................................................................................... 254
23 Adding a Dimension in a sketch...................................................................................................................................
255
24 WorkPoint in center of a hole................................................................................................................................... 256
25 Extruding sketches with multiple concentric
circles................................................................................................................................... 257
26 Getting to the constrain icon in
Inventor................................................................................................................................... 258
27 Deleting , removing a constraint...................................................................................................................................
258
28 Creating a big tube with holes in
it................................................................................................................................... 258
29 Contraints between 3D part
objects................................................................................................................................... 263
30 Creating a workplane offset from another
plane................................................................................................................................... 264
31 Flush Mate And Axis Constraint
Example................................................................................................................................... 265
32 How to chang e the backg round of the Inventor
screen................................................................................................................................... 267
33 Browser is missing ! Get it back!...................................................................................................................................
267
34 Work Axis Thru Circular Hole...................................................................................................................................
267
35 Driven Dimensions and their
Removal/Chang e................................................................................................................................... 268
36 Example of dimensions and parameters in a
sketch................................................................................................................................... 268
37 Work Point in center of a hole
(COPY)................................................................................................................................... 272
38 Inserting an inclined workplane...................................................................................................................................
273
39 Chang e material / color of a solid...................................................................................................................................
274
40 Viewing Multiple Documents in
Inventor................................................................................................................................... 275
41 How to move a 3D object................................................................................................................................... 276
42 Contact set................................................................................................................................... 276
43 iLog ic ................................................................................................................................... 277

(c) Owen Ransen 2016

44 Showing expressions in a sketch...................................................................................................................................


277
45 No visible unadaptive sketches...................................................................................................................................
277
46 How to make a hollow tube................................................................................................................................... 278
47 The Marking Menu................................................................................................................................... 278
48 Customizing the menu................................................................................................................................... 278
49 fx: and parameters and formulas...................................................................................................................................
278
50 Showing dimensions temporarily...................................................................................................................................
279
51 View face command................................................................................................................................... 279
52 Chang ing home view setting ................................................................................................................................... 279
53 Create a sketch by default on creating a new
part................................................................................................................................... 280
54 Inches problem................................................................................................................................... 280
55 Backup options for Inventor files...................................................................................................................................
280
56 ul as a dimension................................................................................................................................... 281
57 Editing a sketch flatly................................................................................................................................... 281
58 Enable and Disable parts and
assemblies................................................................................................................................... 281
59 Yellow Dot Green Dot Constraints...................................................................................................................................
282
60 Completely and adequately constrained
sketches................................................................................................................................... 282
61 Sketch plane................................................................................................................................... 283
62 Extruding with widening ang les...................................................................................................................................
283
63 Getting into and out of sketches...................................................................................................................................
283
64 Trim and Fillet................................................................................................................................... 284
65 Sketches and Features................................................................................................................................... 285
66 Vault ................................................................................................................................... 286
67 Inventor Apprentice................................................................................................................................... 286

68 Workplanes and Sketches, Creating a sketch on an arbitrary


plane ................................................................................................................................... 287

69 Grounded Parts................................................................................................................................... 288


70 Chang ing manipulator snap................................................................................................................................... 288
71 Get the browser pane back................................................................................................................................... 288
72 Application Options Setting s................................................................................................................................... 289
73 Mini tool bar autofade................................................................................................................................... 289

Part XVI Acknowledgements 291 Index 292 Autodesk Inventor Prog ramming in C++ 13

1 Autodesk Inventor Programming in C++


Inventor Programming in C++ is a dynamically growing online book full of useful tips and
code fragments. It is aimed at C++ programmers who want to use the Autodesk Inventor API.

This version March 2014


Several people at Autodesk helped me with my doubts and questions, so here are the
acknowledgements!
Now read How to use this book.
Contact Owen Ransen at [email protected] for more details. 1) How to use this book 15

2 1) How to use this book

You should read in sequence the numbered parts, starting with this one. These will give you a
brief and neccessary overview of the Inventor API, with examples.

Then you should use the index to find answers to specific questions as they pop up when you
create your own Autodesk Inventor C++ programs.
If you are a subscriber, and have any questions not answered here, then please contact me,
Owen Ransen, at [email protected].

I've also included tips on Using Inventor Manually (the second book icon in the contents list to
the left of this page). You may be a programmer but you do need how to use Inventor as a
normal user before you can hope to program it! There are a ton of tutorials out there about
using Inventor. If neccessary please do at least some of them before attempting the rest of this
book.

Now, go to 2) Introduction. 2) Introduction 17

3 2) Introduction
If you've decided to program Inventor in C++ you can do it in many different ways, but
basically either you create an AddIn (not covered in this book) or you create an external exe
file. See the diagrams below.

Both systems use the COM interface, and this book is useful for both types. However this
book covers the external EXE solution using C++. Since both methods use the COM interface
most of this book is applicable to both types of application.

If you are not familiar with the COM interface don't worry, I give lots of examples,
explanations and tips on its use.
I use Visual Studio 2010, C++ with MFC, and so do the example sources.
3) The source code for the book. 3) AutoDesk Inventor Book Source Code 19

4 3) AutoDesk Inventor Book Source Code

The source code can be downloaded at http://www.ransen.com/InventorCpp/Inv_Src.zip .


People who have subscribed to the book will get the password to the course and the zip file.

For simplicity I've placed the project and solution in C: \Inv_Book_Sources on my computer.
You will also need the files in this zip:
http://www.ransen.com/Files-For-Autodesk-Inventor-Programming-InCpp.zip

The source code revolves around a single MFC dialog. (If you do not know C++ and MFC
then learn those two subjects before attempting this book.)
What you need to do now is try to compile the source file and run the application. As you start
to compile and link you may get errors. Look in the index of this book for the error messages
and error numbers, I've documented as many as I've found, with solutions to the problems,
where possible.

Once you have compiled and run the EXE go to 4) The basic architecture of the program.
4) The Inventor Project and Project Fiolder 21

5 4) The Inventor Project and Project Fiolder

If you don't know what Inventor projects are you'd better find out before continuing with this
book. There are some hints here. I've setup a project and project folder for the objects used
and created in this book (C: \InvBook) :

When
you run the program in this book make sure that you have set the Inventor project to InvBook.
5) The basic architecture of the prog ram 23

6 5) The basic architecture of the program

The program creates and runs a dialog which has buttons. The buttons do things via the
Inventor API:

Have a look at InvBookSrc.cpp, which contains the "main" of the application. Here's the part
we are most interested in:
// Start up the COM communications, the Inventor API is a COM API
::CoInitialize (NULL) ;
// Connect to Inventor and get useful pointers CreateInventorGlobals () ;

// ...blah blah... // ...blah blah... // ...blah blah...

CInvBookSrcDlg dlg; // This is the dialog with all the buttons m_pMainWnd = &dlg;
dlg.DoModal(); // Run the dialog with all the buttons // Disconnect from Inventor
DestroyInventorGlobals () ;
// Stop communicatons with COM... ::CoUninitialize();
CoInitialize and CoUninitialize are required to be able to use COM and its pointers. What I do
is, in sequence:

1. CoInitialize starts up COM and COM pointer handling.


2.CreateInventorGlobals, sets up things useful to me as my Inventor program is running. It
also starts Inventor running.
3.dlg.DoModal actually runs the dialog with buttons which the user can use to make objects
with the Inventor API.
4.DestroyInventorGlobals tidies up my pointers after the dialog has finished (i.e. when I come
out of DoModal).
5.::CoUninitialize for the final tidy up of the COM pointers and interface
Step 3 above is the heart of the program, that is what most of this book is about.
7) MakeInventorGlobals, pointers and DestroyInventorGlobals

7 6) MakeInventorGlobals and DestroyInventorGlobals

These two functions initialize and deallocate pointers which are use frequently in Autodesk
Inventor C++ programming. I've called them "globals" because they are accessible from
theApp MFC application global.

They can be found in InvBookSrc.cpp and InvBookSrc.h. You will, in general, call the
following functions to get hold of the pointers as you need them:

CComPtr<Application> GetInvAppPtr () ; // pointer to the inventor application


CComPtr<TransientGeometry> GetTransGeomPtr () ;
CComPtr<TransientObjects> GetTransientObjectsPtr() ;

The Inventor application pointer is the main method for getting data from Inventor and
sending commands to it.
The transient geometry pointer lets you create matrices, vectors etc. Explained more here.

The transient objects pointer is used to make temporary collections of objects you need to
operate on, for example a list of holes in a solid object or some workplanes arranged
somewhere in a part. TransientObjectCollections are explained more here.

Have a look at MakeInventorGlobals and DestroyInventorGlobals to see how they work.


7) Running Inventor Programatically.

8 7) Running Inventor programatically

The function MakeInventorGlobals has to actually run Inventor before it can get at objects
inside it. It does this with a call to ConnectToInventor. This function is defined in
InventorHelpers.cpp. Have a look at the function as you read this decription.

ConnectToInventor sees if Inventor is installed on your computer or not, and whether it is


running already or not. On some computers starting Inventor can take several seconds.

If you are not familiar with COM have a quick read of this explanation of the FAILED macro,
and other HRESULT codes and macros.
The function ReturnAndShowCOMError is used to give you more information about any
failure, and to return the fail code. More here.
8) Creating a part document and a sketch

9 8) Creating a part document and a sketch

The first thing most users do with Inventor is to create a sketch inside a part document, so that
is what we will do with our first button. Have a look inside InvBookSrcDlg.cpp. This is the
dialog which handles all the button clicks at the top level.

Find the function called


void CInvBookSrcDlg::OnBnClickedCreateSketch()

This is the function which is run when the top button is clicked. (This is all fairly standard
MFC/C++ programming so far, and you need that knowledge to follow the explanations in
this book.)

You can see that first a new Part document is created called L"MY NEW PART DOC". Notice
the L at the start of the string. I'm assuming that we will always use wide char, wchar_t,
UNICODE or CStrings for our string data.

A "part" is usually a collection if solid objects with holes or cuts or extrusions. An assembly
is usually a collection of parts, or more formally a set of occurrences of parts. See here for
the file types in Inventor.

Anyway, sticking to parts for the moment, CreateNewPartDoc is a function which does all you
need to create a new part document in Inventor. I've put it inside the file InventorHelpers.cpp.

Unfortunately, the part document isn't really where all the "stuff" is. All the "stuff" is inside a
PartComponentDefinition:
As you can see the PartComponentDefinition contains a lot of lists, and one of the lists
contains sketches, and we'll create a new sketch in that list. But before we do that we have to
get hold of the
PartComponentDefinition. That is done like this:

// Get the component definition of the part, where all the "stuff" is...
CComPtr<PartComponentDefinition> pPartCompDef = nullptr ;
hRes = pPartDoc->get_ComponentDefinition(&pPartCompDef) ;
if (FAILED(hRes) || (pPartCompDef == nullptr)) {
ShowCOMError (hRes,L" get_ComponentDefinition failed.");
}

I'll go into some detail about the these four lines because they illustrate how the Inventor API,
C++ and COM talk to each other.

Many of the variables in C++ programs using COM are smart pointers. In the above example
the smart pointer is pPartCompDef. Using smart pointers like this means that you don't need
to allocate and deallocate them explicitly, it is all done by the smartness of the pointer. So
when we do this:
CComPtr<PartComponentDefinition>pPartCompDef = nullptr ;
we don't need to delete or release pPartCompDef after use, it will all happen automatically
when the pointer goes out of scope.
Also note that I've initialised it to nullptr. This is my own personal style, it means it is
initialised even if I forget to call a function to initialise it.
In general many functions we call in the Inventor API take the address of a pointer and
initialise it, as well as returning a status. For example:
hRes = pPartDoc->get_ComponentDefinition(&pPartCompDef) ;

pPartCompDef will be initialised to point at an object, and you'll get a return value placed in
hRes. Why two return values? Because in some circumstances the pointer returned can be
validly nullptr. hRes might return S_OK, because the function did not fail, but the pointre
could still be nullptr because the object you were looking for does not exist. It is for that
reason that I always look at both return values:

if (FAILED(hRes) || (pPartCompDef == nullptr)) { Click here for more about S_OK,


HRESULT and FAILED.
So you'll see that pattern of four lines in many of the examples in the source code.
I've made a function, CreateXYPlaneSketch. You can have a look at the actual code, but here is
the prototype:
bool CreateXYPlaneSketch (CComPtr<PartComponentDefinition>& pPartCompDef, // where
to add the sketch

CComPtr<PlanarSketch>& pNewSketch, // The sketch created, an output


const wchar_t* const pszSketchName) // Name of the newly created sketch

Note that I pass in a name for the sketch. I advise you to always use signifigant names to the
objects you create. Else you'll get lost in a maze of "WorkPlane33", "Sketch1", "WorkPoint56"
etc. Your memory is not as good as you imagine it is, so use names like "TubeBaseSketch"
and " InsertionPlane" and "BananaRotationAxis".

After we've made the sketch we add a circle to the sketch by calling AddCircleToSketch. Note
that AddCircleToSketch uses the transient geometry pointer:

CComPtr<TransientGeometry>pTransGeom = theApp.GetTransGeomPtr () ;

GetTransGeomPtr is explained here, Transient Geometry is explained here. The transient


geometry pointer is used to create a 2D point which allows us to specify the origin of the
circle we are putting into the 2D sketch.

Graphically this is what we have done, we've put a circle inside a Sketch, which is inside a
Part Component Definition which is inside a Part Document:
A
doddle eh? And along the way you've learned a ton of stuff. Now lets do some 3D stuff and
extrude a circle to create a solid cylinder. 9) Creating a solid object from a sketch.

10 9) Creating a solid object inside a part

The second button handler of InvBookSrcDlg.cpp is called:


void CInvBookSrcDlg::OnBnClickedCreateTube()
and will give you a result like this:

Have a look at the source code for this function. It is almost identical to the circle to sketch
adding function of the previous section, apart from a call to ExtrudeSketch:
const double kHeight = 18.0 ;
hRes = ExtrudeSketch (L"My_Extrusion", // name of created feature
kHeight,
szSketchName, // which sketch to extrude

kNewBodyOperation, // how to extrude kPositiveExtentDirection,


pPartCompDef) ;

There's a ton of parameters there to look at before we delve into the function itself. The first
one is a wide char UNICODE name for the extrusion we are going to create.
9) Creating a solid object inside a part 37

The second one is the height of the extrusion. In which units though? Have a look here for an
explanation of units in Inventor API programming .

The next parameter is the sketch name, and we pass it the name of the sketch we created at the
start of the function:
const wchar_t* const szSketchName = L"Circle_Sketch" ; So you can imagine that
ExtrudeSketch will search for L"Circle_Sketch" in the list of sketches.
Next is how to extrude the sketch. We want to create a new body, so use kNewBodyOperation,
but look here for the alternatives.

The next parameter says in which direction we want to extrude the sketch. Generally the
extrusion is along a normal to the plane of the sketch, but is it negatively, positively, or in
both directions? I've chosen kPositiveExtentDirection. See here for the other possibilities.

Finally, the last parameter is the PartComponentDefinition where we want to add the solid
object.
The complete function ExtrudeSketch is explained here. 10) Load a part and chang e its parameters 39

11 10) Load a part and change its parameters

The third button on the dialog runs some code to load a part (C: \InvBook\Parametric-
Tube.ipt), list its parameters (it has 3) then change 2 of them.
This is an illustration of one of the tips, i.e. you don't need to program stuff which Inventor
already can do for you. In this case I did not need to create a new cylinder from scratch using
sketches and extrusions, I just had to use a standard cylinder and change its parameters.

Anyway C:\InvBook\Parametric-Tube.ipt has three parameters which I set up "manually":


Diam, Len and Taper.
Now, let's have a look at the code, open it in your Visual Studio editor, go to this function:
void CInvBookSrcDlg::OnBnClickedChgparamsBut()

Since opening a part and getting hold of its PartComponentDefinition is often done I've
wrapped it in a function called OpenPart. Note that you'll need the PartComponentDefinition
to do any real work, but you'll also need the PartDocument to be able to save the part if you
want to. That is why OpenPart gives you back both these two things:

HRESULT OpenPart (CComPtr<PartComponentDefinition>& pPartCompDef, // output

CComPtr<PartDocument>& pPartDoc, // output


const CString& csFullPartFileName) // input
See the image here to remind yourself of the relationship between a PartDocument and a
PartComponentDefinition.
Once you have got hold of the PartComponentDefinition the model parameters are listed by a
call to:
ListModelParameters (pPartCompDef) ; The output of the list is sent by the MFC TRACE
macro to your debug output window in the IDE.
You will get a list something like this:
The name of model parameter 1 is Diam. The value is 2.000 (114.592 degs) The name of model parameter 2 is Len. The value
is 5.000 (286.479 degs) The name of model parameter 3 is Taper. The value is 0.000 (0.000 degs)

The degrees is printed just in case the model parameter in an angle, win which case it is in
radians, so I print the degrees version next to it. In our cylinder only the Taper is in degrees,
and it is 0.0

12 11) Insert two parts into an assembly at specified positions

The next button says "create an assembly and add two parts." If you look at the code for it,
void CInvBookSrcDlg::OnBnClickedNewassemBut(), you'll see that first creates a new
assembly with a call to CreateNewAssembly, and then calls AddPartToAssemblyAtPosition
twice.
Things to note in the sources

CreateNewAssembly returns two useful objects, the assembly document, which has the save
to file functions, and the assembly document definition, which allows us to add an manipulate
parts inside the assembly.
The position coordinates in the call to AddPartToAssemblyAtPosition , are in internal
Inventor units. For positions this is always centimeters. So though the objects have been
defined (for example) in mm, I have to position them using cm.

13 X) Some tips for Autodesk Inventor C++ programmers

Here are some tips, in no particular order, I've found useful when programming AutoDesk
Inventor in C++

Tip1) Check your return values, hRes and COM pointers etc. I know it makes your code look
messy, but you are flying blind otherwise. If speed is really a problem then take the out the
checks only at the very end of the development.

Tip 2) Make sure that you know how to do manually what you are trying to do programatically.
Else you may end up trying to debug source code when you should be debugging the manual
method.

Tip 3) Name objects sensibly. Part1 and Assemby3 are less useful when debugging than
InnerTube and MainBikeAssembly.
Tip 4) Don't do programatically what may be easier to do by hand. For example you can make
a parametric object by hand and simply change the parameters with your program. This is
illustrated here.

Tip 5) If you know VB or C# then when in difficulty test using those languages. These are far
more interactive than C++, even with the IDE.

14 Programming Inventor

Click on the book icon to the left to open this section.


14.1 Compile/Link Errors and how to correct them
14.1.1 _WIN32_WINNT error
If you get this error:

"This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher
is recommended."
You need to add this to your preprocessor defines:
_WIN32_WINNT=0x0501
in the preprocessor compilation tab of your Inventor project.
14.1.2 error MSB3075: The command regsvr32 /s /c...
With registry free AddIns you probably don't need to know this any more, but just in case:

regsvr32 needs admin rights to operate. It is called from within Visual Studio. So you must
run Visual Studio "as the administrator" if you are creating old style plugins for Inventor.

It is not sufficient to be the administrator, you need to run as...


14.1.3 Error MK_E_UNAVAILABLE 0x800401e3
This has something to do with the ROT (Running Object Table) not having Inventor in it (yet).
Sometimes even though you have a running Inventor this code:
hRes = ::GetActiveObject (InvAppClsid, NULL, &pInvAppUnk); if (FAILED (hRes)) {
will fail with the error 0x800401e3

I've not been able to understand the underlying problem yet. But one thing to check is that both
processes are running at the same level, both non admin for example.

But see this as well.


This could be that you are running the compiler as administrator and Inventor as normal user.
14.1.4 Include file paths
Here are two include paths you will have to add to get your projects compile:

Else you'll get a C1083 " cannot open include file" problem. Of course you may be using a
different version of Inventor and the patsh on your computer may be slightly different.

InventorUtils.h is usually placed in the file for your project. You add the paths in
the dialog shown below. (The string is very lng so the dialog does not show it, but basically
you tack the two directories above onto the end of whatever is already there in the Include
Directories edit box, separated by semicolons.)

For 2015:
14.1.5 CLSIDFromProgID error resolution You have this usually:
CLSID InvAppClsid;
HRESULT hRes = CLSIDFromProgID (L"Inventor.Application",

&InvAppClsid);
if (FAILED(hRes)) {
pInvApp = nullptr ;
return ReturnAndShowCOMError (hRes,L"ConnectToInventor,

CLSIDFromProgID failed") ;
}
Which may fail with this error:
ConnectToInventor, CLSIDFromProgID failed Error = 800401f3
WCode = 0000
Meaning = Stringa dell'interfaccia non valida.

This could be that you are running the compiler as administrator and Inventor as normal user.
14.1.6 C2064: term does not evaluate to a function taking 0 arguments If you get this
error:
1>c:\...\sources\book\testfunctions.cpp(51): error C2064: term does not evaluate to a function taking 0 arguments
...it could well be that you are calling, for example, a member variable as if it is a function:
VARIANT_BOOL bIs = piPartCompDef->IsiPartFactory () ; In other words you have used
brackets () where they are not required. You should write this:
VARIANT_BOOL bIs = piPartCompDef->IsiPartFactory ; Another example would be the oft
used Count. The following is an error because Count is not a function:

Count is a member variable, this is the correct way of accessing it:

14.1.7 C2774 compile error


You'll get this if you try to modify a property which cannot be modified. For example:

FullDocumentName of a Part cannot be changed.


14.1.8 Failed to register
When you installl the Inventor addin making wizard for Visual Studio you may well get this
message:

In fact it may well have worked,


click on Continue then go into Visual Studio to see if the Inventor plugin AddIn project
wizard is there.
14.1.9 Four API methods warning when compiling for MFC

Yes, those four API methods have the same name with the methods which are introduced by
Windows library. The clients need to use rename to remove the warning.
And about the question that the client asks whether could change the methods name in Inventor
type library, I am afraid not, because we have rules that once a library is released to customer,
we don't allow to update the method names, unless there is a special requirement, such as the
method parameters needs be updated based on design or the method is totally useless. And
about the four methods "DeleteFile", "CopyFile", "MoveFile" and "SetEnvironmentVariable",
they are all old methods which exist for many Inventor releases. So I think they will not be
renamed unless PD's permission.

These have existed since almost the beginning of the Inventor API. Ideally we would not have
the name conflict but this isn't a big issue and we do not see it hasn't caused any big problems
for the past many years.

14.2 Open an Inventor part programatically

This funcion opens an Inventor part, and returns the PartDocument and the
PartComponentDefinition, both of which are usually useful to the caller.

HRESULT OpenPart (CComPtr<PartComponentDefinition>& pPartCompDef, // output


CComPtr<PartDocument>& pPartDoc, // output
const CString& csFullPartFileName, // input
CComPtr<Application>& pInvApp) // input
/*
Opens a part in a separate Inventor document
*/
{
// Read in the correct file.
CComPtr<Documents> pDocs = nullptr ;
HRESULT hRes = pInvApp->get_Documents (&pDocs) ;
if (FAILED(hRes) || (pDocs == nullptr)) {
return ReturnAndShowCOMError (hRes,L"OpenPart,get_Documents failed ");
}
CComPtr<Document> pDoc = nullptr ;
hRes = pDocs->Open (CComBSTR
(csFullPartFileName),VARIANT_TRUE,&pDoc) ;
if (FAILED(hRes) || (pDoc == nullptr)) {
return ReturnAndShowCOMError (hRes,L"OpenPart, Open failed " );
}

pPartDoc = pDoc ;
if (pPartDoc == nullptr) {
return ReturnAndShowCOMError (hRes,L"OpenPart, failed to cast to PartDocument");
}

// Get assembly component definition


pPartCompDef = nullptr ;
hRes = pPartDoc->get_ComponentDefinition(&pPartCompDef) ; if (FAILED(hRes) ||
(pPartCompDef == nullptr)){

return ReturnAndShowCOMError (hRes,L"OpenPart get_ComponentDefinition failed ");


}
return (S_OK) ; }
c text here.
14.3 Referenced Document of a View

When you have a view you can get hold of the object the view is looking at. The object is
called the referenced document, for example if it is a part:
Getting the referenced
document can be useful for getting retrieveable dimensions.
Here is an example code fragment (with no error checking):
So pPartDoc is the document which the view refers to.
14.4 Retrievable Dimensions

Retrievable dimensions are dimensions in the part (and maybe the assembly) which can be
placed in the view. In the GUI you open an IDW, go into the Annotate ribbon and click on the
Retrieve icon:

If
you have two visible versions of the same dimension in different views (on the same sheet)
only one view will get the dimension.
Programatically you use the functions GetRetrievableDimensions and RetrieveDimensions.
Here's a function you can use when a part drawing (not an assembly drawing) has been
opened... though note that at the time of writing (July 2015) there seems to be a bug in the API
when you try to get more than one dimension singly.
Listing the DimensionConstraints...
14.5 Show a dimension programatically
This function will try to show a dimension constraint dimension with a given parameter name
in a given view. It is called like this:

And the definition is this:


14.6 Dimensions in a drawing sheet
Here's how to count the number of dimensions in a drawings sheet:
CComPtr<DrawingViews> pViews = nullptr ;
hRes = pSheet->get_DrawingViews (&pViews) ;

{
CComPtr<DrawingDimensions> pDimensions = nullptr ; hRes = pSheet-
>get_DrawingDimensions (&pDimensions) ; if (FAILED(hRes)) {

ShowCOMError (hRes,L"pSheet->get_DrawingDimensions failed ");


}

long lNumDims;
hRes = pDimensions->get_Count(&lNumDims);
if (FAILED(hRes)) {

ShowCOMError (hRes,L"pDimensions->get_Count failed "); }


WalertBoxA ("This has %d dimensions",lNumDims) ; }
See also retrievable dimensions.
14.7 getType and ObjectTypeEnum
You can use GetType (or get_Type()) to see what sort of object you have.
For example:
CComPtr<ModelParameter> pModelParam ;
... other stuff
// Two ways of getting the object type...
TRACE (L"pModelParam->GetType()=%d\n",pModelParam->GetType()) ;
ObjectTypeEnum ObjType ;
pModelParam->get_Type (&ObjType) ;
TRACE (L"pModelParam->get_Type()=%d\n",ObjType) ; If you have initialised
pModelParam properly it will return 50348544 ( kModelParameterObject).
Other common values are:
This example shows that get_Type will give you a high level description, it does not tell you
which sort of model parameter it is (double, count, etc). For that you need the
ParameterTypeEnum.

The full set of values can be found in rxinventor.tlh, which will be somewhere like:

or in the API help file.


You may find this function useful, adding more cases as you need/find them:
14.8 Listing types of dimensions in a view
This code fragment shows you how to get hold of the DimensionConstraints:
It also shows you how to get an item as an IDispatchPtr and turn it into a DimensionConstraint
(for example), and how to get the name of the parameter which controls the dimension.

14.9 Getting the version of Inventor programatically


Here is the code to do it:

And the output in your debug window will look something like this:

Apart from DisplayName and DisplayVersion there are other functions like get_Major and
get_Minor. For example:

with this result:

But I don't find numbers as helpful as the display strings.

14.10 QueryInterface and Release Etc


If possible use CComQIPtr. If you insist you can read the following...

There is some confusion in this question's answers about what QueryInterface actually does. It
simply retrieves pointers to the supported interfaces on an object and increments the reference
count on that object. It doesn't create a new object for each interface that it implements.

For example if you have an object which implements 2 interfaces, then the call would simply
cast that object as each of the interface and increment a variable which is used as the reference
count.

QueryInterface allows the caller to retrieve references to different interfaces the component
implements. It is similar to dynamic_cast<> in C++. Specifically, it is used to obtain a pointer
to another interface, given a GUID that uniquely identifies that interface (commonly known as
an interface ID, or IID). If the COM object does not implement that interface, an
E_NOINTERFACE error is returned instead.

COM object gives you some pointers to certain functions that you can call to manipulate the
object.

COM object is basically a C++ class. A C++ class is just a struct that always starts with a
pointer to its VTable (an array of function pointers). And the first three pointers in the VTable
will always be named QueryInterface, AddRef, and Release. What additional functions may be
in its VTable, and what the name of their pointers are, depends upon what type of object it is.
This is another important rule of COM. If you get hold of a COM object created by someone
else, you must call its Release function when you're done with it.

CComQIPtr is a CComPtr with a QueryInterface inside it, apparently.


14.11 CComQIPtr is better than QueryInterface
Instead of doing a QueryInterface where you have to worry about
Release etc., you can sometimes use a CComQIPtr, like this:
perform automatic reference counting for you (for example, they
call Release on the interface attached to them, when the smart-pointer variable goes out of
scope).

And is null when you first create it. See comment on first line of the code above.
14.12 Counting the number of documents open in Inventor Get a pointer to the Inventor
application, then use this code:

You can loop over the open dopcuments in Inventor like this:

You'll get a listing in the debug window something like this:


Got document 1 of type 12291 Assembly Document Got document 2 of type 12290 Part Document Got document 3 of type
12290 Part Document Got document 4 of type 12290 Part Document Got document 5 of type 12290 Part Document Got
document 6 of type 12290 Part Document Got document 7 of type 12290 Part Document Got document 8 of type 12290 Part
Document Got document 9 of type 12292 Drawing Document Got document 10 of type 12290 Part Document

14.13 CustomTables in Sheets and Drawings


This example C++ code shows how to create a custom table in an IDW Inventor drawing:
The resulting table looks like this:

The
code does not include error checking, which you should add in your own versions.
If you want to specify column widths you need to pass in a VARIANT which is an array of
doubles, see WidthsVariant below:

.
14.14 New line within table cells
To add a new line within a cell of a custom table you should use \r\n.

for (UINT i = 0 ; i <= iSoFar ; i++) {


CString csPasso ;
csPasso.Format (L"%dx%d\r\n",Counts[i], int(RoundNumber

(Passi[i],0))) ;

if (i != iSoFar) {
// Separator needed....
csPasso += CString ("-") ;

}
csPassi += csPasso ;
}
14.15 CreateDoubleVariantArray
This function is useful for creating VARIANTs which specify the widths of the columns in a
CustomTable...

void CreateDoubleVariantArray (VARIANT& v, const double* const pValues, const UINT


ikNumValues)
/*
Some functions, like adding a custom table into a sheet, require VARIANTs which are
arrays of doubles. This function, given an array of doubles initialises the variant v.
*/
{
v.vt = VT_ARRAY | VT_R8;
SAFEARRAYBOUND sab[1];
sab[0].lLbound = 0; sab[0].cElements = ikNumValues ; v.parray = SafeArrayCreate(VT_R8, 1,
sab);

// Fill with some values...


for(int i=0; i<ikNumValues; i++) {
long indices[] = {i};
SafeArrayPutElement(v.parray, indices, (void *)&(pValues[i]));
}
}

14.16 CreateSafeStringArray
This is useful in various parts of COM programming:
For example in adding tables into sheets.
14.17 Open an assembly part programatically
Here's how to open an AssemblyDocument programatically:

text here.
14.18 Create a drawing file (IDW or DWG)
This code (with error checking omitted) creates a new empty drawing file:
When you do copy/paste of this code for other document types, remember to change the
enumerator of the types in both calls.

Also note that the document you create will already have one sheet in it, you normally do not
need to add any more. It is more likely that you want to add views to the sheet.

See also creating an assembly.


14.19 How to add views to a drawing sheet (Inventor API)

If you have a new or exisiting drawing it is likely that you want to add views of the 3D object
into the sheet. Here is a commented code fragment which shows you to do it (error checking
removed). Note also that we open the assembly invisibly so the user does not have to wait for
the display of the assembly.
See here for projected views.
As
far as the "where are we looking from" option, these are the most common:

These correspond in the user interface, to the view cube:

14.20 Names of views programatically


Although AddBaseView has a name parameter, it is not clear to me what it means. In fact it
never changes the name of the view, to do that you need to follow this code fragment:

So just use to change the name of the view.


14.21 Creating projected views from base views

This page shows how to put in two base views. If you want to create a projected view from the
first base view, the last part of the code becomes:
Here is a BaseView and a ProjectedView:

14.22 Open an assembly invisibly


Here is how to open an assembly invisibly...

Note that if you just want to interrogate the data of a part or assembly opening it invisibly will
be faster.
14.23 Drawing View Styles
With and you can use these enumerators
( :

14.24 Close function for Parts and Assemblies

When you have created a Part or Assembly you may want to close it with or without saving it.
You will Close the assembly or part document, for example:

pAssemblyDoc->Close(VARIANT_TRUE) ;

The boolean (and remember to use VARIANT_TRUE or VARIANT_FALSE) tells Inventor


whether the part should be saved before closing. For example:

pPartDoc->Close(VARIANT_TRUE) ; // "SkipSave" , no saving , just close the document


pPartDoc->Close(VARIANT_FALSE) ; // Don't "SkipSave", save, and maybe prompt
// the user before closing the document
Also note that you can avoid any file saving dialogs by using the "silent" operation. For
example:
pInvApp->SilentOperation = VARIANT_TRUE ; // don't show any dialogs, save with default
names
pAssemblyDoc->put_FullFileName
(CComBSTR(m_csAssemblyFullFileName)) ; // set the name
pAssemblyDoc->Save () ; // do the actual save pAssemblyDoc->Close(VARIANT_TRUE) ; //
close without saving (again)
Remember to switch off SilentOperation at the end of your functions. 14.25
GetInventorDocTypeDesc
Here is a function which will show you a description of the document type using the document
type enumerator:
14.26 Getting the current document of Inventor
It can be done like this:

get_ActiveDocument will put NULL in pDoc if there is no document open. You have to check
that.
You can find out what sort of document it is by looking at the type, for example:
by looking at
DocumentType. You can use this function to get a description of the document type
Valid enumerators are:
Apart from looking at the you can also try to cast the doc into the
doc type you are looking for:

There is another way of getting the part document:

14.27 Adding a sheet to a drawing


Here is a graphical overview of Drawings Sheets and Views:
Note that when you first
create a drawing you already have a single sheet, so often there is no need to add another one.

Anyway, to add a Sheet to a drawing you must get hold of the drawing object's Sheets list and
call the Add method. Here is a fragment, error checking removed:

CComQIPtr<DrawingDocument> pDrawingDoc ;
pDrawingDoc = ...
CComPtr<Sheets> pSheets = nullptr ;
pDrawingDoc->get_Sheets(&pSheets) ;

CComVariant varReal (0.0) ;


CComPtr<Sheet> pSheet = nullptr ;
pSheets->Add (kA3DrawingSheetSize,
kDefaultPageOrientation,
L"View77",
varReal, // width (not used in this case) varReal, // height (not used in this case) &pSheet) ;
The DrawingSheetSizeEnum Enumerator (first parameter in the above call to Add) has many
options, here a just a few:

If you use then Width and Height must be specified.


The orientation of the sheet (second parameter in the above call to Add) will be one of these:

You'll see the two drawings in a single sheet in the browser like this:

14.28 HRESULT codes


Return codes from Inventor COM function calls are the normal COM codes.
Codes greater than or equal to 0 indicate success.
Codes less than 0 indicate failure.
You can use S_OK (defined as 0) to return you own HRESULT success code.
S_FALSE is also a success return code (S_ = success). It could be a simple question you
asked COM, and does not fail.
You can use E_FAIL to return failure from your functions (E_=error)
You can also use E_INVALIDARG to return failure from your function (again E_=error)

These four macros are defined for you in WinError.h:


#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) #define FAILED(hr) (((HRESULT)(hr)) <
0)
#define S_OK ((HRESULT)0L) #define S_FALSE ((HRESULT)1L) You can sometimes get
the text interpretation of the error by using in something like this:

HRESULT hRes = pInvApp->get_ActiveDocument(&pDoc); if (FAILED(hRes)) {


TRACE("Get Active Document Failed");
TRACE(_com_error(hRes).ErrorMessage(),MB_ICONSTOP);
return ;
}

You can also use ShowCOMError


Or you can use:

Some example codes (from one of the many Windows headers):

// Catastrophic failure
//
#define E_UNEXPECTED _HRESULT_TYPEDEF_(0x8000FFFFL)
#if defined(_WIN32) && !defined(_MAC)

// Not implemented
#define E_NOTIMPL _HRESULT_TYPEDEF_(0x80004001L)

// Ran out of memory


#define E_OUTOFMEMORY _HRESULT_TYPEDEF_(0x8007000EL)

// One or more arguments are invalid #define E_INVALIDARG


_HRESULT_TYPEDEF_(0x80070057L)

// No such interface supported


#define E_NOINTERFACE _HRESULT_TYPEDEF_(0x80004002L)

// Invalid pointer
#define E_POINTER _HRESULT_TYPEDEF_(0x80004003L)
// Invalid handle
#define E_HANDLE _HRESULT_TYPEDEF_(0x80070006L)

// Operation aborted
#define E_ABORT _HRESULT_TYPEDEF_(0x80004004L)

// Unspecified error
#define E_FAIL _HRESULT_TYPEDEF_(0x80004005L)

// General access denied error


#define E_ACCESSDENIED _HRESULT_TYPEDEF_(0x80070005L)

See also this page for the error manager.


14.29 Add a mate constraint with two planes programatically

Here is a function which constrains two occurrences by mating two WorkPlanes in the
occurrences. Note that it handles the proxies, so the caller of the function does not need to
worry about those:

void AddMateConstraintOfTwoPlanes
(CComPtr<AssemblyComponentDefinition>& pAsmCompDef,

CComPtr<ComponentOccurrence>& pOccA,
CComPtr<WorkPlane>& pWorkPlaneA,
CComPtr<ComponentOccurrence>& pOccB,
CComPtr<WorkPlane>& pWorkPlaneB) /*
Given two occurrences which contain workplanes to be mated together this function creates a
Mate constraint between them
*/

{ CComPtr<WorkPlaneProxy> pWPProxyA ;
pOccA->CreateGeometryProxy (pWorkPlaneA,(IDispatch**)&pWPProxyA)

;
CComPtr<WorkPlaneProxy> pWPProxyB ;
pOccB->CreateGeometryProxy (pWorkPlaneB,(IDispatch**)&pWPProxyB) ;

// Get the list of constraints of the assembly so you can add a new one
CComPtr<AssemblyConstraints> pConstraintList = nullptr ;
HRESULT hRes = pAsmCompDef->get_Constraints(&pConstraintList) ;

CComVariant varEmpty, varReal(0.0);


CComPtr<MateConstraint> pMateConstraint = nullptr ; hRes = pConstraintList-
>AddMateConstraint(pWPProxyA, pWPProxyB,

varReal, kNoInference, kNoInference, varEmpty, varEmpty, &pMateConstraint);


}

Note that we use proxies, which give the position of the planes in the coordinate system of the
assembly. I assume here that the two occurrences have been taken from the
AssemblyComponentDefinition.

Another thing to note (and maybe change with FlipNormal) when mating WorkPlanes is the
normal. Depending on the part this could flip or rotate your part by 180 degrees.

14.30 Proxies, why and what?

When you have an part or workplane, for example, you can get the coordinates of its points in
the coordinate system of that part or workplane. But what about when the part is an occurrence
in an assembly. How can you get the coordinates of that part in the assembly? You use proxies.
The same goes for other objects, here is an example with workplanes.

In a constraint for example there are two proxies called EntityOne and EntityTwo, which
allow you to get to their respective occurrences:

Getting the proxy to the face (or workplane or point...) will allow you to get the occurrence
from where the proxy was made (using).

Here is an example where (for example) 4 tubes have been constrained on another tube. When
you get the proxies from the constraint (for example the constraint between the third small
tube and the large

Here is another example, with workplane proxies inside an assembly:


14.31 ErrorManager, errors and warnings, ShowCOMError and
ReturnAndShowCOMError
The book sources contain, in ErrorHandling.cpp, some functions which are useful for
reporting errors and debugging.

An example of an error message would be if you tried to create a circle in a sketch with
negative diameter. You'll not get a nice "bad radius" message, just an "invalid parameter"
message.

Have a look at the code for ShowCOMError. Not only does it give you dailog with the the text
of the error code, but sometimes it gives you an extra hint about what caused the error. I add
those text descriptions as I understand them. You can do the same.

void ShowCOMError (HRESULT hRes, const wchar_t* const pszExtraMsg, ...) ;


HRESULT ReturnAndShowCOMError (HRESULT hRes, const wchar_t* const
pszExtraMsg=nullptr) ;
void ShowInventorErrors () ;
Note also that the first function has trailing parameters, which means it can be used just like
printf. Note the %d and %s in the following call:

Extra tip: When using a COM get_ function you often pass the address of a pointer, which
becomes initialised by the get_ function, and the get_ function also returns a result code (an
HRESULT) remember to check both of them. For example the HRESULT may be S_OK (the
function went well) but the pointer comes back NULL (the object you were looking for does
not exist).

See also HRESULT codes.


14.32 Looping over views in sheets
This function will find a named view in a sheet of an IDW:
So you can find a named view inside a sheet..
14.33 Listing and checking constraints

This function goes over the constraints in an assembly checking that a given named constraint
does not already exist:
bool ConstraintNameAlreadyExists (const CString& csNameToCheck,

CComPtr<AssemblyComponentDefinition>& pAsmCompDef)
{
// Get the list of constraints of the assembly
CComPtr<AssemblyConstraints> pConstraintList = nullptr ; HRESULT hRes =
pAsmCompDef->get_Constraints(&pConstraintList) ; if (FAILED(hRes) || (pConstraintList ==
nullptr)) { ShowCOMError (hRes,L"ConstraintNameAlreadyExists could not get
constraints.") ;
return true ; // pretend it exists hopefully to stop further
processing
}

const long ikNumConstraints = pConstraintList->GetCount() ; for (int iConstraint = 1 ;


iConstraint <= ikNumConstraints ; iConstraint++) {
CComPtr<AssemblyConstraint> pConstraint = nullptr ; hRes =
pConstraintList->get_Item(CComVariant(iConstraint),&pConstraint) ; if (FAILED(hRes) ||
(pConstraint == nullptr)) {

ShowCOMError (hRes,L "ConstraintNameAlreadyExists could not get constraint


%d.",iConstraint) ;
return true ; // pretend it exists hopefully to stop further processing
}

CComBSTR bstrConstraintName ;
pConstraint->get_Name(&bstrConstraintName) ;
TRACE (L"Checking constraint <%s>\n",bstrConstraintName) ; if
(CString(bstrConstraintName).CompareNoCase(csNameToCheck)
== 0) {
// A constraint with the given name already exists return true ;

}
}

// If we get here then there are no constraints with the same name as csNameToCheck
return false ;
}

By the way, when your assemblies get even a bit complex it will probably help you to name
the constraints you add, using put_Name.
14.34 Saving apparently disabled (SilentOperation)
If you ever enable SilentOperation in your program remember to reenable it just before your
program exits. i.e:
m_pInvApp->SilentOperation = VARIANT_FALSE ;
14.35 WorkAxes in Inventor programs
In a Part there are always three standard WorkAxes, the X Y and Z axes. Here is the "Z Axis":

When you search for axes by name, use "X Axis", "Y Axis",and "Z Axis" to get the standard
ones. However remember that your use may not be in an English speaking country, and in that
case you can use this function:
HRESULT GetStdWorkAxisByIndex (CComPtr<WorkAxis>& pWorkAxis, const UINT
ikIndex, // 1 2 3 = X Y Z CComPtr<PartComponentDefinition>&

pPartCompDef)
{
if ((ikIndex < gikXIndex) || (ikIndex > gikZIndex)) {

TRACE (L "GetWorkAxisByIndex index out of range: %d\n" ,gikXIndex) ;


return (E_FAIL) ;
}

// Get the axis in the part by name...

HRESULT hRes =
pPartCompDef->WorkAxes->get_Item(CComVariant(ikIndex), &pWorkAxis);
if (FAILED(hRes) || (pWorkAxis == nullptr)) {
ShowCOMError (hRes,L"GetWorkAxisByIndex but 'get' failed\n" );
return (E_FAIL) ;
}

return (S_OK) ; }
Like many things WorkAxes are inside PartComponentDefinition, and you can get hold of
them like this:

CComPtr<PartComponentDefinition>& pPartCompDef ;
...
pPartCompDef->WorkAxes->get_Item(CComVariant(pszWorkAxisName),

&pWorkAxis);
Note that the plural of Axis is Axes, not Axiss!
14.36 Wrapping COM and C++
If you write an EXE in C++ you should follow this high level structure:
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT Result = CoInitialize (NULL); // Start COM...
if (SUCCEEDED(Result))
Result = YourInventorProgram();
CoUninitialize(); // ...end COM
return 0; }

In this way the smart pointers and COM objects will be constructed and destroyed properly, as
long as you keep them on the stack (i.e. local to some function).

If you had a global variable like the error manager outside of YourInventorProgram you
would need to be able to handle it explictly, and you'd probably get errors when you program
closes down (because the global pointer will be handled after CoUnitialize has been called,
and COM is no longer active).

With MFC I'd recommend you use the solution given in the sources of this book. See also the
basic architecture of the book sources.
14.37 Units when programming Inventor
Whatever units the user chooses to use (Inches or mm or feet or cm etc) internally Inventor
only uses one of each type.

For example, even if the user sets inches as the linear unit, intenally Inventor uses Centimeters
anyway. And you, as a programmer should use Centimeters too.

This has implications for parameters, for example.


If you change an angular parameter, for example, remember to use radians, even though the
user will see degrees.
14.38 Exporting Paramenters

To make model and user parameters visibile at a higher level than the part in which they are
contained use the iPart author to place them in the pane on the left:
.
14.39 Placing objects in space Vector and Matrix

When you add an occurrence of a part you can specify the placement using Vector and Matrix.
The example below places the part at 20,2,2:

The TransientGeometry pTransGeom object is an object which creates Vector and Matrix etc.
It is a machine for making these abstract objects.

Also note that the second parameter of SetTranslation is set to VARIANT_TRUE. That means
"Yes, reset any rotation components in the matrix". If you've only just created the matrix as in
the above example, there will be no rotation components inside the matrix, but I generally do
the call with VARIANT_TRUE.

14.40 ObjectCollections in the Inventor API (transient object collections)

Object collections can be used to make a list of already existing objects. This list can then be
used by your program to do repeated operations on those objects. Although the objects
already exist they may be in hard to get places, or in the wrong order to what you want. Or
maybe the objects you want are a sub set of the all the objects in your part or assembly.

Anyway, you need to get hold of the transient objects pointer from the Inventor application:

CComPtr<Application> pInvApp ... ;


CComPtr<TransientObjects> pTransientObjects ; pInvApp->get_TransientObjects
(&pTransientObjects) ;

Or, if basing your programs on the book sources, you can use theApp. GetTransGeomPtr().
The TransientObjects pointor is the thing which allows you to create object collections. Here
is how to create an initially empty one:
CComPtr<ObjectCollection> pObjCollection = nullptr ; pTransientObjects-
>CreateObjectCollection (varEmpty,&pObjCollection) ;
Simply use the Add function to add objects to the collection. Here is an example of adding a
WorkPlaneProxy to an object collection:

CComPtr<WorkPlaneProxy> pWPProxy = nullptr ;


pTuboOcc->CreateGeometryProxy (pWP,(IDispatch**)&pWPProxy) ; pObjCollection->Add
(pWPProxy) ;

Once you have created the list of objects you can get hold of them by passing the index to the
get_Item function:
CComPtr<WorkPlaneProxy> pHoleWPProxy = nullptr ;
int iTroncNum = ..something starting a 1, 1 is the first object....
pObjCollection->get_Item (iTroncNum,(IDispatch**)&pHoleWPProxy) ;

I've removed all error checking from the fragments above. 14.41 Creating a new Part
Document
Here's a function for doing it:

HRESULT CreateNewPartDoc(CComPtr<PartDocument> &pPartDoc, const wchar_t* const


pszPartName)
/*
Given a name a new part document is created in Inventor with that
name.
*/
{
CComPtr<Application> pInventorApp = theApp.GetInvAppPtr() ;

CComVariant pSubDocType;
CComBSTR sTemplate;
HRESULT hr = pInventorApp->GetTemplateFile

(kPartDocumentObject, // We are creating a PartDocument


kMetricSystemOfMeasure, // mm

kDefault_DraftingStandard, pSubDocType, &sTemplate); if (hr != S_OK) {

return hr; }

CComPtr<Document> pDoc;
hr = pInventorApp->Documents->Add (kPartDocumentObject, sTemplate,
VARIANT_TRUE,
&pDoc);
if (hr != S_OK) {
return hr;
}

pPartDoc = CComQIPtr<PartDocument>(pDoc);

if ((pszPartName != nullptr) && (wcslen (pszPartName) > 0)) { BSTR bstrName ;


pDoc->get_DisplayName (&bstrName) ;
TRACE (L"\nFull document name was %s\n",bstrName) ;

pPartDoc->DisplayName = pszPartName ;
pDoc->get_DisplayName (&bstrName) ;
TRACE (L"\nFull document name now is %s\n",bstrName) ;
::SysFreeString (bstrName) ; }
return hr; }
Which can be called like this:

CComPtr<PartDocument> pPartDocument ;
HRESULT hRes = CreateNewPartDoc (pPartDocument,L"MAIN_TUBE") ; if (FAILED(hRes))
{

return ReturnAndShowCOMError (hRes,L"CreateMainTube, CreateNewPart failed") ;


}
14.42 How to extrude a sketch programatically

Here is a function which takes five parameters and creates a 3D extruded feature in the part.
The feature could be a hole, as well as normal solid objects....
HRESULT ExtrudeSketch ( const wchar_t* const pszExtrusionName, // name of created
feature
const double kHeight,
const wchar_t* const pszSketchName, // which sketch to extrude
const PartFeatureOperationEnum eOperation, // how to extrude
const PartFeatureExtentDirectionEnum eDirection,
CComPtr<PartComponentDefinition>& pPartCompDef) /*
Given a height and a sketch name the sketch is extruded to the given height.
The resultant feaure is placed inside pPartCompDef, and is called pszExtrusionName
eOperation tells us whether to cut a hole or create a solid object etc.
eDirection tells us which direction to make the extrusion. */
{
// Get the sketch in the part by name...
CComPtr<PlanarSketch> pSketch;
HRESULT hRes =
pPartCompDef->Sketches->get_Item(CComVariant(pszSketchName), &pSketch);
if (FAILED(hRes) || (pSketch == nullptr)) {
return ReturnAndShowCOMError (hRes,L"ExtrudeSketch but could not get sketch by
name\n");
}
CComPtr<Profile> pProfile ; // This is the return value of the call to AddForSolid

// and will be used when we extrude. CComVariant pSegs; // not used


CComVariant pReserve; // not used
hRes =

pSketch->Profiles->AddForSolid(VARIANT_TRUE,pSegs,pReserve,&pProfile );
if (FAILED(hRes) || (pProfile == nullptr)) {
return ReturnAndShowCOMError (hRes,L"ExtrudeSketch but could not AddForSolid for
pProfile\n");
}

// Features are 3D objects. Get the list of them so we can add to that list...
CComPtr<PartFeatures> pListOfFeatures;
hRes = pPartCompDef->get_Features(&pListOfFeatures);
if (FAILED(hRes) || (pListOfFeatures == nullptr)) { return ReturnAndShowCOMError
(hRes,L"ExtrudeSketch but could not get_Features\n");
}

// Get the list of *extruded* features...


CComPtr<ExtrudeFeatures> pListOfExtrusions;
hRes = pListOfFeatures->get_ExtrudeFeatures(&pListOfExtrusions); if (FAILED(hRes) ||
(pListOfExtrusions == nullptr)) { return ReturnAndShowCOMError (hRes,L"ExtrudeSketch
but could

not get_ExtrudeFeatures\n");
}

// Now at last we can use the pProfile to create a new extrusion, adding it to the list
// of extruded features. This is where we use the eOperation parameter
CComPtr<ExtrudeDefinition> pExtrudeDef;
hRes =
pListOfExtrusions->CreateExtrudeDefinition(pProfile,eOperation,&pExt rudeDef);
if (FAILED(hRes) || (pExtrudeDef == nullptr)) {
return ReturnAndShowCOMError (hRes,L"ExtrudeSketch but could not
CreateExtrudeDefinition\n");
}

// Specify the distance and direction of the extrustion... pExtrudeDef-


>SetDistanceExtent(_variant_t(kHeight),eDirection);

// Add the extrusion.


CComPtr<ExtrudeFeature> pExtrude;
hRes = pListOfExtrusions->Add (pExtrudeDef,&pExtrude); if (FAILED(hRes) || (pExtrude ==
nullptr)) {
return ReturnAndShowCOMError (hRes,L"ExtrudeSketch but could Add
ExtrudeDefinition\n");
}
pExtrude->put_Name (CComBSTR (pszExtrusionName)) ;
return (hRes) ; }
Here are the possible values for the two enumerators used above:

PartFeatureExtentDir ectionEnum
Enumerator
kNegativeExtentDire ction
kPositiveExtentDirect ion
kSymmetricExtentDir ection
Value Description 2099 4
2099 3
2099 5
Extension in the negative direction.
Extension in the positive direction
Extension in positive AND negative direction.

PartFeatureOperatio nEnum
Enumerator
kCutOperation

kIntersectOperation Value Description


20482 Cut operation. (i.e. make a

hole)
20483 Intersect operation.
kJoinOperation 20481 Join operation.
kNewBodyOperation 20485 New Body operation. kSurfaceOperation 20484 Surface
operation.
This image has used kCutOperation and kSymmetricExtentDirection around a center plane of
a cylinder, the sketch contained a single circle:
14.43 Transient
Geometry
The transient geometry object is a "motor" which lets you create COM points, matrices,
vectors, and so on. Think of it like this:
// Set a
reference to the transient geometry object. CComPtr<TransientGeometry> pTrGeom =
theApp.GetTransGeomPtr();

// Draw a 4cm x 3cm rectangle with the corner at (0,0) CComPtr<Point2d> pPt1; // Create a 2d
point
hr = pTrGeom->CreatePoint2d(0.0,0.0,&pPt1);
if (FAILED(hr))

return ReturnAndShowCOMError (hr,L" create 2d point failed") ;

CComPtr<Point> pPt; // Create a 3d point


hr = pTrGeom->CreatePoint(0.5,0.5,0.0,&pPt);
if (FAILED(hr))

return ReturnAndShowCOMError (hr,L" CreatePoint failed") ;

Note that above you've created a 2D point ( CComPtr<Point2d>) and a 3D point


(CComPtr<Point>) using the TransientGeometry object. Here's how to create a matrix:

CComPtr<Matrix> pMatrix; hr = pTransGeom->CreateMatrix(&pMatrix); And to create a


Vector:
CComPtr<Vector> pVector;
hr = pTransGeom->CreateVector(20,2,2,&pVector); Note that these are "abstract geometrical"
objects, not "concrete" CAD objects.
14.44 Changing the application visibility
To set and get the visibility of Inventor:

// Obtain the 'Visible' property of the active application VARIANT_BOOL bVisible;


Result = pInvApp->get_Visible(&bVisible);
if (FAILED(Result)) return Result;

if (bVisible != VARIANT_TRUE){
pInvApp->Visible = VARIANT_TRUE ;
}

...though you may well still see a tiny icon of Inventor at the top left of your screen.
14.45 A matrix to rotate an object

When you insert a part in an assembly you can specify the initial position and rotation. You do
this by providing a mattrix to the AddiPartMember call. Here is an example of how to create a
matrix which will rotate the

part around the Z axis by 180 degrees:

CComPtr<TransientGeometry> pTransGeom = theApp.GetTransGeomPtr () ;


CComPtr<Matrix> pPosMatrix;
pTransGeom->CreateMatrix(&pPosMatrix); // Defaults to origin

CComPtr<Vector> pZAxis = nullptr ; pTransGeom->CreateVector (0,0,1,&pZAxis);


CComPtr<Point> pOrigin = nullptr ; pTransGeom->CreatePoint (0,0,0,&pOrigin);

pPosMatrix->SetToRotation (TwoPi,pZAxis,pOrigin) ; ...and when you call AddiPartMember


you use the matrix like this:
pOccurrencesList->AddiPartMember (bstrFileName,pPosMatrix
,_variant_t(bstrMemberName),&pOccurrence) ;
Note that SetToRotation requires radians, not degrees.
These two diagrams show the result of using a X-Axis rotation matrix when calling
AddiPartMember:
Here is a code fragment which creates the matrix which does that:

CComPtr<Matrix> pRotXMatrix;
pTransGeom->CreateMatrix(&pRotXMatrix);
CComPtr<Vector> pXAxis = nullptr ;
pTransGeom->CreateVector (0,1,0,&pXAxis);
pRotXMatrix->SetToRotation (gkPi,pXAxis,pOrigin) ;

If you are using two planes in a constraint you can also sometimes use FlipNormal to rotate
the inserted object 180
14.46 Proxies, WorkAxes, Vectors and Points
Here is an example of getting the data about a work axis in part which has been inserted into
an assembly:

CComPtr<Line> pAxisLine = nullptr ; p1stHoleWorkAxisProxy->get_Line (&pAxisLine) ;


CComPtr<Point> pRootPoint ;
pAxisLine->get_RootPoint (&pRootPoint) ; CComPtr<UnitVector> pAxisDir ;
pAxisLine->get_Direction (&pAxisDir) ;

Now you can use that axis to form a rotation matrix:


CComPtr<Vector> pAxisVector = nullptr ; pTransGeom->CreateVector
(pAxisDir->X,pAxisDir->Y,pAxisDir->Y,&pAxisVector) ;
pRotMatrix->SetToRotation (gkPi,pAxisVector,pRootPoint) ;
14.47 WorkFeatures and iParts

If you have a workplane in a table based iPart (or even custom iPart) for that workplane to be
visible in when inserted in an assembly (i.e. when it is an occurrence in an assembly) then you
need to include it using the iPart author.

If you don't do that you'll get a com error 80070057.

Here is the sequence:


In this way "TopWP" will be accessable with your program from the assembly.

Here's another graphical explanation:

14.48 What
are PatternElements?
The FeaturePatternElements are the actual "copies" within a pattern, apart from the first one
which is considered special.
14.49 What sort of WorkFeature is this?

Unfortunately WorkPoint WorkAxis and WorkPlane objects do not have a common parent. If
you get a pointer to one of these things from an ObjectsCollection you have to work a bit
harder than normal to get their type. Here is an example, assuming you already have an
ObjectsEnumerator and want to get hold of the iObj th item:

CComPtr<ObjectsEnumerator> pObjs = ... ;


int iObj = ...
...
CComPtr<WorkPlane> pWPlane = nullptr ; CComPtr<WorkPoint> pWPoint = nullptr ;
CComPtr<WorkAxis> pWAxis = nullptr ;
pObjs->get_Item (iObj,(IDispatch**)&pWPlane) ; pObjs->get_Item (iObj,
(IDispatch**)&pWPoint) ; pObjs->get_Item (iObj,(IDispatch**)&pWAxis) ;

if ((pWPlane != nullptr) && (pWPlane->GetType() == kWorkPlaneObject)) {


// pWPlane is a valid workplane
} else if ((pWPoint != nullptr) && (pWPoint->GetType() == kWorkPointObject)) {
// pWPoint is a valid workpoint
} else if ((pWAxis != nullptr) && (pWAxis->GetType() == kWorkAxisObject)) {
// pWAxis is a valid axis

} else {
// This is probably an error
}

.
14.50 IDispatch

You often need to cast pointers to objects into IDispatch* or IDispatch** when calling
functions in the Inventor C++ COM API. Here are some examples, showing how to cast from
various Inventor pointers to an IDispatch* :

Add a sketch based on a workplane:

CComPtr<WorkPlane> pWorkPlane ;
hRes = pSketches->Add (_variant_t((IDispatch*)pWorkPlane), VARIANT_FALSE,
&pNewSketch);

Add a workplane based on an existing workplane:

CComPtr<WorkPlane> pWorkPlane... ;
CComPtr<WorkPlane> pOffsetWorkPlane ;
hRes = pWorkPlanesList->AddByPlaneAndOffset (

_variant_t((IDispatch*)pWorkPlane), // "starting" plane


CComVariant(kTubeDiam/2.0), // how much to offset VARIANT_FALSE, // This is important!
&pOffsetWorkPlane) ; // Return value of this call
Add a workpoint based on a sketchpoint:

CComPtr<SketchPoint> pSketchPoint... ;
CComPtr<WorkPoint> pWorkPoint ;
hRes = pWorkPointsList->AddByPoint (_variant_t((IDispatch*)

pSketchPoint),VARIANT_FALSE,&pWorkPoint) ;
if (FAILED(hRes) || (pWorkPoint == nullptr)) {
return ReturnAndShowCOMError (hRes,L
"AddWorkPointAtSketchPoint, Add workpoint failed") ; }
Create a proxy geometry from an occurrence and a workplane:
CComPtr<WorkPlaneProxy> pWPProxyA ;
pOccurrence->CreateGeometryProxy (pWorkPlaneA,(IDispatch**) &pWPProxyA) ;
14.51 Interrogating rectangular patterns
Here is a rectangular pattern inside an assembly:

If you have a PartComponentDefinition which contains a


RectangularPatternFeature use this fragment of code to find out basic data:
Note the strangeness of the fact that there is no Y count if the pattern is a linear array with , for
example, 5 X items. That is why I set iYCount to 1 and change it only if pYCountParam is not
nullptr.

Note also that you should check hRes, I've not done it for clarity here.
14.52 Name of part in a component occurrence
Here is a function which will return the component occurrence (within an assembly) of a
given name.
HRESULT GetComponentOccurrenceByName (CComPtr<ComponentOccurrence>&
pCompOccRet,
const wchar_t* const pszOccName,

CComQIPtr<AssemblyDocument> pAssemblyDoc)
{

// Init for safety


pCompOccRet = nullptr ;

// Get assembly component definition


CComPtr<AssemblyComponentDefinition> pAssemblyCompDef = nullptr; HRESULT hRes =

pAssemblyDoc->get_ComponentDefinition(&pAssemblyCompDef); if (FAILED(hRes) ||
(pAssemblyCompDef == nullptr)){ return ReturnAndShowCOMError(hRes,L
"GetComponentOccurrenceByName, get_ComponentDefinition failed "); }

// Get the ComponentOccurrences collection for the assembly document


CComPtr<ComponentOccurrences> pOccs;
hRes = pAssemblyCompDef->get_Occurrences(&pOccs);
if (FAILED(hRes) || (pOccs == nullptr)){
return ReturnAndShowCOMError (hRes,L
"GetComponentOccurrenceByName, get_Occurrences failed ");
}

long lNoOccs;
hRes = pOccs->get_Count(&lNoOccs);
if (FAILED(hRes)) {

ReturnAndShowCOMError (hRes,L"GetComponentOccurrenceByName, get_Count failed ");


}
TRACE (L"GetComponentOccurrenceByName, there are %d occurrences\n",lNoOccs);
//iterate through the current level of occurrences for (long lOccCount=1; lOccCount <=
lNoOccs; ++lOccCount) {

CComPtr<ComponentOccurrence> pThisCompOcc = nullptr ; hRes = pOccs-


>get_Item(lOccCount, &pThisCompOcc); if (FAILED(hRes) || (pThisCompOcc == nullptr)){

ShowCOMError(hRes,L "GetComponentOccurrenceByName, get_Item failed ");


return hRes ;
}

CComPtr<ReferencedFileDescriptor> pRefFileDesc = nullptr ; pThisCompOcc-


>get_ReferencedFileDescriptor (&pRefFileDesc) ; if (FAILED(hRes) || (pThisCompOcc ==
nullptr)){

ShowCOMError(hRes,L "GetComponentOccurrenceByName, get_ReferencedFileDescriptor


failed ");
return hRes ;
}

CComBSTR bstrDisplayName; // ::SysFreeString not required because CComBSTR, not


BSTR
hRes = pRefFileDesc->get_DisplayName (&bstrDisplayName) ;
if (FAILED(hRes) || (pThisCompOcc == nullptr)){
ShowCOMError(hRes,L"GetComponentOccurrenceByName, get_DisplayName failed ");
return hRes ;
} else {
TRACE (L"Component occurrence %02d <%s>\n" ,lOccCount,bstrDisplayName);
if (_wcsicmp(bstrDisplayName,pszOccName)==0) { pCompOccRet = pThisCompOcc ;
}
}

if (pCompOccRet != nullptr) { // We can get out


return (S_OK) ;

}
}
TRACE (L"Could not find an occurrence called <%s>\n",pszOccName) ;
return (E_FAIL) ; }
Basically you get the name of the occurrence's part using the occurrences
ReferencedFileDescriptor .
14.53 Add an occurrence to an assembly does not work

When you add an .ipt part to an .iam assembly you need to pass the correct sort of parameter
to the Add function. For example this will not work:

CComPtr<ComponentOccurrence> pCyl2Occ = nullptr; hRes = pOccurrencesList->Add


(L"C:\\TEST\\Cyl2.ipt" ,pPosMatrix,&pCyl2Occ) ;

...but this will...

CComPtr<ComponentOccurrence> pCyl2Occ = nullptr; hRes = pOccurrencesList->Add


(CComBSTR(L"C:\\TEST\\Cyl2.ipt" ),pPosMatrix,&pCyl2Occ) ;

The difference is that the first call does not cast to CComBSTR, the second, working version,
does.
14.54 Listing constraints in an assembly programatically

Here is a code fragment showing how to list constraints and cast EntityOne and EntityTwo
into appropriate proxies. Graphically the constraint and two proxies look like this:
// Get the list of constraints of the assembly so you can add a new one
CComPtr<AssemblyConstraints> pConstraintList = nullptr ;
hRes = pAssemblyCompDef->get_Constraints(&pConstraintList) ;
if (FAILED(hRes) || (pConstraintList == nullptr)) { TRACE (L"Could not get constraints.") ;
return ;
}

// List the two entities of each MateConstraint... for (int i = 1 ; i <= pConstraintList->Count ;
i++) { CComPtr<AssemblyConstraint> pConstraint = nullptr ;
pConstraintList->get_Item (CComVariant(i),&pConstraint) ;
CComQIPtr<MateConstraint> pMate (pConstraint) ; if (nullptr != pMate) {
// This is a mate constraing, show more data about it...
IDispatchPtr pEnt1 = pMate->EntityOne ;
IDispatchPtr pEnt2 = pMate->EntityTwo ;
TRACE (L" Two parts are %p %p\n",pEnt1,pEnt2) ;
CComQIPtr<FaceProxy> pFace1 =
CComQIPtr<FaceProxy>(pEnt1);
CComQIPtr<WorkPlaneProxy> pWP1 =
CComQIPtr<WorkPlaneProxy>(pEnt1);
if (pFace1 != nullptr) {
TRACE (L" Ent1 is a face proxy...\n") ;
} else if (pWP1 != nullptr) {
TRACE (L" Ent1 is a workplane proxy...\n") ; CComPtr<ComponentOccurrence> pContOcc =

pWP1->ContainingOccurrence ;
if (pContOcc != nullptr) {

CComPtr<ReferencedFileDescriptor> pFileDesc = nullptr ;


pContOcc->get_ReferencedFileDescriptor (&pFileDesc) ;
if (pFileDesc != nullptr) { CComBSTR bstrFullFileName ; pFileDesc->get_FullFileName
(&bstrFullFileName) ; TRACE (L" Ent1 full file name is %s\n" ,bstrFullFileName) ;
} }

} else { TRACE (L" Ent1 This is neither a face or workplane proxy\n") ;


} }
}
14.55 Listing members in an iPartFactory programatically Here is how to list members of
an iPartFactory, starting with the PartDocument:

// Open the standard part...


CComPtr<PartComponentDefinition> pTroncPartCompDef = nullptr ;
CComPtr<PartDocument> pTroncPartDoc = nullptr ;

HRESULT hRes = OpenPart


(pTroncPartCompDef,pTroncPartDoc,gkcsTroncFactory,pInvApp) ;
// Check that it is an iPartFactory...
if (pTroncPartCompDef->IsiPartFactory == VARIANT_FALSE) { gLogger.Printf
(ekImmediateErrorMsg,L"%s non e' un

iPartFactory" ,gkcsTroncFactory) ;
// This is NOT an iPartFactory
return ;

/*
* Get the iPartFactory from the component definition... */

CComPtr<iPartFactory> piPartFactory = nullptr ;


hRes =pTroncPartCompDef->get_iPartFactory (&piPartFactory) ;
/*
* Get the rows of the factory, each row corresponds to a

"member"...
*/
CComPtr<iPartTableRows> piPartTableRows = nullptr ; piPartFactory->get_TableRows
(&piPartTableRows) ;

/*
* Loop over the members in the table, printing Member... */

for (int iRow = 1 ; iRow <= piPartTableRows->Count ; iRow++) { CComPtr<iPartTableRow>


piPartRow ;
piPartTableRows->get_Item (iRow,&piPartRow) ;

const int ikNumColumns = piPartRow->GetCount() ; BSTR bstrMember = nullptr ;


piPartRow->get_MemberName (&bstrMember) ;

TRACE (L " Row %03d:%s has %d things\n"


,iRow,LPCSTR(bstrMember),ikNumColumns) ;
for (int iCol = 1 ; iCol <= ikNumColumns ; iCol++) { CComPtr<iPartTableCell>
piPartTableCell = nullptr ; piPartRow->get_Item (CComVariant(iCol),&piPartTableCell) ;

CComBSTR bstrCellString ;
piPartTableCell->get_Value (&bstrCellString) ; TRACE (L" iRow %d iCol %d has value
%s\n"

,iRow,iCol,LPWSTR(bstrCellString)) ; }
::SysFreeString (bstrMember) ; }
As usual there's not as much error checking in the source above as there should be. That last
inner loop could use a function like this:

See also iPartMember. and


14.56 PartComponentDefinition from an occurrence

If you have an occurrence of a part, you can get the


PartComponentDefinition of that part by using the Definition member and a cast as shown
below:

CComQIPtr<PartComponentDefinition> pCompDef =
CComQIPtr<PartComponentDefinition>(pTuboOcc->Definition); You are casting from a
ComponentDefinition to a
PartComponentDefinition.
14.57 AddiPartMember

You can add an iPart member (i.e. an instance of an iPart from the iPart's table) by using the
function AddiPartMember. The easiest type of call is when you know the index of the row of
the table, for example row 3 in the example below:

CComPtr<ComponentOccurrence> pPartOcc = nullptr;


pOccurrencesList->AddiPartMember (CComBSTR("My_Factory.ipt"), // iPart factory file

pPosMatrix,

CComVariant(3), // Row of the iPart Factory Table, the "member"


&pPartOcc) ;

You can also specify directly the member to insert using the Member string:

As a reminder, the Member column is the first in the iPart table:


See
also iPartFactory, listing members, and rotating parts in assemblies. 14.58 Getting the
workplanes of a part occurrence in an assembly What you need to do here is get the
occurrence and then get the part component definition of it. This requires a cast...
CComQIPtr<PartComponentDefinition> pPartCompDef =
CComQIPtr<PartComponentDefinition>(pOcc->Definition);

You need to be sure that the occurrence point to a part, get its Definition, then cast it from
ComponentDefinition to PartComponentDefinition, as shown above. Now you can get the
workplanes from the pPartCompDef, for example:

14.59 SubOccurrences
SubOccurrences of an assembly can be parts or assemblies. Given an assembly this code
fragment lists their names:

CComPtr<ComponentOccurrencesEnumerator> pCompOccsEnum = nullptr ;


pAttOcc->get_SubOccurrences (&pCompOccsEnum) ;
UINT iNumSubOccurrences = pCompOccsEnum->Count ;
for (UINT i = 1 ; i <= iNumSubOccurrences ; i++) { TRACE (L"Occ%d =
%s\n",pCompOccsEnum->Item [1]->Name ) ;
}

14.60 SaveAs function


Be careful with this function. It will accept a wchar_t but will not work unless the wchar_t is
wrapped inside a CComBSTR type:

hRes = pPartDoc->SaveAs (CComBSTR(L "C:\\CHS_LHS_COLL\\This.ipt"


),VARIANT_TRUE) ;
if (FAILED(hRes)){
ShowCOMError(hRes,L
"CCollettore::CreateCollectorMainTubePart, save failed."); return (false) ;
}

That last parameter is:

- any existing file will be overwritten


- an existing file will not be overwritten and the function will fail.

Here is another example with an assembly document:

CComQIPtr<AssemblyDocument> pAssemblyDoc ;
...init pAssemblyDoc ...
CString csFullAssemblyName (L"C:\\YOUR_TEST\\Test_Assembly.iam")

;
pAssemblyDoc->SaveAs (CComBSTR(csFullAssemblyName),VARIANT_TRUE)
;

SaveAs will save to a copy and not change the name of the document.
See also Save.
14.61 Save programatically
The Save function can be used like this:
Note that in this example I've changed the full filename of the assembly, and then called Save.

If the file already exists then a Save dialog will pop up, otherwise the save will run silently.
Save will not silently overwrite an existing file, check the return value if you find your
changes are not being saved.

Note also that if the doc is new, and so does not have a name, the Save will fail with error
80004005. This is because of the empty filename. Here is an example of avoiding that error:

See also SaveAs, which allows you to specify overwrite.


14.62 Close function, Inventor API

Here's an example of using the Close function on a PartDocument. Imagine we have opened
and modified and existing file. Next we SaveAs to create a copy of our original part, then we
Close the original without saving:
Notice the comment just before the call to Close. We've already saved the part with SaveAs,
and we just want to close the document, and we don't want any further saving (or dialogs) to
come up. Hence
VARIANT_TRUE (which means SkipSave) is used.

14.63 Visibility programatically in Inventor


Here is an example of how to set the visibility of a workpoint
CComPtr<WorkPoint> pWorkPoint = nullptr ;
GetWorkPointByName (pWorkPoint,csPointName,pPartCompDef) ;
if (bMakeVisible)) {
pWorkPoint->put_Visible (VARIANT_TRUE) ;

} else {
pWorkPoint->put_Visible (VARIANT_FALSE) ;
}

14.64 AddCustomiPartMember details and tips


Look at this call:
pOccs->AddCustomiPartMember(strFactoryFile, // This is the source file of the object to
create
pMatrix, // This is where to

place the created custom iPart


strFullFileName, // This is the
resulting file of the created object
varEmpty, // Usually unused with
custom iParts, hence varEmpty.
oleSafeArray, // Parameters, in
column order
&pCyl1Occ) ;

varEmpty will be something like this:


CComVariant varEmpty ; The creation of oleSafeArray is explained here. However
remember that the values must be in column order, for example:

BSTR strParams[] = {
CString("35 mm").AllocSysString(), // Diameter CString("1.5 mm").AllocSysString(), //
Thickness CString("350 mm").AllocSysString(), // Length CString("10").AllocSysString(), //
R1Angle CString("20").AllocSysString(), // R2Angle

};
const int ikNumParams = sizeof(strParams)/sizeof(strParams[0]) ;
COleSafeArray oleSafeArray;
oleSafeArray.CreateOneDim(VT_BSTR, ikNumParams, strParams);
The call may fail for one of these reasons:
1. The columns you have specified don't make solid sense, an outer diameter smaller than an
inner diameter for example.
2. The factory file (first parameter) does not exist.

The two filenames can be created like this:


CComBSTR strFactoryFile(L"C:\\CHS_LHS_COLL\\Tube-Custom.ipt") ; CComBSTR
strFullFileName(L"C:\\CHS_LHS_COLL\\Tube_999.ipt") ;
14.65 Add in the occurrence of a custom iPart into an assembly The most difficult part of
adding a custom iPart into an assembly is understanding how to specify the parameters.
The first step is to get hold of the list of occurrences so you can add a new occurrence to the
list.
Then you create a matrix and a vector to specify the position (and any rotations etc.) of the
object.

Then you create a list of parameters in column order of the iPart. When you use the iPart
Author you'll see the custom parameters in purple. Use that order. These parameters have to
be created in a COleSafeArray.

Now you are ready to call AddCustomiPartMember with the objects you created in the
previous steps.
Here is a fragment which assumes you already have an
AssemblyComponentDefinition:
CComPtr<ComponentOccurrences> pOccs;
hRes = pAssemblyCompDef->get_Occurrences(&pOccs);

// This is the name of the iPart factory, from which custom iParts will be created...
CComBSTR strFactoryFile(L"C:\\TEST\\CustomCylinder.ipt") ;

// Get hold of the transient geometry pointer to create the matrix which says
// where to place the custom iPart...
CComPtr<TransientGeometry> pTransGeom = theApp.GetTransGeomPtr()

;
CComPtr<Matrix> pMatrix; // Defaults to 0,0,0 position pTransGeom-
>CreateMatrix(&pMatrix);
CComPtr<Vector> pVector; // Create a Vector to modify the Matrix pTransGeom-
>CreateVector(2,2,0,&pVector);
hRes = pMatrix->SetTranslation (pVector,VARIANT_TRUE) ;

// This is the name of the output file, the iPart created from the factory file...
CComBSTR strFullFileName(L"C:\\CHS_LHS_COLL\\CUSTOMCYL2.ipt") ;
CComVariant varEmpty ; // Nothing because we are not selecting a row

// We are not selecting a row but we are changing parameters.


Here is how
// we specify those parameters...
#define NUM_PARAMS 2
BSTR strBSTR[NUM_PARAMS] =
{
CString("20 cm").AllocSysString(), CString("10 cm").AllocSysString(), };

COleSafeArray oleSafeArray;
oleSafeArray.CreateOneDim(VT_BSTR, NUM_PARAMS, strBSTR);
CComPtr<ComponentOccurrence> pCyl1Occ;
pOccs->AddCustomiPartMember(strFactoryFile,pMatrix,strFullFileName,v
arEmpty,oleSafeArray,&pCyl1Occ) ;
I've not yet found out how to create the parameter list when not using MFC. COleSafeArray is
an MFC object.
See also AddCustomiPartMember details and tips.
14.66 Occurrences and component definitions

An occurrence is like an XREF insert in AutoCAD. Occurrences exist, for example, inside
assemblies. It is an instance of a part. The diagram below shows that an assembly has insidie it
an
AssemblyComponentDefinition, and inside that is a list of occurrences (among ther things):
Here is some code to list the occurrences in an assembly:
I've not placed any error checking in the previous code.
How to get the name of an occurrence.
14.67 How to get the parameters of an assembly
If you have an assembly with parameters you can get hold of the parameters programatically
like this:
CComPtr <AssemblyComponentDefinition> pAssCompDef ; pAssemblyDoc-
>get_ComponentDefinition (&pAssCompDef) ;
CComPtr <Parameters> pParams ;
pAssCompDef->get_Parameters (&pParams) ;
const long ikNumParams = pParams->Count ;

TRACE (L "There are %d params in %s\n",ikNumParams,pszOccName) ; for (int i = 1 ; i <=


ikNumParams ; i++) { CComPtr <Parameter> pParam ;
pParams->get_Item (CComVariant(i),&pParam) ;

VARIANT VarValue ;
pParam->get_Value (&VarValue) ; VarValue.dblVal ;

CComBSTR bstrParamName ;
pParam->get_Name (&bstrParamName) ;
TRACE (L" param %d is called %s and has a value of %.3f=
\n",i,bstrParamName,VarValue.dblVal ) ;
}
Notice how the parameter data is picked up inside the for loop.
If you have a part occurrence inside an assembly and want to get the parameters of that part a
occurrence you can use this:

CComPtr<ComponentDefinition> pCompDef = nullptr ; hRes = pCompOcc->get_Definition


(&pCompDef) ;
if (FAILED(hRes) || (pCompDef == nullptr)){

return ReturnAndShowCOMError(hRes,L
"ShowComponentOccurrenceParameters, get_Definition failed."); }
TRACE (L"The type of this occurrence is %d, def is %d\n" ,pCompOcc-
>GetType(),pCompDef->GetType()) ;
CComPtr<Parameters> pParams;

CComQIPtr<PartComponentDefinition> pPartCompDef = pCompOcc->Definition;


if (!pPartCompDef) {
return (E_FAIL) ;
}

if (pPartCompDef->IsiPartFactory) { TRACE (L"Is an ipart factory\n") ; }

// It is a part component definition, so we can get the // parameters of the part definition
pParams = pPartCompDef->Parameters;
const long ikNumParams = pParams->Count ;

TRACE (L"There are %d params in %s\n",ikNumParams,pszOccName) ;

for (int i = 1 ; i <= ikNumParams ; i++) { CComPtr <Parameter> pParam ;


pParams->get_Item (CComVariant(i),&pParam) ;

VARIANT VarValue ;
pParam->get_Value (&VarValue) ;
CComBSTR bstrParamName ;
pParam->get_Name (&bstrParamName) ;
TRACE (L" param %d is called %s and has a value of %.3f=

\n",i,bstrParamName,VarValue.dblVal ) ;
}
14.68 get_Item and Item, what sort of parameter?
When I need to get an item from a list, I generally use get_Item, because it crashes less, Item
will throw an exception.
Here, the last two lines of code do the same thing:
CComPtr<UserParameter> pUserParam ;
pUserParameters->get_Item (CComVariant(i),&pUserParam) ; pUserParam =
pUserParameters->Item [i] ;

And what about the parameters? Generally it is an index, and generally that index starts at 1
(not 0) as the first item.

for (UINT i = 1 ; i <= ikNumModelParams ; i++) {


CComPtr<ModelParameter> pModelParam ;
pModelParameters->get_Item (CComVariant(i),&pModelParam) ;

Sometimes, if the item in the list has a text name, you can use the name in the call to get_Item.
For example:

const wchar_t * const pszUserParamName = ... ...


CComPtr<UserParameter> pUserParam = nullptr ; pUserParameters->get_Item

(CComVariant(pszUserParamName),&pUserParam) ;

Horses for courses.


14.69 Suppression and Unsuppression of features

To suppress and unsuppress features in a part simply use the feature's suppression boolean:
pFeature->put_Suppressed(true) ;
Here is a function which will suppress a named part in a PartComponentDefinition:
static void SetSuppressPartFeatureByName

(CComPtr<PartComponentDefinition>& pPartCompDef,
const wchar_t* const
pszName,
const bool bSuppress)
{
TRACE (L"SetSuppressPartFeatureByName %s, %d\n"
,pszName,bSuppress) ;

// Get the list of features...


CComPtr<PartFeatures> pFeaturesList ;
HRESULT hRes = pPartCompDef->get_Features(&pFeaturesList) ; if (FAILED(hRes) ||
(pFeaturesList == nullptr)) {

ShowCOMError(hRes,L "SetSuppressPartFeatureByName get_Features failed");


return ;
}

const long ikNumFeats = pFeaturesList->GetCount() ;


TRACE (L" There are %d pattern features\n",ikNumFeats) ;
bool bDone = false ;

for (long iFeat = 1 ; iFeat <= ikNumFeats ; iFeat++) { CComPtr<PartFeature> pFeature ;


hRes = pFeaturesList->get_Item

(CComVariant(iFeat),&pFeature) ;
if (FAILED(hRes) || (pFeature == nullptr)) {

ShowCOMError(hRes,L "SetSuppressPartFeatureByName get_Item failed");


return ;
}
BSTR bstrName ;
pFeature->get_Name (&bstrName) ;

if (_wcsicmp (bstrName,pszName) == 0) { if (bSuppress) {


pFeature->put_Suppressed (VARIANT_TRUE) ; TRACE (L"Found Feature %d called %s to
be

suppressed\n",iFeat,bstrName) ;

} else {
pFeature->put_Suppressed (VARIANT_FALSE) ; TRACE (L"Found Feature %d called %s to
be

unsuppressed\n" ,iFeat,bstrName) ;
}
bDone = true ;

}
::SysFreeString (bstrName) ;

if (bDone) { break ;
}
}

if (!bDone) {
TRACE (L"Could not suppress feature by name with name =

<%s>\n" ,pszName) ;
}
}

Within a single RectangularPattern (or any other pattern) you can usethis fragment as a
starting point.
In some circumstances Suppressed=VARIANT_FALSE will crash while put_Suppressed
(VARIANT_FALSE) will not. A mystery wrapped inside an enigma. I always use
put_Suppressed.

Note that you'll need to call Update to refresh the display:


pPartDocument->Update () ; // Like an AutoCAD regen
You cannot suppress all types of objects. You cannot, for example, suppress workpoints.
14.70 How to get the value of a user parameter
Here is some code to get the value of a user parameter in an Inventor part:
double GetUserParameterValueByName

(CComPtr<PartComponentDefinition>& pPartCompDef, const wchar_t* const


pszUserParamName)
{
// Parameters contains two lists, Model and User... CComPtr<Parameters> pParameters ;
pPartCompDef->get_Parameters (&pParameters) ;

// Get the USER parameters list...


CComPtr<UserParameters> pUserParameters ;
pParameters->get_UserParameters (&pUserParameters) ;

CComPtr<UserParameter> pUserParam = nullptr ;


HRESULT hRes = pUserParameters->get_Item
(CComVariant(pszUserParamName),&pUserParam) ;
if (FAILED(hRes) || (pUserParam == nullptr)) {

ShowCOMError (hRes,L "Could not get user parameter <%s>" ,pszUserParamName) ;


return 0.0 ;

} else {
VARIANT UserParamValue ;
pUserParam->get_Value (&UserParamValue) ; return UserParamValue.dblVal ;

}
}
14.71 Suppression and Unsuppression of elements in a pattern Read about general
suppression programatically first, if you have't already.

Within a single RectangularPattern (or any other pattern) you can use this fragment as a
starting point for suppressing individual features within a pattern:

CComPtr<Parameter> XCountParam ;
pRectPatFeat->get_XCount (&XCountParam) ; const int ikXCount = XCountParam->GetValue
() ;
TRACE (L"Component %d is called %s, and the x count is %d " ,iRect,bstrName,ikXCount) ;
CComPtr<FeaturePatternElements> pFeaturePatternElements ; pRectPatFeat-
>get_PatternElements (&pFeaturePatternElements) ;

const int ikNumElements =


pFeaturePatternElements->GetCount() ;
TRACE (L", this has %d FeaturePatternElements\n" ,ikNumElements) ;

// Start at 2 because the first element cannot be suppressed for (int iElem = 2 ; iElem <
ikNumElements ; iElem++) { CComPtr<FeaturePatternElement> pFeaturePatternElement ;
pFeaturePatternElements->get_Item
(iElem,&pFeaturePatternElement) ;

VARIANT_BOOL bSuppressed ;
if (((iElem/2)*2) == iElem) { bSuppressed = VARIANT_TRUE ;

} else {
bSuppressed = VARIANT_FALSE ;
}

pFeaturePatternElement->put_Suppressed(bSuppressed) ; }
::SysFreeString(bstrName); }
Note that you'll need to call Update to refresh the display:
pPartDocument->Update () ; // Like an AutoCAD regen
14.72 How to open a document programatically
Here is some example code illustrating how to open a document file:

CComPtr<Documents> pDocs = nullptr ;


HRESULT hRes = pInvApp->get_Documents (&pDocs) ; if (FAILED(hRes) || (pDocs ==
nullptr)) {

ShowCOMError(hRes,L"RunTest,get_Documents failed "); return ;


}
CComPtr<Document> pDoc;
hRes = pDocs->Open (CComBSTR

(L"C:\\PARTS\\MyPart.Ipt"),VARIANT_TRUE,&pDoc) ;
if (FAILED(hRes) || (pDocs == nullptr)) {
ShowCOMError(hRes,L"RunTest, Open failed "); return ;

}
...
14.73 Function calls in Autodesk Inventor C++ programming Every COM C++ Inventor
API method comes in 2 "flavors":
1. low level methods: that take output param as input and return HRESULT, for example hRes
= get_Item (Index,&Pointer).
2. high level methods: that return the result directly and throw exceptions, for example Pointer
= GetItem (Index)

A concrete example of the difference is the visibility of workaxes:

// This "low level" version will not crash and you can look at the success or not via hRes
hRes = pWorkAxis->put_Visible (vbVisib) ;
if (FAILED(hRes)) {
// Show some error message if you want
}

// This "high level" version will throw and exception and crash if something is wrong
pWorkAxis->Visible = vbVisib ;

There are other functions which are high and low distinguished by whether or not they have
Method... in front of the name, high level methods are usually prefixed "Method".

Some examples :

HRESULT hRes = pWorkPlanesList->get_Item (CComVariant(1),&pWorkPlane) ; // low level


version
WorkPlanePtr pWorkPlane = pWorkPlanesList->GetItem (CComVariant(1)) ; // high level
version

...and...

HRESULT hRes = pConstraintList->AddAngleConstraint


(...etc...,&pAngConstraint) ; // low level version
AngleConstraintPtr pAngConstraint =
pConstraintList->MethodAddAngleConstraint(...etc...) ; // high level version

Note that with "low level" versions you often pass the address of a pointer which is the "return
value" of the function.
14.74 Names of objects inside sketches
You cannot name objects inside sketches (sketch points and lines etc) though you can give
them IDs and Attributes.
14.75 COM pointers when programming AutoDesk Inventor Here I'm paraphrasing Adam
Nagy who helped me understand this stuff... My personal solution is explained here.

When using COM objects like the ones provided by the Inventor COM API, then you have to
take care of releasing the references to the objects you retrieved. This is what CComPtr is
helping you with, which is a smart-pointer and provides auto release of objects: when a
CComPtr object variable goes out of scope then its destructor will be called and there it will
release the COM object it is referencing, i.e. it will decrease the reference counter on that
COM object.

Here are a couple of examples to help explain when you have to explicitly release the object
or how to reorganize your code to release the COM objects in time: all objects need to be
released before CoUninitialize() is called.

If your CComPtr is declared inside a function (local variable) then it will only be destructed -
just like any other local variables - when the function returns, and that's when it will release
the reference to the COM object. In case of this sample function the pointer is released too late
because of that:

One easy solution to this would be to place the code part that is interacting with the COM
objects into a separate function, so that the local variables will be release by the time we get to
CoUninitialize():
Another simple solution is to create a local scope around the local variables that ends before
CoUninitialize():
When CComPtr is declared as a global variable then it will only be destructed at the very end,
even after the main function of the application has returned:
See what I mean?
14.76 Create a rectangular pattern programatically

There are a zillion parameters to handle and understand when you create a rectangular pattern
in Inventor. Here is some example code which should help you get to grips with the
RectangularPatternFeature::Add function:

HRESULT CreateZArrayOfFeatures (CComPtr<PartComponentDefinition>& pPartCompDef,


CComPtr<Application> pInvApp)
{

// Get the list of features...


CComPtr<PartFeatures> pFeaturesList ; pPartCompDef->get_Features(&pFeaturesList) ;

// Get the list of rectangular features, we will add to this list....


CComPtr<RectangularPatternFeatures> pRectPatList ; pFeaturesList-
>get_RectangularPatternFeatures (&pRectPatList) ;

// Get the list of *extruded* features, we'll use some of these in the pattern (array)...
CComPtr<ExtrudeFeatures> pListOfExtrusions;
HRESULT hRes =
pFeaturesList->get_ExtrudeFeatures(&pListOfExtrusions);

// Get the features you want to make an array of, put these in an object collection
CComPtr<ExtrudeFeature> pHoleFeature ;
hRes = pListOfExtrusions->get_Item
(CComVariant("NAME_OF_HOLE_FEATURE"), &pHoleFeature);

// Get a named workpoint I want to put in the array... CComPtr<WorkPoint> pTronHoleWp ;


hRes = GetWorkPointByName

(pTronHoleWp,"NAME_OF_WP",pPartCompDef) ;

// Make an object collection


CComPtr<TransientObjects> pTransientObjects;
hRes = pInvApp->get_TransientObjects(&pTransientObjects);

CComVariant varObjEnumerator;
CComPtr<ObjectCollection> pObjectCollection; hRes =
pTransientObjects->CreateObjectCollection(varObjEnumerator, &pObjectCollection);

// Add a hole feature (and extrusion) and a workpoint feature to the object collection
hRes = pObjectCollection->Add (pHoleFeature) ;
hRes = pObjectCollection->Add (pTronHoleWp) ;

// Get hold of the z axis...


CComPtr<WorkAxis> pZWorkAxis ;
GetWorkAxisByName (pZWorkAxis,L"Z Axis",pPartCompDef) ;

// Make the rectangular array, in this case a 3 x 1 CComPtr<RectangularPatternFeature>


pRectPatFeature ; hRes = pRectPatList->Add (pObjectCollection,

// What to create the array from


_variant_t((IDispatch *)pZWorkAxis),
// The X direction of the array
VARIANT_TRUE,

// Natural or invented x direction?

CComVariant(3), // How many items in X?


CComVariant(15.0), // The spacing between X items
kDefault, // Spacing type
CComVariant(), // Default XStartPoint,
CComVariant(), // No Y Direction entity
VARIANT_TRUE, // Natural or inverted in Y
CComVariant (1) , // YCount,
CComVariant (0.0), // YSpacing,
kDefault, // Spacing type
CComVariant (), // Default YStartPoint
kOptimizedCompute, // For faster computation
kIdentical, // Keep features oriented as in the original
&pRectPatFeature) ; // Return value

return (S_OK) ; }
Here is what you could end up with given the above parameters:
If you double click on the
object in the browser you'll get:

Parameters 7 and 13 of Add are X and Y direction start points. Those parameters accept
SketchPoint3D, so you need to create or use an existing Sketch3D.
You can list the RectangularPatterns in a part with this code.
14.77 VARIANT_BOOL
VARIANT_BOOL is a type currently defined as a short:
/* 0 == FALSE, -1 == TRUE */
typedef short VARIANT_BOOL;
Here is an example:
VARIANT_BOOL bSuppressed = pFeaturePatternElement->GetSuppressed () ;
TRACE (L"Element %d suppressed = %d\n",iElem,bSuppressed) ; In this case bSuppressed
will show either -1 (true) or 0 (false).
You can use the predefined macros VARIANT_TRUE and VARIANT_FALSE as values.
Since VARIANT_FALSE is 0 you can use them in ifs like this:

14.78 ParameterPtr and get_XCount

Some Inventor API COM functions take a ParameterPtr, even to get simple integers, like the
count in a RectangularPattern. Here is how to declare and use the parameter pointer in those
cases:

//CComPtr<Parameter> iXCount ; // this works too ParameterPtr iXCount ;


pRectPattern->get_XCount (&iXCount) ;

So you can use CComPtr<Parameter> or ParameterPtr. Here is an example of getting an


integer value:

CComPtr<Parameter> XCountParam ;
pRectPatFeat->get_XCount (&XCountParam) ; const int ikXCount = XCountParam->GetValue
() ;

TRACE (L"Component %d is called %s, and the x count is %d\n" ,iRect,bstrName,ikXCount)


;
So you need to use GetValue()
14.79 Model and User parameters programatically
Inside a PartComponentDefinition is a Parameters list which contains two other lists, the
model parameters and the user parameters:
Here is an example of listing the ModelParameters programatically:

void ListModelParameters (CComPtr<PartComponentDefinition>& pPartCompDef)


{

// Parameters contains two lists, Model and User... CComPtr<Parameters> pParameters ;


pPartCompDef->get_Parameters (&pParameters) ;

// Get the model parameters list...


CComPtr<ModelParameters> pModelParameters ;
pParameters->get_ModelParameters (&pModelParameters) ;

// Print them all out with their names...


const UINT ikNumModelParams = pModelParameters->Count ; for (UINT i = 1 ; i <=
ikNumModelParams ; i++) {

CComPtr<ModelParameter> pModelParam ;
pModelParameters->get_Item (CComVariant(i),&pModelParam) ; CComBSTR
bstrParamName;
pModelParam->get_Name (&bstrParamName) ;
TRACE (L"The name of model parameter %d is %s\n" ,i,bstrParamName) ;
}
}
From the above example you can imagine how to list the UserParameters.
You can change the values of the parameters like this:

HRESULT ChangeDoubleModelParam ( const double kNewVal, const wchar_t* const


pszModelParamName,
CComPtr<PartComponentDefinition>&
pPartCompDef)
/*
Change the value of a double (i.e. floating point) parameter of a
part.
Remember to understand internal units before calling this!
*/
{
// Parameters contains two lists, Model and User... CComPtr<Parameters> pParameters ;
pPartCompDef->get_Parameters (&pParameters) ;

// Get the model parameters list...


CComPtr<ModelParameters> pModelParameters ;
pParameters->get_ModelParameters (&pModelParameters) ;

CComPtr<ModelParameter> pModelParam ;
HRESULT hRes = pModelParameters->get_Item (CComVariant
(pszModelParamName),&pModelParam) ;
if (FAILED(hRes) || (pModelParam == nullptr)) {
return ReturnAndShowCOMError (hRes,L"ChangeDoubleModelParam, get_Item failed") ;
}

// Change the value of the parameter


hRes = pModelParam->put_Value (CComVariant(kNewVal)) ; if (FAILED(hRes) ||
(pModelParam == nullptr)) {

return ReturnAndShowCOMError (hRes,L"CUnits hangeDoubleModelParam, put_Value


failed") ; }
TRACE (L"New Value=%.3f\n",pModelParam->Get_Value()) ;
return (S_OK) ; }
You will probably not see an immediate change in your model when you call the above
function, it needs a call to Update to do that:

ChangeDoubleModelParam (999.0,L "d0",pPartCompDef) ; ChangeDoubleModelParam


(100.0,L"d5",pPartCompDef) ; ChangeDoubleModelParam ( 5.1,L"d9",pPartCompDef) ;
pPartDocument->Update () ; // like regen in AutoCAD
Having a separate Update means you can change many parameters without having Inventor
(wasting time) doing an Update after every change.

See also parameter types and Units


14.80 Gettings objects by name

When you create complex parts and assemblies it is best to name them with other than the
default names. That way you can get hold of them in your program without having to
remember indices into a get_Item array, or having to remember that WorkPoint1 is the point
at the end of the tube or that WorkPlane3 is in the center of the cube.

(Note that for international programs you may prefer to use indices, because the standard
objects created by Inventor change the names. For example "X Axis" in English is "Asse X" in
Italian.)

Here are some functions for getting hold of named objects:

HRESULT GetSketchByName (CComPtr<PlanarSketch>& pSketch, const wchar_t* const


pszSketchName, CComPtr<PartComponentDefinition>&

pPartCompDef)
{
// Get the sketch in the part by name...

HRESULT hRes =
pPartCompDef->Sketches->get_Item(CComVariant(pszSketchName), &pSketch);

if (FAILED(hRes) || (pSketch == nullptr)) {

ShowCOMError (hRes,L "GetSketchByName but could not 'get' sketch\n");


return (E_FAIL) ;
}

return (S_OK) ; }

HRESULT GetWorkPlaneByName (CComPtr<WorkPlane>& pWorkPlane, const wchar_t*


const pszWorkPlaneName, CComPtr<PartComponentDefinition>&

pPartCompDef)
{
// Get the sketch in the part by name...
HRESULT hRes =
pPartCompDef->WorkPlanes->get_Item(CComVariant(pszWorkPlaneName),
&pWorkPlane);
if (FAILED(hRes) || (pWorkPlane == nullptr)) {
ShowCOMError (hRes,L"GetWorkPlaneByName but 'get' failed\n"
);
return (E_FAIL) ; }

return (S_OK) ; }

HRESULT GetWorkAxisByName (CComPtr<WorkAxis>& pWorkAxis, const wchar_t* const


pszWorkAxisName, CComPtr<PartComponentDefinition>&

pPartCompDef)
{
// Get the sketch in the part by name...
HRESULT hRes =
pPartCompDef->WorkAxes->get_Item(CComVariant(pszWorkAxisName),
&pWorkAxis);
if (FAILED(hRes) || (pWorkAxis == nullptr)) {
ShowCOMError (hRes,L"GetWorkAxisByName but 'get' failed\n"
);
return (E_FAIL) ; }
return (S_OK) ;
}

You can imagine what GetWorkPointByName will look like.


Since these functions report errors you could ignore their return values if you want, if there is
an error you'll see it.
14.81 How to get the RectangularPatterns in a PartComponentDefinition

What you need to remember is that a RectangularPattern is a feature, so you need to get the
features of a part in order to get any rectanguar patterns inside that part.

Here is a function which lists the names of rectangular patterns inside the part parameter
passed to it:

void ListRectangularPatternFeatures
(CComPtr<PartComponentDefinition>& pPartCompDef) {

// Get the list of features...


CComPtr<PartFeatures> pFeaturesList ; pPartCompDef->get_Features(&pFeaturesList) ;

// Get the list of rectangular features, we will add to this list....


CComPtr<RectangularPatternFeatures> pRectPatList ;
pFeaturesList->get_RectangularPatternFeatures (&pRectPatList) ;

const long ikNumRecFeats = pRectPatList->GetCount() ;


TRACE (L"There are %d rectangular pattern features\n" ,ikNumRecFeats) ;
for (int iRect = 1 ; iRect <= ikNumRecFeats ; iRect++) {
CComPtr <RectangularPatternFeature> pRectPatFeat ; pRectPatList->get_Item
(CComVariant(iRect),&pRectPatFeat) ;
BSTR bstrName = pRectPatFeat->GetName () ;
TRACE (L"Component %d is called %s\n",iRect,bstrName) ;
::SysFreeString(bstrName); }
}
Error checking has been removed for brevity and clarity, but, as always, you should check the
return values of the various Inventor API functions.
How to add a RectangularPattern to a PartComponentDefinition. 14.82 ResultFeatures
ResultFeatures, when got from Patterns, are workplanes, workpoints, worksurfaces which are
created when the Pattern is created.

ResultFeatures are the result of creating a pattern with some features. You often use them for
getting proxies of the features. Result Features are of the type ObjectsEnumerator, a list of
objects.

Graphically:

Here is a fragment which gets


14.83 ObjectsEnumerator, a list of objects
The ObjectsEnumerator can be thought of a list of objects, from a selection set for example,
or from resulting features in a pattern.
14.84 Parameter types

Apart from Model parameters and User parameters each parameter also has a type
ParameterTypeEnum which specifies who and why a parameter was created.

Here is how to get the information:

ParameterTypeEnum eParamType ;
pModelParam->get_ParameterType (&eParamType) ;
TRACE (L"The ParameterTypeEnum is %d\n",eParamType) ;

and the values can be:

kDerivedParameter : Parameters automatically created from derived component.


kModelParameter : Parameter created automatically by Inventor when a command requires it.
kReferenceParameter : Parameter created automatically by Inventor while creating a driven
dimension, for example.
kTableParameter : Parameters created from a table; like a spreadsheet. kUserParameter :
Parameters explicitly created by the user.

The user units of the parameters are stored as a string and can be accessed like this:

CComBSTR bstrUnits ;
pModelParam->get_Units (&bstrUnits) ;
TRACE (L"Units = <%s> \n",(wchar_t*)(bstrUnits)) ;

You'll get strings like "mm" or "in" etc. Note that internal units may be different.
14.85 Face Edge EdgeProxy
As far as I can tell the EdgeProxy will give you details of where the edge is in the Assembly
into which the Part has been inserted.
14.86 Attributes

An "Attribute" is extra data added to an Inventor object. You, the programmer, can store non
graphical data in an object's attributes. If you have ever programmed AutoCAD you could
compare attributes in Inventor with Xdata in AutoCAD.

AutoDesk supplies a program called Attribute Helper which you can use to add attributes into
objects. For example into the faces of a part.
Imagine the cylindrical surface of the part above has some attribute sets. This is how to list
them programatically:
14.87 CreateExtrudeDefinition
This function does not actually create an extrusion, it should be paired with Add to do that.
Here is an example (error checking removed):

// Now at last we can use the pProfile to create a new extrusion, adding it to the list
// of extruded features
CComPtr<ExtrudeDefinition> pExtrudeDef;
hRes = pListOfExtrusions->CreateExtrudeDefinition(pProfile,
kJoinOperation,&pExtrudeDef);

pExtrudeDef->SetDistanceExtent(_variant_t(kHeight), kPositiveExtentDirection );
CComPtr<ExtrudeFeature> pExtrude;
hRes = pListOfExtrusions->Add (pExtrudeDef); What you need to remember is that an
ExtrudeDefinition is not an extrusion feature.
14.88 Inserting an extrusion in a Part

You need to have a part .ipt document open for the following function to work, and that .ipt
must have a sketch called Sketch1 already existing inside it. I've tested it with an empty
Sketch1.

I've removed much of the hRes checking, but you should do that checking:

static HRESULT AddSolid(CComPtr<Application> pInvApp) {


CComPtr<Document> piDoc;
HRESULT hRes = pInvApp->get_ActiveDocument(&piDoc);

CComQIPtr<PartDocument> pPartDoc(piDoc); // you should check that pPartDoc does not


result in nullptr
CComPtr<PartComponentDefinition> piPartCompDef; hRes = pPartDoc-
>get_ComponentDefinition(&piPartCompDef);
CComPtr<TransientGeometry> oTG;
hRes = pInvApp->get_TransientGeometry(&oTG);
CComPtr<Point2d> oCenterP;
hRes = oTG->CreatePoint2d(0, 0, &oCenterP);
CComPtr<PlanarSketch> pSketch = NULL;
hRes = piPartCompDef->Sketches->get_Item(CComVariant(_T( "Sketch1")), &pSketch);
CComPtr<SketchCircle> pSketchCircle = NULL;
hRes = pSketch->SketchCircles->AddByCenterRadius(oCenterP,2);

CComPtr<Profile> pProfile = NULL;


CComVariant pSegs;
CComVariant preserve;
hRes =

pSketch->Profiles->AddForSolid(VARIANT_TRUE,pSegs,preserve,&pProfile );
CComPtr<PartFeatures> pPartFs;
hRes = piPartCompDef->get_Features(&pPartFs);
CComPtr<ExtrudeFeatures> pExtrudeFs; hRes = pPartFs-
>get_ExtrudeFeatures(&pExtrudeFs);
CComPtr<ExtrudeDefinition> pExtrudeDef;
hRes = pExtrudeFs->CreateExtrudeDefinition(pProfile, kJoinOperation,&pExtrudeDef);
pExtrudeDef->SetDistanceExtent(_variant_t(2.0), kPositiveExtentDirection);

CComPtr<ExtrudeFeature> pExtrude;
hRes = pExtrudeFs->Add (pExtrudeDef);
if (FAILED(hRes)) {

TRACE ("AddSolid but could Add ExtrudeDefinition\n"); return hRes ;


}
TRACE ("AddSolid finished, extrusion added ok.\n");
return hRes; }

Good luck young man.


14.89 Optional parameters and empty COM values

In VB and VBA there are sometimes optional parameters. And often the only help available
for functions in Inventor is the VB version, you have to guess the parameters of the C++
version from the VB version.

When there are optional parameters in C++ which you don't want to use you will probably
have to pass an empty COM type value. A good example is GetTemplateFile:

hr = pFileManager->GetTemplateFile (kAssemblyDocumentObject, // type of file


kDefaultSystemOfMeasure,
kDefault_DraftingStandard,
CComVariant(), // Optional in VB, GUID for Weldment and SheetMetal
&strTemplateFilename); // return value

That fourth parameter is an empty variant because we do not use it in this instance. In the VB
description of the same function it is an optional parameter.

See also function call methods.


14.90 Points and CenterPoints
The difference between these two sorts of points is that CenterPoints are displayed as center
points:

Programatically the difference is here:


CComPtr<SketchPoint> pInventorPt;
pSketch->SketchPoints->Add
(pThePoint,VARIANT_TRUE,&pInventorPt);
That VARIANT_TRUE says "show as center point". Otherwise you should use
VARIANT_FALSE.
You can get the setting for this in two ways:
VARIANT_BOOL bHoleCenter ;
pInventorPt->get_HoleCenter (&bHoleCenter) ; // first method
bHoleCenter = pInventorPt->HoleCenter ; // second method
14.91 GetTemplateFile

The template file is how an new empty file of a new object will look like. It is what is used
when you create a new file, and contains things like units etc. When you do a new part or a
new assembly Inventor uses a template file to create your empty file.

You can get hold of template files for various types of documents like this:

CComBSTR strTemplateFilename;
CComPtr<FileManager> pFileManager;
HRESULT hr = pInvApp->get_FileManager(&pFileManager);

hr = pFileManager->GetTemplateFile (kAssemblyDocumentObject, // type of file


kDefaultSystemOfMeasure,
kDefault_DraftingStandard,
CComVariant(), // GUID for Weldment and SheetMetal
&strTemplateFilename); // return value

In the above call the strTemplateFilename would come back containing something like this:
The second parameter sets the measurement units (mm or inches). It can be

Enumerator Val ue
kDefaultSystemOfMe 896
asure 1
kEnglishSystemOfMe896
asure 3
kMetricSystemOfMea896
sure 2 Description

Installed, default system in use for this user.


English system of measure (inches etc.)
Metric system of measure (mm etc.).

Note that GetTemplateFile can have an empty 4th parameter in this case because we are not
dealing with Weldment or SheetMetal. In those two cases the fourth parameter will be a GUID
which further identifies the sort of standard to be used.

Of course if you know and want to use a specific template file you can simply do this:

without calling GetTemplateFile .


14.92 Add a (planar) sketch to a workplane programatically Here is a function which will
add a new sketch to a named workplane in a PartComponentDefinition:

HRESULT AddSketchToWorkplane (CComPtr<PartComponentDefinition>& pPartCompDef,


const wchar_t* const pszNewSketchName,
const wchar_t* const
pszOldWorkPlaneName)
{
// Get the workplanes list
CComPtr<WorkPlanes> pWorkPlaneList ;
HRESULT hRes = pPartCompDef->get_WorkPlanes(&pWorkPlaneList); if (FAILED(hRes) ||
(pWorkPlaneList == nullptr)) { return ReturnAndShowCOMError
(hRes,L"AddSketchToWorkplane, could not get workplane list") ;
}

// Get the workplane to which we will add the sketch...


CComPtr<WorkPlane> pWorkPlane ;
hRes = pWorkPlaneList->get_Item
(CComVariant(pszOldWorkPlaneName), &pWorkPlane);
if (FAILED(hRes) || (pWorkPlaneList == nullptr)) { return ReturnAndShowCOMError
(hRes,L"AddSketchToWorkplane, could find specific workplane") ;
}

// Get the list of sketches


CComPtr<PlanarSketches> pSketchList ;
hRes = pPartCompDef->get_Sketches (&pSketchList); if (FAILED(hRes) || (pSketchList ==
nullptr)) {

return ReturnAndShowCOMError (hRes,L"AddSketchToWorkplane, could not get planar


sketches") ;
}
// Create a new sketch inside the list of sketches

CComPtr<PlanarSketch> pNewSketch ; // return value of following call...


hRes = pSketchList->Add (_variant_t((IDispatch *)pWorkPlane), VARIANT_FALSE, //
Ignored when based on a workplane
&pNewSketch) ;
if (FAILED(hRes) || (pNewSketch == nullptr)) {
return ReturnAndShowCOMError (hRes,L"AddSketchToWorkplane, could not get planar
sketches") ;
}

pNewSketch->put_Name (CComBSTR (pszNewSketchName)) ;


return (S_OK) ; }

See also this page.


14.93 Component Definition

A part component definition is contained inside a part document. The component definition
contains the nitty gritty of the actual objects you want to manipulate and add to. Often there are
lists of components, like sketches, features, workplanes etc:
To get the PartComponentDefiniton from a PartDocument use this:

CComPtr<PartDocument> pPartDocument ;
... init pPartDocument in some way...

// Get the component definition inside the PartDoc... CComPtr<PartComponentDefinition>


pPartCompDef;
hRes = pPartDocument->get_ComponentDefinition (&pPartCompDef); if (FAILED(hRes) ||
(pPartCompDef == nullptr)) {

return ReturnAndShowCOMError (hRes,L"get_ComponentDefinition failed") ;


}

An AssemblyDocument and an AssemblyDocumentDefinition has the same sort of structure.


Here you can see just two of the many lists inside an AssemblyDocument:
There are other lists inside an AssemblyComponentDefinition. Here is an example of getting
the AssemblyComponentDefinition and the constraints list inside it:

// Init this in some way......


CComQIPtr<AssemblyDocument> pAssemblyDoc = pDoc ;

// Get assembly component definition


CComPtr<AssemblyComponentDefinition> pAssemblyCompDef; hRes = pAssemblyDoc-
>get_ComponentDefinition(&pAssemblyCompDef);

CComPtr<AssemblyConstraints> pConstraintList;
hRes = pAssemblyCompDef->get_Constraints(&pConstraintList) ;
14.94 Adding a workplane to a Part programatically
You need to get the list of workplanes and add to that. Here are the standard workplanes which
are contained in all parts:

As an example here I add a


workplane which is offset from the YZ Plane by 2.3. Here is what we will do graphicaly:

//
Get the list of workplanes in the part...

CComPtr<WorkPlanes> pWorkPlanesList ;
pPartCompDef->get_WorkPlanes (&pWorkPlanesList) ; if (FAILED(hRes) ||
(pWorkPlanesList == nullptr)) {

return ReturnAndShowCOMError (hRes,L"CreateMainTube, could not get work planes list")


;
}
TRACE (L"There are %d workplanes\n",pWorkPlanesList->Count) ;

// Get the YZ Plane work plane (Index 1)...


CComPtr<WorkPlane> pWorkPlane ;
hRes = pWorkPlanesList->get_Item (CComVariant(1),&pWorkPlane) ; if (FAILED(hRes) ||
(pWorkPlane == nullptr)) {

return ReturnAndShowCOMError (hRes,L"CreateMainTube, could not get standard


workplane") ;
}

// Just for fun print the name of the 1st standard workplane... CComBSTR bstrWrkplaneName
;
pWorkPlane->get_Name(&bstrWrkplaneName) ;
TRACE (L"pWorkPlane(1) is called <%s>\n",bstrWrkplaneName) ;

// Create a workplane parallel to the standard YZ Plane... CComPtr<WorkPlane>


pOffsetWorkPlane ;
hRes = pWorkPlanesList->AddByPlaneAndOffset

(_variant_t((IDispatch *)pWorkPlane), // "starting" plane CComVariant(2.3), // how much to


offset

VARIANT_FALSE, // This is important!


&pOffsetWorkPlane) ; // Return value
if (FAILED(hRes) || (pOffsetWorkPlane == nullptr)) { return ReturnAndShowCOMError
(hRes,L"CreateMainTube, could not add workplane with offset") ;
}

// For fun, again, get the name of the new workplane... hRes = pOffsetWorkPlane->get_Name
(&bstrWrkplaneName) ; if (FAILED(hRes)) {

return ReturnAndShowCOMError (hRes,L"CreateMainTube, could not get name of offset


workplane") ;
}
TRACE (L"Offset WorkPlane was called <%s>\n",bstrWrkplaneName) ;

// Change the name of the workplane...


pOffsetWorkPlane->put_Name (CComBSTR (L"Parallel_Smith")) ;

14.95 Set the visibility of all workplanes in a part


Here is how to set all the WorkPlanes in a part to be visible or invisible:
You can write similar functions for WorkPoints and WorkAxes. 14.96 get_ActiveDocument
The active document can be one of many types. Here is an example call:

get_ActiveDocument will put NULL in pDoc if there is no document open. You have to check
that as well as hRes:

CComPtr<Document> pDoc;
HRESULT hRes = pInvApp->get_ActiveDocument(&pDoc); if (FAILED(hRes) || (pDoc ==
nullptr)) {

ShowCOMError(hRes,L"Get Active Document Failed"); return ;


}
14.97 Get and Set the name of an Inventor document You can get and set the document
display name...
...like this:
pPartDoc = CComQIPtr<PartDocument>(pDoc);

BSTR bstrName ;
pDoc->get_DisplayName (&bstrName) ;
TRACE (L"\nFull document name was %s\n",bstrName) ;

pPartDoc->DisplayName = L"George" ;
pDoc->get_DisplayName (&bstrName) ;
TRACE (L"\nFull document name now is %s\n",bstrName) ;
The above also illustrates how to get a part document pointer from a document pointer.
14.98 The .AddIn file

What is the .AddIn file? The .AddIn file is an XML format file which tells Inventor various
things about your program. Inventor knows where to look for .AddIn files and so can pick up
information about your AddIn. Open an example .AddIn file to get familiar with its contents,
you'll be able to find one here:

or in a directory similar.
Here are the most imports parts of an .AddIn file:
ClassId and ClientId which are simply unique identifiers to make sure Inventor does not
confuse your AddIn with other AddIns.

DisplayName and Description are strings which will appear in the AddIn manager. (You can
find the AddIn manager under the Tools tab, Options panel of the Inventor ribbon.)
DisplayName appears in the main list, and Description appears at the bottom of the dialog
when you click on the name in the main list.

The Assembly is the path to the DLL which contains your AddIn, and so it is this entry which
tells Inventor where to find your program. If your DLL is in Inventor's bin directory you can
simply list the name of the AddIn without the full path, for example:

<Assembly>ScrewMaker.dll</Assembly>

The UserUnloadable element specifies whether the user can unload the AddIn. Assumed to be
true if this value is not specified (i.e. user can unload the add-in). Value can be 0 or 1.

The optional Hidden element defines whether the AddIn is visible in the AddIn Manager or
not. A value of 1 indicates that it is hidden, although the end-user can still right-click within
the AddIn Manager and choose "Show hidden members" to display all AddIns. The default
value is 0, i.e. not hidden.

The UserInterfaceVersion is explained here.


14.99 Adding a flush constraint programatically

A flush constraint means two planes are aligned on the same plane. So this means that you
must get hold of the two planes to make them flush. Imagine two boxes, you could select a
face from each box to become flush.
Here is an example of adding a flush constraint with AddFlushConstraint. AddFlushConstraint
requires WorkPlanes or planar objects like faces. The example below uses faces (planar
objects).

When you call this function you'll need two parts (with one box in each part) in the Inventor
assembly document for this to work.
Other sorts of constraints are available too.
14.100Adding a flush constraint using workplanes

Here is an example, which shows that you must use geometrical proxies, assuming you have a
to start off with.

/*
* Get the assembly definition which contains the actual "stuff"...
*/

CComPtr<AssemblyComponentDefinition> pAssemblyCompDef = nullptr ;


hRes = pAsmDoc->get_ComponentDefinition(&pAssemblyCompDef);

/*

* Get the list of occurrences so that you can add two cyliders to it...
*/
CComPtr<ComponentOccurrences> pOccurrencesList=nullptr; hRes = pAssemblyCompDef-
>get_Occurrences (&pOccurrencesList) ;

/*
* Create some geometries to place the parts in space... */

CComPtr<TransientGeometry> pTransGeom = nullptr ; pInvApp-


>get_TransientGeometry(&pTransGeom);
CComPtr<Matrix> pPosMatrix = nullptr ;
hRes = pTransGeom->CreateMatrix(&pPosMatrix); // Defaults to 0 0

0
CComPtr<ComponentOccurrence> pCyl1Occ = nullptr; hRes = pOccurrencesList->Add
(CComBSTR(L"C:\\TEST\\Cyl1.ipt" ),pPosMatrix,&pCyl1Occ) ;

CComQIPtr<PartComponentDefinition> pCyl1CompDef =
CComQIPtr<PartComponentDefinition>(pCyl1Occ->Definition);
CComPtr<WorkPlane> pWorkPlane1=nullptr ;
hRes = pCyl1CompDef->WorkPlanes->get_Item(CComVariant(L"XY
Plane"),&pWorkPlane1);

CComPtr<WorkPlaneProxy> pWPProxy1 ; pCyl1Occ->CreateGeometryProxy

(pWorkPlane1,(IDispatch**)&pWPProxy1) ; CComPtr<ComponentOccurrence> pCyl2Occ =


nullptr; hRes = pOccurrencesList->Add (CComBSTR(L"C:\\TEST\\Cyl2.ipt"
),pPosMatrix,&pCyl2Occ) ;
CComQIPtr<PartComponentDefinition> pCyl2CompDef =
CComQIPtr<PartComponentDefinition>(pCyl2Occ->Definition); CComPtr<WorkPlane>
pWorkPlane2 ;
hRes = pCyl2CompDef->WorkPlanes->get_Item(CComVariant(L"YZ
Plane"),&pWorkPlane2);
CComPtr<WorkPlaneProxy> pWPProxy2 ;
pCyl2Occ->CreateGeometryProxy
(pWorkPlane2,(IDispatch**)&pWPProxy2) ;

// Get the list of constraints of the assembly so you can add a new one
CComPtr<AssemblyConstraints> pConstraintList = nullptr ;
hRes = pAssemblyCompDef->get_Constraints(&pConstraintList) ;

CComVariant varEmpty, varReal(0.0);


CComPtr<FlushConstraint> pFC = nullptr ;
hRes = pConstraintList->AddFlushConstraint (pWPProxy1,pWPProxy2,

varEmpty, varEmpty, varEmpty,&pFC);


14.101Constraints and parts from a programmer's point of view

Inside an AssemblyDocument (or rather an


AssemblyComponentDefinition) Occurences and Constraints can be imagined like this:
You can see that occurences of parts are "constrained" together by constraints. "Ball" and
"Chain" are constrained by the constraint number 1, called "Mate:1"

You can also see that constraint number 4 has a user selected name, "Hold_Me".

When you are programming it might be good to name your constraints so that you can easily
pick the one you are looking for, rather than having to remember the indices or the standard
names.

14.102Loading your DLL


Addins are loaded at the startup of Inventor.

Once you have your Inventor AddIn DLL you need to show it to Inventor so it can be loaded.
You do this by creating an .AddIn file. If you use the wizard that will be done for you. The
.addin file needs to be placed in one or more of several directories.

One example place is here:

Note that the above path will resolve down to something like this:

Also note that maybe you are using a different version of Inventor, so the 2013 becaomes
2014 for example.

Anyway, since the .AddIn file has a path to your DLL, Inventor scans the known directories
and examines the .AddIn files it finds. Hence it reads the <Assembly> part of the .AddIn file,
and knows where to pick up the file.

14.103Sketches in an Inventor Part


This diagram shows you how sketches are contained inside a part:

They are inside a list which is itself inside a component definition. Programatically here is
how to get a sketch by name:

// Get the component definition inside the PartDoc... CComPtr<PartComponentDefinition>


pPartCompDef;
hRes = pPartDoc->get_ComponentDefinition(&pPartCompDef);

// Get the sketch in the part by name...


CComPtr<PlanarSketch> pSketch = NULL;
hRes = pPartCompDef->Sketches->get_Item(CComVariant(L

"MAIN_TUBE_CIRCS"), &pSketch);
if (FAILED(hRes)) {

ShowCOMError (hRes,L "AddSolid but could not 'get' sketch\n" );


return (false) ; }

You can get hold of sketches by index (starting from #1)

CComPtr<PlanarSketch> pSketch ;
// Get the first sketch in the part
hRes = pPartCompDef->Sketches->get_Item(CComVariant(1), &pSketch);

Of course both these sketch getting methods require that the named sketch you are looking
for, or the index, are present in the Sketches list of the Inventor Part.

14.104Add a circle to a sketch function


Here's a function for adding a circle to a sketch:

HRESULT AddCircleToSketch (CComPtr<PlanarSketch>& pSketch, const double xCenter,


const double yCenter, const double kDiam, CComPtr<Application>& pInvApp)

{
CComPtr<TransientGeometry> pTransGeom ; GetTransGeomPtr (pTransGeom,pInvApp) ;

CComPtr<Point2d> pCenter;
pTransGeom->CreatePoint2d(xCenter,yCenter,&pCenter);

HRESULT hRes =
pSketch->SketchCircles->AddByCenterRadius(pCenter,kDiam/2.0);
if (FAILED(hRes)) {
return ReturnAndShowCOMError (hRes,L"AddCircleToSketch but could not add by radius
(Outer)\n");
}

return (S_OK) ; }
Note that this function uses the transient geometry object.
If you don't need that circle itself you can just ignore that last parameter, like this:
hRes =
pSketch->SketchCircles->AddByCenterRadius(pCenter,kDiam/2.0); ...because it defaults to 0.
14.105Default workplanes and default sketches programatically Every part has 3 default
workplanes.
You can add sketches to them programatically like
this, starting with a PartDocument:
// Get part document template
_bstr_t templateFilename = pApp->MethodGetTemplateFile (kPartDocumentObject, // get the
PART template file
kDefaultSystemOfMeasure,
kDefault_DraftingStandard,

vtMissing);
// Get the list of Documents
CComPtr<Documents> pDocs;
hr = pApp->get_Documents(&pDocs);
if (FAILED(hr))

return hr;

// Create a new part document


CComPtr<Document> pDocument;
hr = pDocs->Add(kPartDocumentObject,

templateFilename,
VARIANT_TRUE, // create visible
&pDocument); // return value if (FAILED(hr))
return hr;

// convert generic document to partdocument


CComPtr<PartDocument> pPartDocument;
hr = pDocument->QueryInterface(DIID_PartDocument,

(void**)&pPartDocument);
if (FAILED(hr)) return hr;
// Set a reference to the component definition.
CComPtr<PartComponentDefinition> pPartComponentDefinition; hr =

pPartDocument->get_ComponentDefinition(&pPartComponentDefinition); if (FAILED(hr))
return hr;

// Create a new sketch on the X-Y work plane


//(Fixed predefined).
// Since it's being created on one of the base // workplanes we know the orientation it will be
created // in and don't need to worry about controlling it. // Because of this we also know the
origin
// of the sketch plane will be at (0,0,0) in model space.

// Get PlanarSketches, the list of sketches, probably empty at the moment


CComPtr<PlanarSketches> pSketches;
hr = pPartComponentDefinition->get_Sketches(&pSketches);
if (FAILED(hr))
return hr;

// Get standard default WorkPlanes, probably 3 only initially in the list


CComPtr<WorkPlanes> pWorkPlanes ;
hr = pPartComponentDefinition->get_WorkPlanes(&pWorkPlanes);
if (FAILED(hr))
return hr;

// Get hold of one of the WorkPlanes. 3L here says the XY workplane


// Note that unlike C++ arrays in COM start at 1 (not 0)
CComPtr<WorkPlane> pWorkPlane ;
hr= pWorkPlanes->get_Item(_variant_t(3L, VT_I4),&pWorkPlane); if (FAILED(hr))
return hr;

// Now actually create a sketch and get a pointer to it in one go...


CComPtr<PlanarSketch> pSketch;
hr = pSketches->Add(_variant_t((IDispatch *)pWorkPlane), VARIANT_FALSE,
&pSketch);
if (FAILED(hr))
return hr;

CComBSTR bstrSketchName ;
pSketch->get_Name (&bstrSketchName) ;
TRACE (L"The name of the sketch just made is %s\n" ,LPWCSTR(bstrSketchName)) ;

The last part of the code above shows you how to get the name of a sketch using get_Name.
The following diagram shows the indices to get the standard workplanes:
See also this page.
14.106Add a work point at a sketch point
Here's a function to place a workpoint in space at the same position as a point in a sketch. This
is what we want to do:

This is how to do it:


HRESULT AddWorkPointAtSketchPoint (CComPtr<PartComponentDefinition>&
pPartCompDef, const wchar_t* const

pszNewPointName, const wchar_t* const


pszSketchName)
/*
Adds a workpoint in space at the first point in a named sketch
*/
{
CComPtr<WorkPoints> pWorkPointsList ;
HRESULT hRes = pPartCompDef->get_WorkPoints (&pWorkPointsList) ; if (FAILED(hRes)
|| (pWorkPointsList == nullptr)) { return ReturnAndShowCOMError (hRes,L
"AddWorkPointAtSketchPoint, could not get workplane list") ; }

CComPtr<PlanarSketch> pSketch ; hRes = GetSketchByName


(pSketch,pszSketchName,pPartCompDef) ; if (FAILED(hRes) || (pSketch == nullptr)) {

return ReturnAndShowCOMError (hRes,L


"AddWorkPointAtSketchPoint, could not get sketch") ; }

CComPtr<SketchPoints> pSkPoints;
pSketch->get_SketchPoints (&pSkPoints) ;
long iNumPoints ;
hRes = pSkPoints->get_Count (&iNumPoints) ;
if (FAILED(hRes) || (iNumPoints < 1)) {

return ReturnAndShowCOMError (hRes,L


"AddWorkPointAtSketchPoint, not enough points in sketc") ; }

CComPtr<SketchPoint> pSketchPoint ;
hRes = pSkPoints->get_Item (1,&pSketchPoint) ; if (FAILED(hRes) || (pSketchPoint ==
nullptr)) {

return ReturnAndShowCOMError (hRes,L


"AddWorkPointAtSketchPoint, get sketch point failed") ; }
CComPtr<WorkPoint> pWorkPoint ;
hRes = pWorkPointsList->AddByPoint (_variant_t((IDispatch
*)pSketchPoint),VARIANT_FALSE,&pWorkPoint) ;
if (FAILED(hRes) || (pWorkPoint == nullptr)) { return ReturnAndShowCOMError (hRes,L
"AddWorkPointAtSketchPoint, Add workpoint failed") ; }
pWorkPoint->put_Name (CComBSTR (pszNewPointName)) ;
return (hRes) ; }

This function assumes that there is at least 1 points in the sketch, and takes the first. The
function also takes a name for the workpoint because I find that giving signifigant names to
objects in Inventor makes them easier to find.

14.107Getting and setting the sketch name (as well as other objects) Here is how to get
and set the sketch (and other objects) name:
CComPtr<PlanarSketch> pSketch;
...
CComBSTR bstrSketchName ;
pSketch->get_Name (&bstrSketchName) ; //Get the sketch name ...
pSketch->put_Name (CComBSTR(L"Tube_Base")) ; // Set the name

Many many objects in the Inventor API have names, like workplanes and parts etc. You can
usually interrogate and change the names with the methods shown above.

14.108Rectangular Pattern
RectangularPatternFeatures.Add Method
Description

Method that creates a new rectangular pattern feature. The new RectangularPatternFeature
object is returned. Defining instances in the Y direction is optional. If any of the Y-direction
information is missing, only the X instances will be created.

Syntax

RectangularPatternFeatures. Add( ParentFeatures As ObjectCollection, XDirectionEntity As


Object, NaturalXDirection As Boolean, XCount As Variant, XSpacing As Variant, [
XSpacingType] As PatternSpacingTypeEnum, [XDirectionStartPoint] As Variant, [
YDirectionEntity] As Variant, [NaturalYDirection] As Boolean, [YCount] As Variant, [
YSpacing] As Variant, [YSpacingType] As PatternSpacingTypeEnum, [YDirectionStartPoint ]
As Variant, [ComputeType] As PatternComputeTypeEnum, [OrientationMethod] As
PatternOrientationEnum ) As RectangularPatternFeature

Parameters

Name Description

Input that contains the features to be patterned. The collection could contain the various part
features, sheet metal features, work planes, work axes, work points, or a SurfaceBody. Only
the primary (result) surface

ParentFeatures
body, obtained from ComponentDefinition.SurfaceBodies.Item(1) is a valid input. If a
SurfaceBody is supplied, the only other objects that can be in the collection are work planes,
work axes, work points, and surface part features. Finish features such as fillets and chamfers
may be included only if their parent feature is also included.

XDirectionEntity Linear entity that defines the first direction. This can be an edge a work
NaturalXDirectio n

XCount
XSpacing
XSpacingType
XDirectionStartP oint
YDirectionEntity
NaturalYDirectio n

YCount axis, a work plane (normal is used), a planar face (normal is used) or a Path. Use the
CreatePath or CreateSpecifiedPath methods on the PartFeatures object to create a Path. The
path can be a combination of 2D and 3D sketch elements.

Input Boolean that indicates if the direction of the pattern is in the natural direction of the
XDirectionEntity or reversed. A value of True indicates it is in the natural direction.

Input Variant that defines the number of instances in the X direction. This can be either a
numeric value or a string. A parameter will be created to control this value when the feature is
created. If a string is input it can be any string that can be evaluated by Inventor to result in a
unitless number.

Optional input Variant that defines the spacing between instances in the X direction. This can
be either a numeric value or a string. A parameter will be created to control this value when
the feature is created. If a string is input it can be any string that can be evaluated by Inventor
to result in a unitless number. This input may be left unspecified only if the XSpacingType is
kFitToPathLength and if the XDirectionEntity is not a work axis.

Optional input enum that indicates if the occurrences along the x direction are to be fitted
within a specified distance. A value of kDefault indicates that the occurrences are to be
separated by the specified distance. A value of kFitted indicates that all occurrences are to be
fitted within the specified distance. A value of kFitToPathLength indicates that all occurrences
are to be fitted within a distance equal to the length of the XDirectionEntity. The
kFitToPathLength value is invalid in cases where the XDirectionEntity is a work axis.

Optional input object that defines the start point of the portion of the XDirectionEntity to be
used as the pattern path.

Optional input linear entity that defines the second direction. This can be an edge a work axis,
a work plane (normal is used), a planar face (normal is used) or a Path. Use the CreatePath or
CreateSpecifiedPath methods on the PartFeatures object to create a Path. The path can be a
combination of 2D and 3D sketch elements.

Optional input Boolean that indicates if the direction of the pattern is in the natural direction
of the YDirectionEntity or reversed. A value of True indicates it is in the natural direction.

Optional input Variant that defines the number of instances in the Y direction. This can be
either a numeric value or a string. A parameter will be created to control this value when the
feature is created. If a string is input it can be any string that can be evaluated by Inventor to
result in a unitless number.
YSpacing

YSpacingType
YDirectionStartP oint
ComputeType

OrientationMetho d
Optional input Variant that defines the spacing between instances in the Y direction. This can
be either a numeric value or a string. A parameter will be created to control this value when
the feature is created. If a string is input it can be any string that can be evaluated by Inventor
to result in a unitless number.

Optional input enum that indicates if the occurrences along the Y direction are to be fitted
within a specified distance. A value of kDefault indicates that the occurrences are to be
separated by the specified distance. A value of kFitted indicates that all occurrences are to be
fitted within the specified distance. A value of kFitToPathLength indicates that all occurrences
are to be fitted within a distance equal to the length of the YDirectionEntity. The
kFitToPathLength value is invalid in cases where the YDirectionEntity is a work axis.

Optional input object that defines the start point of the portion of the YDirectionEntity to be
used as the pattern path.

Property that that indicates the method of solution for the pattern. If specified as
kOptimizedCompute, which is the default, patterns are optimized for faster calculation. If
kIdenticalCompute is specified, all occurrences in the pattern use an identical termination,
regardless of where they intersect another feature. Use this method to efficiently pattern large
numbers of features when the feature being duplicated has a distance termination or
terminates on a work plane. If kAdjustToModelCompute is specified, the termination of each
occurrence is calculated individually. Computation time can be lengthy for patterns with a
large number of occurrences. You must use this method if the parent feature terminates on a
model face.

Optional input enum that defines the orientation of the occurrences along either the first or the
second direction. The default is kIdentical indicating that the orientation of all occurrences is
the same as the original occurrence.

14.109PatternSpacingTypeEnum
Constants identifying the pattern spacing type, used in, patterns (arrays) of objects.

Name
kDefault Value Description
33537 Occurrences separated by specified distance. kFitted 33538 All occurrences fitted
within specified distance.
kFitToPathLen33539 All occurrences fitted within path length.
gth
14.110PatternOrientationEnum
PatternOrientationEnum, Constants identifying the pattern orientation method.
Name Value kAdjustToDirection1 33794

kAdjustToDirection2 33795
kIdentical 33793
14.111Occurences as Xrefs
Description
Orientation of occurrences adjusted to direction 1.
Orientation of occurrences adjusted to direction 2.
All occurrences are oriented identically.

If you are familiar with Xrefs in AutoCAD then you can imagine that an occurence can be
considered as a sort of xref.
As Xiaodong Liang of Autodesk said:

" I think this is a good comparison. The Inventor assembly contains the occurrence
information (file, path, transformation etc) only. It does not contain the geometry of the
occurrence. When the assembly is opened, it tries to resolve the occurrence, after that, read the
geometries and display them in the assembly context with the transformation defined with the
occurrence. The occurrence is actually a proxy of the original document. If the original file
cannot be found, Inventor will ask the user to resolve. So it may be OK to say some behaviors
are similar to Xref."

14.112VT_I4
VT_I4 32-Bit signed long value (positive 2147483647 to negative 2147483648 )
14.113CreateObjectCollection
CreateObjectCollection is used for holding collections of profiles and sketches.
14.114rgs file for Inventor AddIns, what is it?
***WARNING***: The old plugin wizard may create this file for you, but it is no longer
required for modern registry free AddIns.
14.115BSTR OLECHAR wchar_t
BSTR is normally defined as an OLECHAR* and is normally a pointer to a wide string.
So this is valid:

CComBSTR bstrSketchName ;
pSketch->get_Name (&bstrSketchName) ;
TRACE (L"The name of the sketch just made is %s\n"

,bstrSketchName) ;
Remember that with TRACE the format specifier requires L to indicate wide char string types
(wchar_t). See here for another example.
CComBSTR is a class which encapsulates BSTR:

class CComBSTR
{
public:

BSTR m_str;
...
...
So use CComBSTR instead of BSTR whenever you can, since BSTR requires more explicit
memory handling, a call to ::SysFreeString after use for example:

As an aside I doubt that anyone is still using ASCII, almost all Inventor programmers are
using UNICODE. For that reason I no longer use the _T macro, which was used to
conditionally compile for both ASCII and UNICODE.

You of course have to check what type of string a given function is requesting. In case of
calling Inventor API functions the strings are required as BSTR (sometimes wrapped in a
VARIANT) which you can get in multiple ways. All of them can create it from wchar_t:
SysAllocString, CComBSTR, _bstr_t

14.116AddForSolid
AddForSolid creates a profile inside a sketch which can be used for extrusion (for example).

CComPtr<Profile> pProfile = NULL;


CComVariant pSegs;
CComVariant pReserve;
pSketch->Profiles->AddForSolid (VARIANT_TRUE, // combine all elements into one "path"

pSegs, // path segments, may well not be used


pReserve, // not used, but parameter requitred
&pProfile); // returned combined profile

The VARIANT_TRUE means combine all the elements in the sketch into one path.
pSegs may well not be used.
In the above case pProfile is the return data from AddForSolid. pProfile could be used later in
the function like this:

CComPtr<ExtrudeDefinition> pExtrudeDef; hRes =


pExtrudeFs->CreateExtrudeDefinition(pProfile,PartFeatureOperationEnu
m::kJoinOperation,&pExtrudeDef);

Next...
14.117VBA, VB.NET, C# or C++
VBA is only recommended for small macros.

VB can create quite large programs, as can C#.


C++ can be used to create EXE files which interact with Inventor from "outside" Inventor.
C++ can be used to create DLLs which run "inside" Inventor and add commands to the
program and icons in the "Ribbon".
14.118Profiles in sketches programatically
A profile is something like a circle, which is contained inside a sketch.
You can get the list of profiles in a sketch like this:

// Get Profiles
CComPtr<Profiles> pSkProfiles;
hr = pSketch->get_Profiles(&pSkProfiles) ;

14.119Installing the SDK


After you have installed Inventor you'll have a directory like this:
C:\Users\Public\Documents\Autodesk\Inventor 2013\SDK

or something very similar. Click on the DeveloperTools.msi . UserTools. msi has real tools
together with source code, so maybe good for looking at samples. Though I have to tell you
that currently (July 2013) most of the samples are very old.

Once you have installed the SDK you'll find another .msi file for the Wizards which create
application skeletons for you. It will be somewhere like this:

C:\Users\Public\Documents\Autodesk\Inventor 2013
\SDK\DeveloperTools\Tools\Wizards\InventorWizards.msi
14.120Creating an Assembly
Here is an example of how to do it in C++
Of course if you know and want to use a specific template file you can simply do this:

without calling GetTemplateFile .


See also creating a drawing, DWG IDW.
14.121Getting the project file location and other options programatically You can use this
fragment:

CComPtr<FileLocations> pFileLocations;
Result = pInvApp->get_FileLocations(&pFileLocations); if (SUCCEEDED(Result))
{
CComBSTR bstrFileLocationsFile;

Result =
pFileLocations->get_FileLocationsFile(&bstrFileLocationsFile);
if (SUCCEEDED(Result))
TRACE(L"Active Project File: %ls \n", bstrFileLocationsFile);
}

and something like this:


static HRESULT GetInventorInformation(CComPtr<Application>& pInvApp) {
// Display some information about Inventor TRACE("\nInventor Information: \n");

CComBSTR bstrCaption;
HRESULT Result = pInvApp->get_Caption(&bstrCaption); if (SUCCEEDED(Result))

TRACE(L"Caption: %ls \n", bstrCaption);

CComBSTR bstrLanguage;
Result = pInvApp->get_LanguageName(&bstrLanguage); if (SUCCEEDED(Result))

TRACE(L"Language: %ls \n", bstrLanguage);

CComBSTR bstrUserName;
Result = pInvApp->get_UserName(&bstrUserName); if (SUCCEEDED(Result))

TRACE(L"User Name: %ls \n", bstrUserName);

CComPtr<SoftwareVersion> pSoftwareVersion;
Result = pInvApp->get_SoftwareVersion(&pSoftwareVersion); if (SUCCEEDED(Result))
{

CComBSTR bstrSoftVerDispName;

Result =
pSoftwareVersion->get_DisplayName(&bstrSoftVerDispName);
if (SUCCEEDED(Result))
TRACE(L"Software Version: %ls \n", bstrSoftVerDispName);
}

CComPtr<FileLocations> pFileLocations;
Result = pInvApp->get_FileLocations(&pFileLocations); if (SUCCEEDED(Result))
{

CComBSTR bstrFileLocationsFile;

Result =
pFileLocations->get_FileLocationsFile(&bstrFileLocationsFile);
if (SUCCEEDED(Result))
TRACE(L"Active Project File: %ls \n", bstrFileLocationsFile);
}
CComPtr<GeneralOptions> pGeneralOptions;
Result = pInvApp->get_GeneralOptions(&pGeneralOptions); if (SUCCEEDED(Result))
{
CComBSTR bstrStartupProjectFile;
Result =
pGeneralOptions->get_StartupProjectFileName(&bstrStartupProjectFile) ;
if (SUCCEEDED(Result))
TRACE(L"Startup Project File: %ls \n\n", bstrStartupProjectFile);
}

// Obtain the 'Visible' property of the active application VARIANT_BOOL bVisible =


VARIANT_FALSE;
Result = pInvApp->get_Visible(&bVisible);
if (FAILED(Result)) return Result;

if (bVisible != VARIANT_TRUE){ pInvApp->Visible = VARIANT_TRUE ;


}

CComPtr<Document> pDoc;
Result = pInvApp->get_ActiveDocument(&pDoc);
if (FAILED(Result)) {

ShowCOMError (Result,L"get_ActiveDocument failed\n") ; return Result ;


}

...etc.
14.122regsvr32

This information is only useful if you are making old style AddIns. New Registry Free AddIns
don't require the use of regsvr32.
Required for when you make AddIns. Two examples:
regsvr32 shmedia.dll (for registering a file)
regsvr32 /u shmedia.dll (for unregistering a file)
Note that the full path of the .dll may be used to ensure that you are registering the correct dll.
The def file is required because it is used to export the functions DllRegisterServer and
DllUnregisterServer. Here's an example:
; SimpleAddIn.def : Declares the module parameters.
LIBRARY "SimpleAddIn.DLL"

EXPORTS
DllCanUnloadNow PRIVATE DllGetClassObject DllRegisterServer PRIVATE PRIVATE

DllUnregisterServer PRIVATE
DllCanUnloadNow is a function inside your code which Inventor calls to see if it can unload
the DLL to free up memory.
14.123What and where is the AddIn manager?
You can get hold of it here:

But also from the Windows Start Menu->Programs->Autodesk->Inventor>Tools. Just look


for the "+" icon.

In your .AddIn file you can put a description of the addin which will appear in the manager:

You can also see the DisplayName from the .AddIn file in the main list of the manager. In this
case it is InventorAddIn5AddInServer.
14.124RxInventor.tlb
A tlb file is a type-library and it contains a description of one or more a COM components.

To get the compiler to find the tlb file you need to add a path to it in the projects properties.
Of these two I've been told to use the one under bin32 :

If you don't add the path you'll get something like this:
C1083: Cannot open type library file: ': No such file or directory.
The compiler will create two more files, in your DEBUG and RELEASE directories:
If you change Inventor version you should
probably erase the tli and tlh files before recompiling.
14.125Adding a rectangle to a sketch

We create a rectangle in a 2D sketch by specifying 2 points. You get the points from transient
geometry object, but they need to be used to create the two SketchPoint things.

// Get the transient geometry object. We'll use this to create pure geometric points
CComPtr<TransientGeometry> pTrGeom;
pTrGeom = pApp->TransientGeometry;

// Draw a 4cm x 3cm rectangle with the corner at (0,0) CComPtr<Point2d> pPt1; // Pure
geometric point
hr = pTrGeom->CreatePoint2d(0.0,0.0,&pPt1);
if (FAILED(hr))

return ReturnAndShowCOMError (hr,L" create 2d point failed") ;

CComPtr<Point2d> pPt2; // Pure geometric point hr = pTrGeom-


>CreatePoint2d(4.0,3.0,&pPt2); if (FAILED(hr))
return ReturnAndShowCOMError (hr,L" create 2d point failed")

// Create sketch points from above points


// Get list of SketchPoints, points existing in a sketch CComPtr<SketchPoints> pSkPoints;
hr = pSketch->get_SketchPoints(&pSkPoints);
if (FAILED(hr))

return ReturnAndShowCOMError (hr,L" get sketch point list failed") ;

// Create a SketchPoint from a geometric point


CComPtr<SketchPoint> pSpt1;
hr = pSkPoints->Add(pPt1, // geometrical point
VARIANT_FALSE, // not a hole center &pSpt1); // resulting SketchPoint if (FAILED(hr))
return ReturnAndShowCOMError (hr,L" add point to sketch failed") ;

CComPtr<SketchPoint> pSpt2;
hr = pSkPoints->Add(pPt2,VARIANT_FALSE,&pSpt2); if (FAILED(hr))

return ReturnAndShowCOMError (hr,L" add point to sketch failed") ;


CComPtr<SketchEntitiesEnumerator> pRectangleLines;

// Get SketchLines
CComPtr<SketchLines> pSkLines;
hr = pSketch->get_SketchLines(&pSkLines);
if (FAILED(hr))

return ReturnAndShowCOMError (hr,L" get lines list failed") ;


TRACE (L"There are currently %d lines in the sketch\n" ,pSkLines->Count) ;
// Creat a rectangle from two points
hr = pSkLines->AddAsTwoPointRectangle(_variant_t((IDispatch

*)pSpt1),
_variant_t((IDispatch
*)pSpt2),
&pRectangleLines);

14.126get_ and Get ?


What is the difference between the functions like these:

GetProperty and MethodMethName(): is called high method syntax get_property and


MethodName(): is the raw syntax.

The first one returns a value and can throw exceptions. The second one returns an error code
and take the return value as in/out param. This is usually the suggested way to use the API,
reason is that your program is less likely to crash in case you are not handling exceptions.

The returned property value itself is of course identical using one or the other syntax.
Using the second method also means that you generally do not have to worry about Releasing
smart pointers and other COM arcania...
See also VARIANT and CComVariant.
14.127UserInterfaceVersion
UserInterfaceVersion is an entry in an .AddIn file.

It is used by Inventor to know when it should regenerate the GUI of your . AddIn. As you
develop your AddIn's GUI this number should be incremeted so that Inventor knows to
recreate that part of the ribbon.

It should be a positive integer. Here's an example:


<UserInterfaceVersion>1</UserInterfaceVersion> And if you change the GUI then you can do
this:
<UserInterfaceVersion>2</UserInterfaceVersion> to let Inventor know.
14.128Difference between CComPtr and CComQIPtr?

CComQIPtr is derived from CComPtr. QI stands for Query Interface. When you construct
with a CComQIPtr it can result in nullptr., which means the cast has not worked. This is useful
to check the type of the pointer. For example:

CComQIPtr<PartDocument> pPartDoc(pDoc) ; if (pPartDoc == nullptr) {


// pDoc did not point to a PartDocument
return (false) ;
}

...and another example...

CComQIPtr<AssemblyDocument> pAsmDoc(pDoc); if (pAsmDoc == nullptr) {


// pDoc did not point to an AssemblyDocument
return (nullptr) ;
}

.
14.129VARIANT and CComVariant
CComVariant is a C++ encapsulation of VARIANT.

They are more or less tagged unions.


An example of using CComVariant when programming in Inventor is in the many get_Item
calls in for loops:

const int ikNumConstraints = pConstraintList->Count ; for (int j = 1 ; j <= ikNumConstraints ;


j++) { CComPtr<AssemblyConstraint> pConstraint;
hRes = pConstraintList->get_Item(CComVariant(j) ,&pConstraint) ;
if (FAILED(hRes)) {
TRACE (L"Could not get the constraint %d of the assembly, hr=%X\n",j,hRes);
return ;
}
TRACE (L"Got constraint %d\n",j); }
Look at that CComVariant(j) call. That is how you send an integer to get_Item when get_Item
wants a VARIANT.
Note also that it all the get_Item things start at 1.
You can create an empty variant and a real double variant as illustrated below:
CComVariant varEmpty, varReal(0.0);
14.130Getting items from collections
You often want to get hold of items in various collections within Inventor objects. You can
often use get_Item to do this.
CComPtr<PlanarSketch> pSketch = NULL;
hRes = piPartCompDef->Sketches->get_Item(CComVariant(_T( "BaseCircles")), &pSketch);
The above code looks inside the list of sketches to find the one called " BaseCircles".
Sometimes you can simply pass an index:

Another way of getting an item from a collection uses get_Item with an cast index:

for (int j = 1 ; j <= ikNumConstraints ; j++) {


CComPtr<AssemblyConstraint> pConstraint;
pConstraintList->get_Item(CComVariant(j),&pConstraint) ; TRACE ("Got constraint
%d\n"),j);

}
In the example above the index is passed as a CComVariant, CComVariant(j).
Here are some other ways of using get_Item:

When using integer indices they always start from 1 (not 0). 14.131Assembly.Document
Assembly
Here's how to get it...
...basically you check to see if the cast (in red) returns something other than nullptr.
14.13264bit vs 32bit
You should use 64 bit compilation when doing an AddIn for 64 bit Inventor.
But you can use 32 or 64 bit when doing an external exe which will communicate with 64 bit
Inventor.
14.133Client Graphics

Client Graphics are graphics which appear in drawings or on objects which a programmer
can add via the API. There is a C++ example of this in the samples.

14.134Hierarchy of objects
The hierarchy is like this:
Assembly
AssemblyComponentDefinition
AssemblyConstraints...
ComponentOccurencesList

ComponentOccurence
SurfaceBodiesList
SurfaceBody
FacesList

Face (Planar, Cylinder, Spheric...) EdgeLoop (Line, Arc, Curve, Spline...)


14.135Getting or running an Inventor Instance
This code runs Inventor if it is not already running:
After that you can carry on an interact with Inventor with pInvApp.
How to correct it if CLSIDFromProgID fails.

14.136Add a part to an assembly programatically


Here is the code to do this, with no error checking:
It is long winded but clear.
14.137Getting hold of the surfaces and faces of a solid object You can start with an
occurrence, then drill down to the data you are interested in:

1. Start with an occurrence.


2. Get the surface body(ies) of the occurrence. There should only ever be 1
3. Get the list of shells from the (single) surface body.
4. For every shell in the list get the Faces.
5. For every Face you can find out what it is.

Here are the sort of surfaces that you can find:

kCylinderSurface kPlaneSurface
kConeSurface
kSphereSurface kTorusSurface
kBSplineSurface

In the end a cylinder is composed of a single shell which is composed of two plane surfaces
and a cylindrical surface.
And here is a code fragment illustrating the process:
14.138Creating a 64 bit plugin using the Wizard

1. Select new project and select Autodesk Inventor AddIn.


2. Follow all the defaults til you get an empty 32 bit project
3. Go to Configuration Manager Release/Debug combo in the tool bar and select New
4. Then in the dialogh which comes up select, under the Active solution Platforms select New
5. Choose x64 in the litlle dialog which pops up
6. Now the first project in the list will default to WIN32, change it to x64
7. Build it

You may well get 2 warnings and 1 error. The error could MSB3073, be that it cannot copy
the .addin file into the Inventor addins directory, This is usually because the .addins directory
in the makefile does not contain the string 2013. For example this is wrong:

"C:\ProgramData\Autodesk\Inventor Addins\" It should be:


"C:\ProgramData\Autodesk\Inventor 2013\Addins"
So you'll have to change that in the command line of the post build event step.
14.139Button Definition
A button definition has two functions:

1. It is a definition of the aspect, look of the button


2. It has an OnExecute member which lets you react to a user clicking on the button

Note that a button definition is not a button, that will be explained later.

Icons of a button are optional, and can be of two sizes Normal size icons are 16 pixels wide
by 16 pixels high. Large icons are 32 pixels wide by 32 pixels high. If an icon of a different
size is provided, Inventor will scale it to fit.

A good place to actually add an instance of a button is in the Activate member of your addin.
Read and understand the comments here:
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
{
// This method is called by Inventor when it loads the addin.
// The AddInSiteObject provides access to the Inventor Application object.
// The FirstTime flag indicates if the addin is loaded for the first time.

// Initialize AddIn members.


m_inventorApplication = addInSiteObject.Application;
// Control definitions are definitons of things like buttons and menus...
ControlDefinitions controlDefs =
m_inventorApplication.CommandManager.ControlDefinitions;

// Create a *definition* of a button, what it looks like mainly...


m_buttonDefinition = controlDefs.AddButtonDefinition( "Owen's Button",

"invrSampleCommand",
Inventor.CommandTypesEnum.kShapeEditCmdType,
"{786675cb-d781-4f02-bfaa-02c4fda0ba61}",
"Owens Desc", "Owens Tooltip") ;
m_buttonDefinition.Enabled = true;
// Now we have to *place* the button somewhere. // This is a lot of drilling down...

// Get the object which handles the user interface... UserInterfaceManager


userInterfaceManager; userInterfaceManager =

m_inventorApplication.UserInterfaceManager;

// Get the list of ribbons...


Inventor.Ribbons ribbons;
ribbons = userInterfaceManager.Ribbons;

// Get the "Part" ribbon, a list of tabs active when editing a part...
Inventor.Ribbon partRibbon;
partRibbon = ribbons["Part"];

// Get the tabs associated with part ribbon RibbonTabs ribbonTabs;


ribbonTabs = partRibbon.RibbonTabs;

// In particular get the "tools" tab... RibbonTab partSketchRibbonTab;


partSketchRibbonTab = ribbonTabs["id_TabTools"];

// Inside the "Tools" tab there are many panels... RibbonPanels ribbonPanels;
ribbonPanels = partSketchRibbonTab.RibbonPanels;

// Get the measurepent panel...


RibbonPanel ribbonPanel;
ribbonPanel = ribbonPanels["id_PanelP_ToolsMeasure"] ;

// Finally we can add the button...


ribbonPanel.CommandControls.AddButton(m_buttonDefinition); }
The Gui heirachy is illustrated here:

14.140Materials API

Material Assets serve to group a physical asset and appearance together. Conceptually a
material can be described by its physical properties (density, Poissons ratio, yield strength,
etc.) and how it looks or its appearance. A material property has some basic information that
identifies it, (name, description, type, etc.), and it references a physical properties asset.
Where do materials exist?
The number of asset libraries changes when you have nothing open (1 for examples) to when
you have an assembly open (4 for example).
14.141Investigating Asset Libraries Progamatically
You can loop over all the asset libraries loaded into inventor like this:
And you'll get a result something like this:
Lib 1 has <Autodesk Material Library>, <C:\Program Files (x86)\Common Files\Autodesk
Shared\Materials\2015\PhysicalMaterial.adsklib>, <AD121259-C03E-4A1D-92D8-59A22B4807AD>. Lib 2 has
<Autodesk Appearance Library>, <C:\Program Files (x86)\Common Files\Autodesk
Shared\Materials\2015\assetlibrary_base.adsklib>, <314DE259-5443-4621-BFBD-1730C6CC9AE9>. Lib 3 has
<Favorites>, <C:\Users\Owen\AppData\Roaming\Autodesk\Inventor 2015\FavoriteMaterials.adsklib>, <D07F930C-485A-
4658-AD69-C91D17FEB99B>. Lib 4 has <Inventor Material Library>, <C:\Users\Public\Documents\Autodesk\Inventor
2015\Design Data\Materials\InventorMaterialLibrary.adsklib>,
<AFEFC330-5E61-4E24-814F-AE810148B79D>.

The internal name is a GUID it looks like.


Once you have an asset lib you can loop over its contents like this:

And the results will look something like this:


DisplayName=<GFRC> Name=<Material-010> CatName=<Concrete> DisplayName=<Gold> Name=<Material-068>
CatName=<Metal> DisplayName=<Iron, Ductile> Name=<Material-071> CatName=<Metal> DisplayName=<Lead>
Name=<Material-072> CatName=<Metal> DisplayName=<Silver> Name=<Material-076> CatName=<Metal>
DisplayName=<Steel> Name=<Material-077> CatName=<Metal> DisplayName=<Steel, Galvanized> Name=<Material-
079> CatName=<Metal>

I think the display name will change from language to language, but I need to investigate
further. Categories are clearly Metal, Concrete, Wood etc.
15 Using Inventor manually

15.1 iParts
15.1.1 iParts general info
iParts work with parametric parts.
Steps to create an iPart, a tube for example:

1. Create a new part.


2. In the sketch add a circle
3. Add a dimension to the circle and in the tiny mm box type Diameter=20
4. End the sketch and extrude it.
5. In the edit box for the extrusion type Length=50.
6. Finish the sketch
7. Now you have two model parameters named as you want as Length and Diameter (instead
of the default L0 and D0).
8. You also have a tube which is 20 by 50
9. Now go into the Manage tab and click on the Create iPart icon.
10.Now you can create a table of different sized tubes. Each row of the table is called a
Member.

15.1.2 iPart - standard vs custom

A standard iPart has parameter values which must be selected from a predefined list. e.g. part
code corresponds to a record in a table. The record contains the parameters like angle and
length to specify the iPart for that code.

A custom iPart allows you to write whatever values you want, not just selecting one of several
fixed values from a list.
In the SDK there are two examples of iParts, one custom one standard, in this directory...

...you should find


and .
15.1.3 iPart author
To get to the iPart Author click on the Create iPart icon in the Manage tab.
You must have Excel installed for iParts to work.
15.1.4 iPart Member and PartNumber

As far as I can tell there is some confusion here. It seems that Member is the key index into the
table, and maybe PartNumber is a descriptive field. This confusion/duplication/feature is due
to history.

So when creating iParts make sure that Member has the code of the object you are creating,
like 34120009.

Why is a new column needed? It is because sometimes members can have the same Part
Number. PN is just a user book-keeping attribute. We need a column with unique values.

In summary, the Member column has to be there. The cell values can be changed but they have
to be unique. Please do not delete or relocate the column.

The Member also gives the name to any temporary files created by the iPart factory.

The iPart also generates "children" files, which represent each of the members of your table.
These are files that you normally don't have to do much with, as they are controlled by the
table in the Factory part. The file names for these child parts are controlled by the Member
name from the table - hence, when you change the member names, their file names will
change. This (not the name of the factory part) is what the warning message was referring to.

15.1.5
Custom iParts
Create your part normally, for example a cylinder with Diameter and Length dimensions.

Clicking on the Create iPart icon you'll get the iPart Author dialog, right click on the
Diameter column and select Custom Parameter Column:
The diameter column will become purple. Do this with all the other parameters to make the
custom iPart:

When
you place the custom iPart inside an assembly you'll be shown this dialog, where you can
change the values:
Here is an example of the 3
custom iPart cylinder instances inside an assembly:

How to change parameters of an already created custom iPart. 15.1.6 Changing Custom
Ipart Parameters

Once you have created a custom ipart you can change the parameters by Activating its table:
So here I'm
changing the parameters of the"derived" object.
In the above screenshot the "source" object is Tubo-CHS-LHS-Custom. ipt
15.1.7 Suppression of features parametrically using the iPart Author

You need to drag the feature into the right hand panel of the Suppression tab, then the accepted
values inside the parameter edit box is C or S. (Computer or Suppress).
15.1.8 Changing from iPart back to normal part

If you have an iPart with a table and you want to get back to a normal part without a table,
open the iPart, right click on the table, and select "Delete"

1. You'll get a warning about turing the file back into a normal part. 2. Remember to set the
parameters to those that you want before

removing the table.


3. Do this on a copy of you want to keep the original tabulare iPart. 15.2 Patterns (arrays) of
features

To create a rectangular array of features follow these steps which show how to create a linear
array:
1. Click on the rectangular pattern icon (the dialog pops up) 2. Select the feature
3. Click on direction icon
4. Click on (for example) and axis
5. Modify the spacing

And voila':

15.3 Problems
encountered while executing this command. You may get this message if you are trying to
do something in an Assembly when you should be doing it in a Part.
For example you will not be able to extrude from a sketch in an Assembly, but you will inside
a part.
15.4 Suppression and mirrored features
If you suppress a part, will its mirror be suppressed too?
Yes.
15.5 Filename of referenced doc
The FullDocumentName seems to be the filename. Here's an example
15.6 Open a part from a view
Here is a fragment to show you how:
.
15.7 Crash when creating a new drawing
You may get this message:
It may be fixed, perhaps, by following the instructions above and changing the hardware
accelleration (inside Inventor) from performance to conservative.

15.8 Project files

You should start all new projects with a project file. It will be inside a directory with the same
name as the project and will contain a ProjectName.ipj project file.

Projects are a way of organizing many components, parts, assemblies etc. There are two main
reasons for having a project file.
1. Organise a single standalone project
2. Have a library of read only components.

For single users project directories contain all the (new) components of the project, i.e. sub
drectories are not used. Libraries contain parts and assemblies which will not be modified.

The book: Mastering AutoDesk Inventor 2013 has some interesting techniques for project
files.

Project files are XML files. Note that when you open a .ipt or .iam the dialog box also
specified the project:
You can set the top level directory of all your projects using the Application Options dialog.

Include= (in the project options dialog) tells you which other projects can be accessed from
this project.
15.9 File types

Inventor Standard Part File: *.ipt. : Used for storing general single or multi-body
components or part. For example a shaft, bolt, etc. Part files are the building blocks of any
design. Collections of part files come together to make an assembly. The Inventor standard
part file can be created easily by using the Standard (mm).ipt, Standard (in).ipt or Standard.ipt
template on the New File dialog box.

Inventor sheetmetal part file: *.ipt. Used for creating parts (and iParts?) or components
with constant and thin thicknesses. Most sheet metal parts have thicknesses ranging from 1
mm to 6 mm. You can create sheet metal parts by using the Sheetmetal (mm).ipt, sheetmetal
(in).ipt or sheetmetal.ipt template on the New File dialog box.

Standard Assembly File: *.iam. It is used for storing assembly files. Collections of part files
come together to make an assembly. An assembly file is made of parts or components that are
linked to each other parametrically. All assemblies without weldments are accommodated
here. Inventor standard assembly files can be created by using the Standard(mm).iam,
Standard(in).iam or Standard.iam template on the New File dialog box.
Inventor Weldment Assembly File: *.iam. This type of assembly file is used for creating
assemblies that require welding process for joining one part or component to another. This
file type can be created by using the Weldment.iam template on the New File dialog box

Inventor Drawing File: *.idw or *.dwg . The Inventor detail drawing files are used for
creating design documentation. In a drawing file, one creates views (sectioned, detailed,
orthographic, auxiliary, etc) accompanied with annotations, dimensions and Bill of Materials
(BOM). There are two ways of creating drawing files in Inventor. One is with the *.idw file
type and the other is with the *.dwg. The DWG format is an industry standard and such files
may be viewed with AutoCAD-based applications.

Inventor Presentation File: *.ipn *.ipt: Used for creating exploded views of assemblies.
These exploded parts could be animation to visualize how the parts will be assembled Can be
created by using the Standard(mm).ipn, Standard(in).ipt or Standard.ipn.

Inventor Project File: *.ipj : This is like the root of a large project.
Inventor iFeature file: .ide : A file for an iFeature..
15.10 Creating a drawing of an assembly or part

You need to have the assembly (or part) already open before you can create a drawing of it.
And then, oddly enough, you have to create a new drawing using the file menu, and then
specify the assembly.

1. Use the "file" new drawing command, you'll get a piece of paper on the screen.
2. Right click on the paper and select "Base View"
3. Choose various parameters:
You can also get the above dialog by right clicking on the view and selecting "edit".
15.11 Delete a parameter
Use the Parameters list dialog box and right click on the line of the parameter you want to
delete.
Note that if the parameter is in use you'll not get a "Delete Parameter" menu item.
15.12 FlipNormal and WorkPlane constraints
When you use WorkPlanes for constraints remember that they have a normal direction. The
normals are the white arrows in the diagram below:
You can change the normal direction by choosing FlipNormal from the workplane's context
menu.
If you see a red(dish) workplane you are looking at the front of it. If you see a blue(ish)
workplane when you are looking at the back of it.
15.13 Add a point to the surface of a tube manually
The first step is to put a plane at the required height:
Put a sketch on that new plane, then project the geometry of the tube onto the sketch. Draw a
line and put a point at the intersection of the geometry and the line.

15.14 Add a feature to an existing pattern

You can add a feature to an existing pattern by simply editing it and when the dialog comes up
(don't click in the dialog) hover the mouse over the feature you want to add (you'll see a +
sign near the cursor). Then click on it.
NB : In the browser you must put the new features you want to add to the pattern higher up
than the pattern itself. The features you want to add to the pattern must be considered to be
created before the pattern itself.

15.15 Change the offset elevation of a plane


Double click on the plane:
and
you'll get the edit box.
15.16 Removing material with the cut extrusion command
Here is the sequence:
15.17
Templates and Template files
You will find the template files in this directory (or something similar)

When you create a new file (a new assembly or part) the template choosing dialog...
...will respect what is inside the templates directory...
15.18 Problem when inserting iParts into Assemblies
You may get one of these messages while trying to insert a specific member of an iPart:

When it happened to me I found that only certain members had problems. I had to copy those
members in the iPart Author with a temporary new member name, then delete the offending
rows, then rename the member to the original code.

For example code (member) 123456 gives you problems:


1. Create a new entry in the table, 123456N for example.
2. Set the column values to be the same as 123456.
3. Delete 123456, and rename 123456N into 123456. You'll be warned that changing the
member name will change the filename. Continue anyway.

15.19 Plane on the surface of a tube at an angle


Create a sketch with a circle and a line. Add a point at the intersection of the circle and the
line:
You may have to promote that sketch to see it at Part level.
Anyway, then use the WorkPlane at tangent to surface through point:

15.20 Add an angular dimension


You select the Dimension icon and then select two lines.

The problem is that the standard axes are not considered lines, so you have to add one
manually before you can select it. Add a line along the axis you want to use as the base for the
angular dimension, in other words.

15.21 Editing Model Parameters and how they are displayed Double click on a dimension
in a sketch to change the value of that dimension.
To see the name of the dimension change the document settings as follows:

Select Display As Expression in the radio buttons. Then you'll get "d0=45" rather than just
"45". Not only but you can also change the name of the parameter, for example from "d0" to
"DiamTube".

15.22 Changing the default units


Use the application options to change the default template file:
You can also change this in the document options:

When
programming Inventor internal units are fixed.
15.23 Adding a Dimension in a sketch
The add dimension icons are in the constrain panel of the sketch tab.
For example...

Create a circle in Sketch mode and create a dimension in the Tools tab. Then click on the
Parameters icon in the Manage tab. Now you can change the name of the parameter from "d0"
to, for example, "MainTubeDiam". So that parameter now controls the diameter of a tube
constructed on that sketch.

15.24 WorkPoint in center of a hole


If you want to place a work point in the center of a hole one option is to use the "Point In
Center Of Loop Of Edges" function:

You'll have to select one of the two circles which forms the hole.
Autodesk forum also showed me this:
See also center points and non.
15.25 Extruding sketches with multiple concentric circles

If you add several concentric circles into an Inventor sketch, when you extrude the sketch,
Inventor will need to know which areas you want to extrude. Click inside the ones you want.

Three
circles have been interpreted correctly when the extrusion happened.
15.26 Getting to the constrain icon in Inventor
You must be in assembly mode to see the constrain icon!

Doh!
15.27 Deleting, removing a constraint
Right click on the constraint in the browser and choose "delete".

The delete key on your keyboard will not work for this operation, it seems.
15.28 Creating a big tube with holes in it
Start a new part and then a new sketch. Use the XY plane for your sketch:

While in sketch mode draw two circles on it, then exit the sketch:
Now extrude, you may have to select the "profile" as being the area between the two circles:

In the browser select the yz plane and


create a new sketch there:
Like this:
Now you have to put some points in the sketch which can be used as hole centers. To do this
make sure that center point is highlighted like this:

Now when you use the point


command the points you make can be used as center points:
Putting 3 points in the
yz sketch will look like this:

Click on Finish Sketch, you'll return


to the 3D part view. Now click on the Hole icon and you'll get something like this:
15.29 Contraints between 3D part objects
Move into the Assemble tab and click on the Constrain icon, see below:
The screenshot
above also illustrates the fact that constraints can have names, apart from Mate:1 etc. Note
George and Mildred.
3D object based constraints are generally at the level of assembly, and constraints "connect"
parts within the assembly.
Click here for constraints and parts from a programmers point of view.
15.30 Creating a workplane offset from another plane
Here is how to move a workplane, offsetting a workplane, use this menu:

And this sequence to


specify the offset:

15.31 Flush Mate And


Axis Constraint Example
To put a tube inside a hole inside another tube you can make a flush costraint with a
workplane tangential to the cylindrical surface:

And the next step is to make the two axes coincident:


So
two constraints.
15.32 How to change the background of the Inventor screen Use Tools | Application
Options | Colors tab.
15.33 Browser is missing! Get it back!
Go to View tab, User Interface icon.
15.34 Work Axis Thru Circular Hole
Do it like this:
Simples! No?
15.35 Driven Dimensions and their Removal/Change
Driven dimensions are controlled by the geometry.

Turning a driven dimension into a normal dimension: Right click on the dimension then if it
is a driven dimension a small window will show you a check box checked. Uncheck it.

Driven dimensions have brackets around them, like: (45,921)


Compare these with driving dimensions.
15.36 Example of dimensions and parameters in a sketch
Two circles, to form a tube, later. Change the names from d1 and d2 then add a thickness:
Now, to change InnerDiam into a driven dimension:
And you'll
get a tiny dialog where you can type in a formula:
Click on the green tick.
You'll see the driven dimension:
15.37 Work Point in
center of a hole (COPY)
The insert constraint requires a flat object, and a tube in a cylinder is not a flat circle
So this will not give you an insert constraint...

...which is why they've added a point in the center of


a loop of edges.
15.38 Inserting an inclined workplane
Here are the steps.
Make sure an axis is visible, like that Inventor will give you the possibility to rotate it later:
It may be the fact that
you have selected an axis which allows you to incline the plane later. Which happens in the
fourth step:

15.39 Change material / color of a solid


Select the object in the browser, and then use the material combo at the top of the window:
15.40 Viewing
Multiple Documents in Inventor
If you have more than one document or window open in Inventor you'll see it in the tabs, as
shown below:

15.41 How to move a 3D object


Simply right click in the browser on the object you wwant to move:
You will get 3 axes which you can
drag.
15.42 Contact set
A contact set is a subset of points for calculating interference.
15.43 iLogic
iLogic is basic simple programming to control parametric parts.
15.44 Showing expressions in a sketch
In the sketch right click on the graphics screen and select

Dimension Display - > Expression


15.45 No visible unadaptive sketches
You might get this error message:

No visible unadaptive sketches


...if you make a sketch at assembly level rather than part level.
15.46 How to make a hollow tube

1. Start a new part, clicking in the main window.


2. Make a new sketch for this part.
3. In the 2d commands draw a circle.
4. Select Offset and so make another circle inside the first.
5. After getting the two circles to the rights size clikc on Finish sketch
6. You are now in the 3d Model tab
7. Click on Extrude and click between the two circles so that the ring becomes grey.

15.47 The Marking Menu


This is the menu which pops up when you right click in the graphics area.

You can use that to get to know where some commands are, so that you can use mouse
gestures (drag with "other" button pressed) for very quick access.

15.48 Customizing the menu


Use the tools tab customize icon.
15.49 fx: and parameters and formulas
If you add a dimension but set it not to a numeric value but to a parameter, then that dimension
will be shown with an fx: in front of it.

To get a sketch dimension to be a user parameter all you need to do is


1. Create the user parameter. Use the big f icon under the manage tab.
2. When you create an object in sketch mode, instead of typing in a number, type in the name
of the user parameter.
These are called driving dimensions. Compare them to driven dimensions.

Difference between model parameters and user parameters. Model Parameters are created
automatically when you create an object, and are given automatic names, d0 for the diameter
of the first circle you draw, for example. You can name model parameters on the fly, for
example when you draw a circle, and then do a dimension of it instead of typing 35, type
InnerTube=35 directly. In that way what would have been d4 (for example) becomes
InnerTube. Actually type that into the tiny dimension edit box. It will then appear in the f
dialog.

User Parameters are created by you to maybe drive dimensions, and maybe be applied to
more than one part of the sketch.
15.50 Showing dimensions temporarily
In the browser right click the object (for example a feature) and select Show Dimensions.
Select the same object to switch them off.
To remove the dimensions just click somewhere else in the browser. I'm not totally clear on
all this at the moment.
15.51 View face command
The view face command lets you select a face in a 3D object and view it head on, from its
normal type like.
15.52 Changing home view setting
Go to the view you want to be the home view then right click on the home view icon, the
examine the menu which pops up.
Front Top Right is the default visibility of the cube for home view.
You can choose to set the current view as fit to view or fixed distance.
15.53 Create a sketch by default on creating a new part
Use the Tools Application Options Part tab to select create x-y sketch automatically.
15.54 Inches problem

Sometimes you create a new project and unless you are careful the first part you put in will be
in inches. When you create the component be sure to select the Metric/Standard (mm).ipt
template. You may have to hit the browse button in the dialog to do that.

Alternatively in the Project dialog Folder Options you can point the template directly at:
Templates = C:\Users\Public\Documents\Autodesk\Inventor 2013 \Templates\Metric\
15.55 Backup options for Inventor files
This is an item in the project options. Select the project in the upper pane and select the
Options branch in the lower pane.
The default setting for Old Versions To Keep is 1, keep one backup. You can set this to 2 3 4
or whatever.

15.56
ul as a dimension
ul means unitless and you'll see it inside rectangular pattern properties as a count of the
number of repititions.
15.57 Editing a sketch flatly
Use the look at command (rectangle and arrow icon) and click on the sketch to get that sketch
flat on the screen.
15.58 Enable and Disable parts and assemblies
If you right click in the browser a part you can Enable or not Enable it. When not enabled it
goes green and cannot be selected.
15.59 Yellow Dot Green Dot Constraints
When doing a sketch yellow snap nodes are not constraints, whereas green snap nodes are
constraints.
A circle with a center snapped off the origin (becomes a yellow node), maybe on a axis, can
be moved. These are called "soft snaps".

A circle with a center snapped on the origin (becomes a green node), cannot be moved.
Snapped to green are called "hard snaps" because the object cannot be moved afterwards.

15.60 Completely and adequately constrained sketches

A sketch has dimensions and constraints. Here is how to add constraints manually:
The two red arrows show how to add a tangent constraint between a line and a circle.

The two green arrows show how to add a contraint between a WorkPoint and a line endpoint.
Inadequatrely constrained objects are black.

The bottom right status bar in sketch mode tells you whether the sketch is fully constrained or
not. It will either say
Fully Contrained or N dimensions needed.

15.61 Sketch plane


The sketching plane is by default the XY plane and extrusions go along the Z axis.
But you can change the default sketch plane, use the Tools tab, application options dialog, Part
tab.
15.62 Extruding with widening angles
When you are extruding something you can use the tab key to switch between length minibar
and angle minibar.
15.63 Getting into and out of sketches
To get into a sketch, in the browser on the left of the screen right click on the node called, for
example, "Sketch1" and choose Edit Sketch.
To get out of a sketch simply click on the green Finish Sketch icon at top right of the main
tool bar.
It pops up also if you do a right click anywhere on the sketch.
15.64 Trim and Fillet
Fillet and Chamfer:

These commands exist in Inventor in the sketch tab. Select two lines (use the shift key for
multiple selection) then click on the Fillet (or Chamfer only one will be visible at the same
time) icon in the toolbar. You can change the radius of the fillet by clicking on the number
which specifies the current size.

Chamfers also have a size and again you change change it by double clicking on the number.
Trim:
In Inventor trimming is easy Create a sketch with two overlapping rectangles, click on the
Trim command (middle of the toolbar) and hover the mouse over the lines which intersect.
Click to actually trim.

These are sometimes called placed features and should be done at the end of a job, not at the
beginning.
15.65 Sketches and Features
In general Sketches are 2D and features are 3D objects.
You have a basic solid feature created from a 2D sketch.
15.66 Vault
Autodesk Vault locks down Inventor files for their protection.
There is a Vault icon in the Inventor toolbar.
15.67 Inventor Apprentice

Apprentice Server is basically a read-only subset of the Inventor API unless you are doing
some file manipulations - like savecopyas. It's not a great subset either. I have not been able to
use it much in my apps yet.

Inventor Apprentice is a freely available programming component that can be used by a


program to read information from Inventor files. In a few cases, it is also possible to write
information. A key part of understanding how to use Apprentice is to understand what its
capabilities are, both what it can and cannot do. This class will look at the functionality of
Apprentice using several sample programs to illustrate its capabilities.

The simple way to think of Apprentice is that it's a smaller version of Autodesk Inventor that
does not have a user interface. Without a user interface the only way to access its functionality
is by using its API. Apprentice is actually an ActiveX component. It runs within the process
space of the client that's using it. For example, if you write a Visual Basic program that
displays information about the contents of an assembly, Apprentice will be running within
your VB program's process space. Apprentice can be very efficient for certain applications
because it's smaller than the complete Autodesk Inventor application and because it runs in the
same process as your application.

The API exposed by Apprentice is a subset of the complete Autodesk Inventor API. Apprentice
provides access to file references, assembly structure, B-Rep, geometry, attributes, render
styles, and document properties. Access to the assembly structure, B-Rep, geometry, and
render styles is read-only.

15.68 Workplanes and Sketches, Creating a sketch on an arbitrary plane


Workplanes need geometry, for example 3 points. Often workplanes are added to parts.

First you make a workplane, so far what I have done is insert 3 points and use the workplane
from 3 points command. Then make a sketch form that.

Default workplanes exist in every part, xy yz and xz planes.


FYI in a program workplanes can be accessed like this:

15.69 Grounded Parts

An assembly is a collection of parts and by default the first component in an assembly file
will be grounded. This means it cannot move, and probably the other components will be
offset relative to it. This assembly has two parts. The pushpin says which is grounded and
cannot be should not be moved.
15.70 Changing manipulator snap
Use the Document Settings in the Tools tab. Then choose the Modelling tab, 3D Snap Spacing
edit box.
15.71 Get the browser pane back
Go into the view tab and click on the user interface icon near the center.
15.72 Application Options Settings
At empty startup go into the Tools tab and click on Application Options.
The files tab of this dialog lets you change various directories, like your default projects
folder.

If you can't find an option in Application Options it is probably in Document Settings (next to
each other in the Tools ribbon). You can use templates to make application wide document
settings.

15.73 Mini tool bar autofade


Switch autofade on and off using the minitoolbar options, usually a menu near the red X
button.
Acknowledg ements 291

16 Acknowledgements

Thanks to, in alphabetical order (most , but not all, of these people work for AutoDesk):

Vladimir Ananyev Jonathan D. Kriek Philippe Leefsma

Xiaodong Liang Adam Nagy


Kean Walmsley
Caroline Ward

If I've left anybody out, my apologies and please let me know!


Index
- .
.addin 17, 187
.AddIn file directory 187
.AddIn file in Autodesk Inventor C++ Programming 180
.AddIn manager 207
.addins directory 219
.DEF file 206
.dwg 241, 242
.EXE file 17
.iam 241
.ide 241
.idw 241, 242
.ipj 240, 241
.ipj programatically 204
.ipn 241
.ipt 241
.rgs file for Inventor AddIns, what is it? 199 .tlb 208
- :
::SysFreeString 199
- \
\n in a table 73
\r in a table 73
- _
_com_error (Autodesk Inventor) 89
_T macro 199
_WIN32_WINNT=0x0501 in Inventor Programming

46
- 0
0x800401e3 MK_E_UNAVAILABLE Autodesk Inventor Programming 46
0x800401f3 CLSIDFromProgID failure 49
- 1
1083 208
1083 in Inventor Programming 47
12291 64
- 2
2064: term does not evaluate to a function taking 0 arguments 49
2130706443 64
- -
-2147467259 registration error in Inventor Programming 50
- 2
2774 compile error in Inventor programming 50
2d and 3d points (abstract geomety) 110
2d sketch 281
2d sketch solid feature 285
- 3
3073 error 219
32 vs 64 in Autodesk Inventor Programming in C
219
3D snap spacing 288
- 4
4278 Autodesk Inventor Programming 50
- 5
50348544 is kModelParameterObject 64
- 6
64 bit AddIn in Autodesk Inventor Programming in C++ 215

64bit vs 32bit in Autodesk Inventor Programming in C++ 215


67113776 64
- 8
80004005 error when saving Inventor documents
131
800401f3 CLSIDFromProgID failure 49
80070057 and WorkFeature visibility 115
83886592 64
83887616 64
83893504 64
83893664 64
83923968 64
- A
Acknowledgements 291
active document 204
Active Document, Inventor programming in C++ 178
Active Inventor Document, how to get it 214 ActiveDocument 84
Add a circle to a sketch function 189
Add a feature to an existing pattern 245 Add a mate constraint with two planes
programatically, Autodesk Inventor Programming 91
add a part into an assembly 42
Add a part to an assembly programatically 216 Add a point to the surface of a tube manually 244 add a rectangle to a sketch
programatically 209 add a sheet to a drawing 86
Add a sketch based on a workplane 118 Add a sketch on a part's default workplane programatically 190
add a sketch programatically 172
Add a work point at a sketch point 192
Add a workplane based on an existing workplane 118
add a workplane programtically 176
Add an angular dimension 252
add an extrusion to a part programatically 168 Add an occurrence to an assembly does not work 123
Add function calling (occurrences) 123
Array of objects programatically 149
arrays (rectangular) in Autodesk Inventor
Programming in C++ 159
Arrays in COM 74
Ascii 30
ASCIIand UNICODE 199
Assemblies - Hierarchy 215
assembly 241
assembly .iam 241
Assembly Close programatically 83
Assembly creation programatically 202
assembly document creation 216
assembly document opening (Inventor API) 75 Assembly in .AddIn file 180
Assembly.Document get current one 214 AssemblyComponentDefinition - Hierarchy 215 AssemblyComponentDefinition and
component occurrences 121
AssemblyDocument from general Document 216 AssemblyDocument, get currenr document 214 asset lib access
programatically 224
asset looping 224
assets, material API 223
Attribute Sets in Inventor Programming 163 Attributes in Inventor programming in Autodesk Inventor Programming in C++
163
author of iParts 228
Autodesk Inventor COM API 30
AutoDesk Inventor functions 169
Autodesk Inventor Programming in C++ basic architecture of the source code 23
Autodesk Inventor Programming in C++ how to use this book 15
Autodesk Inventor programming, COM and Smart Pointers 30
Autodesk inventor version programatically in C++ 67
autofade on and off 289
Axes (standard X Y Z( 99
Axis (X Y Z standard) 99
Axis And Flush Mate Constraint Example 265 axis constraints 265
Axis Thru Circular Hole 267

Add in the occurrence of a custom iPart into an assembly 134


add named sketch to named workplane
programatically 172
Add views to an IDW 76
Add vs MethodAdd 144
AddAsTwoPointRectangle 209
AddBaseView 76
AddByCenterRadius 189
AddByCenterRadius example 168
AddByPlaneAndOffset 176
AddCircleToSketch 189
AddCustomiPartMember tips and hints and help 133
AddCustomiPartMember, how to use it in C++ 134 AddFlushConstraint 184
AddFlushConstraint in Autodesk Inventor C++ Programming 181
AddForSolid and profiles and AutoDesk Inventor Programming in C++ 200
AddForSolid example 168
addin dll 187
AddIn file 180
addin loading 187
AddIn Manager 207
AddIn, Autodesk Inventor Programming in C++ 17 adding a button 220
Adding a Dimension in a sketch 255
AddiPartMember 128
AddiPartMember and rotation 112
AddMateConstraint 91
AddMateConstraintOfTwoPlanes 91
AddSketchToWorkplane Autodesk Inventor Programming in C++ 172
adequate constraint in sketch 282
administrator for regsvr32 in Inventor Programming

46
angle (Inventor Programming) 101
angular dimension, how to add manually 252 angular units and Autodesk Inventor Programming 101
application invisible 112
application options 283
Application Options Settings 289
application visible 112
Apprentice Server 286
array of double values as an array for Inventor 73 array of features 235
- B
background of Inventor screen options 267

Backup files 280


Backup options for Inventor files 280 Base View 242
BaseView 76
boolean values in COM 153
boolean VARIANT_BOOL 153 Browser visibility 267
Browser is missing! Get it back! 267 browser pain on and off 288
BSpline Surface 217
BSTR and ::SysFreeString 199 BSTR OLECHAR wchar_t 199 BSTR vs CComBSTR 199
button 220
button definition 220
- C
C# 201
C++ 201
C++ code for AutoDesk Inventor Book 19 C++ from VBA 169
C1083 in Inventor Programming 47
C1083: Cannot open type library file: 'RxInventor.tlb': No such file or directory 208
C1189 error in Inventor Programming 46 C2064: term does not evaluate to a function taking 0 arguments 49
C2774 compile error in Inventor programming 50 C4278 Autodesk Inventor Programming 50 cannot add feature to existing
pattern 245 carriage return inside table cells 73
cast to get part document 84
cast to IDispatch**, in Autodesk Inventor
Programming 118
Casting from a ComponentDefinition to a
PartComponentDefinition. 127
category of material 224
CComBSTR and wchar_t in the Autodesk Inventor API 130
CComBSTR cast in Add function call 123 CComBSTR in AutoDesk Inventor Programming 123
CComBSTR vs BSTR in Inventor programming 199
CComPtr and how to release them in Inventor programming 145
CComPtr vs CComQIPtr 212
CComPtr<Parameter> 153

CComPtr<Point> Autodesk Inventor Programming 110


CComPtr<Point2d> Autodesk Inventor Programming

110
CComQIPtr and QueryInterface 68
CComQIPtr and Release 69
CComQIPtr is better than QueryInterface 69 CComQIPtr vs CComPtr and AutoDesk Inventor Programming in C++ 212
CComStr and programming Autodesk's Inventor 199
CComVariant and VARIANT 212
cells in tables in IDW drawings 71
center point for hole 258
CenterPoints and Points 170
Chamfer 284
change a model or user parameter programatically 154
change document filename when saving Inventor documents 131
change filename of object in the Autodesk Inventor API 131
Change material / color of a solid 274
change name of workplane programatically 176 change parameter name 253
change the default units 254
Change the offset elevation of a plane 246 Changing from iPart back to normal part 234 Changing home view setting 279
Changing manipulator snap 288
Changing the application visibility in Autodesk Inventor Programming 112
changing the name of a drivng dimension 255 circle, add to a sketch 189
Circular Hole With Work Axis 267
ClassId in the .AddIn file 180
Client Graphics and AutoDesk Inventor Programming in C++ 215
ClientId in the .AddIn file 180
Close (SkipSave) Inventor API 132
Close and SaveAs Autodesk Inventor API C++ 132
Close function, Inventor API 132
Close of a part programatically 83
Close of an assembly programatically 83 Close with SkipSave 83
CLSIDFromProgID failure 49
CLSIDFromProgID in Autodesk Inventor
Programming in C++ 215
constraint (flush) in Autodesk Inventor C++ Programming 181
constraint (Insert) does not work 272
Constraint deletion 258
constraint example (Inventor programming) 212 Constraint removal 258
Constraint, EntityOne, EntityTwo 124
constraint, programming 91
Constraints - Hierarchy in Autodesk Inventor Programming in C++ 215
Constraints and parts from a programmer's point of view 185
constraints and proxies 124
constraints and proxies (planes) Autodesk Inventor Programming 91
constraints between parts in an assembly 129 constraints in an asselmbly, listing them 97 constraints in sketches 282
constraints, WorkPlane and FlipNormal 244 contact set 276
contacts for Inventor Programming in C++ 13 contacts for Programming Inventor in C++ 13 convert from Document to
AssemblyDocument 216
convert from general to drawing document 75 convert from IDispatchPtr to something else, if possible 66
convert generic document to partdocument 190 CopyFile warning, Autodesk Inventor Programming

cm inches (Inventor Programming) 101


cm parameters 161
CoInitialize and AutoDesk Inventor Programming in C++ 100
COleSafeArray VARIANT arrays of strings 134 collections, getting items from them 213
color and material of a solid 274
colors of Inventor screen options 267
COM and AutoDesk Inventor Programming 100 COM API and pointers and memory in Autodesk Inventor Programming in
C++ 145
COM arrays 74
COM DLL registering 206
Com error 80070057 115
COM errors in Autodesk Inventor 89
COM errors, and Autodesk Inventor Programming 95
COM Function calls in Autodesk Inventor C++ programming 144
COM macros in Inventor C++ programming 89 COM ParameterPtr 153
COM points matrices vectors Autodesk Inventor Programming 110
COM return values 95
COM RxInventor 208
compiling with MFC dialog (for Autodesk Inventor) 50
complete constraint in sketch 282
Completely and adequately constrained sketches 282
component definition and occurrences 135 Component definition, definition of, Inventor Programming in C++ 173
ComponentOccurence - Hierarchy 215
ComponentOccurence and
ReferencedFileDescriptor 121
ComponentOccurencesList - Hierarchy 215 ComponentOccurrenceByName 121
ComponentOccurrences when creating an assembly

202
Compute or Suppress 234
ComVariant, CComVariant 212
concentric circle extrusion 257
Cone Surface 217
ConnectToInventor, running Inventor
programatically, Autodesk Inventor Programming in C++ 28
constrain command 263
Constrain icon in Inventor 258

50
CoUninitialize and AutoDesk Inventor Programming in C++ 100
CoUninitialize() and COM pointers 145
Count error C2064 49
Counting the number of documents open in Inventor
69
crash when inserting a drawing 239
create a 2d point (transient geometry) 110 create a drawing from a part or assembly 242 create a hole extruding 106
create a new document 202
Create a proxy geometry from an occurrence and a workplane 118
Create a rectangular pattern programatically 149 Create a sketch by default on creating a new part 280
create a sketch programatically example 30 Create an array of objects programatically (Inventor C++ programming) 149

Create Extruded Feature: problems encountered while executing this command. 237
Create iPart 227, 228
create new assembly document 216
CreateDoubleVariantArray, Autodesk Inventor C++ COM API 73
CreateExtrudeDefinition 167
CreateExtrudeDefinition and AddForSolid 200 CreateExtrudeDefinition example 168
CreateMatrix 216
CreateNewPartDoc Autodesk Inventor Programming

104
CreateObjectCollection and AutoDesk Inventor Programming in C++ 199
CreateObjectCollection in the Inventor API 103 CreateOneDim VARIANT arrays of strings 134 CreatePoint in Autodesk
Inventor Programming 110
CreatePoint2d 209
CreatePoint2D in Autodesk Inventor Programming 110
CreateSafeStringArray 74
Creating a big tube with holes in it 258
Creating a new Part Document Autodesk Inventor Programming 104
Creating a workplane offset from another plane 264
Creating an Assembly programatically 202 Creating projected views from base views using the Inventor API 80
CSafeArray 74
CSafeArray and IDW and CustomTable 71 CSLID and AutoDesk Inventor Programming in C++

215
CString 30
current display driver stops responding error message 239
custom iPart 227
custom ipart programatically 134
custom iParts programatically 133
Custom iParts, changing parameters 232 Custom iParts, how to make and use them 229 custom table, multiple lines in cells 73
customize the menu 278
CustomTables in Sheets and Drawings 71 cut extrusion 247
Cylinder Surface 217
- D
database blah blah .ipt could not be saved 250 DEF file 206
Default Parameter Input Display 253
default project templates 280
default projects folder 289
default sketch 280
default sketch plane 280
default units (mm or inch) 254
default variant 212
default workplanes 287
Default workplanes and sketches programatically 190
degrees and radians and Autodesk Inventor Programming 101
degrees and radians SetToRotation 112 delete a parameter 243
DeleteFile warning, Autodesk Inventor Programming

50
Deleting a constraint 258
Description in .AddIn file 207
Description in the .AddIn file 180
descriptions of objects 64
DestroyInventorGlobals and MakeInventorGlobals 26
detail drawing 241
DeveloperTools.Msi 201
diameter as a driven dimension 268
diameter parameter 282
Difference between CComPtr and CComQIPtr? 212
Difference between model parameters and user parameters 278
DIID_PartDocument 84
dimension editing 253
dimension in a sketch 255
dimension name getting 66
dimension selection to show 59
dimension types 66
DimensionConstraint 69
dimensions as user parameters 278
dimensions in a drawing sheet 63
dimensions needed. 282
dimensions, dirven 268
Dimensions, Retrievable 54
Dimensions, Showing temporarily 279
dwg 241, 242
dwg object 84
DWG, create a new one 75

directory for tlb files 208


Disable and Enable parts and assemblies 281 disabling user save 98
displaying expressions in a sketch 277
DisplayName 207
DisplayName in Autodesk Inventor C++
Programming 179
DisplayName in the .AddIn file 180
dll addin 187
DllCanUnloadNow 206
DllRegisterServer 206
DllUnregisterServer. 206
Document getting 84, 178
document name getting and setting 179 Document opening in Autodesk Inventor
Programming in C++ 144
document settings 289
document types 84
document types in Inventor 84
DocumentDescriptor, referenced document 53 Documents opening 144
documents programatically 144
DocumentType 84
DoModal and Inventor COM programming Autodesk Inventor Programming in C++ 19
double array, as a VARIANT 73
double parameters (ParameterTypeEnum) 161 double variant 212
drawing dimensions 59
drawing object 84
drawing object, create a new one 75
drawing of assembly 242
drawing of part 242
drawing page sheet size 86
drawing sheet addition 86
drawing view styles 83
DrawingDimensions 63
DrawingDocument creation 75
drawings, views, sheets, Inventor C++ API 76 DrawingSheetSizeEnum 86
DrawingView names 80
DrawingViewStyleEnum 83
DrawingViewStyleEnum , Inventor API 76 DrawingViewStyleEnum AddBaseView 76 driven dimension diameter example 268
driven dimension removal 268
driven dimensions, what are they? 268
driving dimensions 278
- E
E_ABORT Operation aborted (Autodesk Inventor) 89
E_ACCESSDENIED (Autodesk Inventor) 89 E_FAIL Unspecified error (Autodesk Inventor) 89 E_FAIL COM macro and
Autodesk Inventor Programming 89
E_HANDLE invalid handle (Autodesk Inventor) 89 E_INVALIDARG (Autodesk Inventor) 89
E_NOINTERFACE (Autodesk Inventor) 89 E_NOTIMPL (Autodesk Inventor) 89
E_OUTOFMEMORY (Autodesk Inventor) 89 E_POINTER invalid pointer (Autodesk Inventor) 89
E_UNEXPECTED (Autodesk Inventor) 89 EdgeProxy and occurrence 162
edit sketch 283
edit the offset of a workplane 246
Editing a sketch flatly 281
editing dimensions 253
Editing Model Parameters and how they are displayed 253
email address for Inventor Programming in C++ 13 email address for Programming Inventor in C++ 13 empty variant 212
Enable and Disable parts and assemblies 281 enable contact set 276
enabling user save 98
EntityOne and EntityTwo in a constraint 124 enum in GetTemplateFile 171
enum values and rxinventor.tlh 64
enum values of ObjectTypeEnum 64
enumerator for sheet sizes, DrawingSheetSizeEnum

86
enumerators for extrusion 106
erase a parameter 243
error 80004005 when saving Inventor documents 131
Error C1083 in Inventor Programming 47 error C2064: term does not evaluate to a function taking 0 arguments, Autodesk
Inventor Programming

49
error MSB3075: The command "regsvr32 /s /c in Inventor Programming 46
error strings and codes from COM in Autodesk Inventor 89
error when compiling in Autodesk Inventor Programming 46, 47, 49, 50
ErrorManager for Autodesk Inventor Programming

95
errors and reporting them and Autodesk Inventor Programming 95
errors in COM (Autodesk Inventor) 89
Example C++ code shows how to create a
CustomTable in an IDW Inventor drawing 71 exception throwing in Autodesk Inventor
Programming in C++ 144
EXE file, Autodesk Inventor Programming in C++ 17
export WorkFeatures from iParts into Assemblies 115
expression display 277
expressions in a sketch 277
extrude programatically 168
ExtrudeDefinition in Autodesk Inventor Programming in C++ 167
ExtrudeSketch in Autodesk Inventor 36
extruding programatically 200
extruding programatically (AutoDesk Inventor Programming) 106
Extruding sketches with multiple concentric circles 257
Extruding with widening angles 283
extrusion angle 283
extrusion cutting 247
extrusion of circles 257
extrusion problems 237
extrusion programatically (AutoDesk Inventor Programming) 106
extrusion to remove material 247
extrusions and profiles (Inventor Programming) 106
extrusions programatically in Autodesk Inventor Programming in C++ 168
- F
Face 217
Face - Hierarchy 215 Face Edge EdgeProxy 162 face enumeration 217

face getting 217


face normal viewing 279
face viewing along normal 279
FaceShell 217
FacesList - Hierarchy 215
factory, listing members 125
FactoryFile 133
FAIL return value for HRESULT codes (E_FAIL) 95
FAILED COM macro and Autodesk Inventor Programming 89
FALSE VARIANT_BOOL 153
feature arrays 235
feature patterns 235
Feature Suppression of features programatically 140
FeaturePatternElements 140
FeaturePatternElements, suppression of 142 Features and Sketches 285
file locations programatically 204
File manager (Inventor programming) 171 file types 241
FileManager and AutoDesk Inventor Programming in C++ 216
filename in the Autodesk Inventor API 131 Filename of referenced doc 238
filename, directory name, or volume label syntax is incorrect. 250
files for Autodesk Inventor Programming in C++ book 19
Fillet and Trim 284
FindDrawingViewInSheetByName 96
finish sketch 283
fit to view 279
flat sketch editing 281
FlipNormal and WorkPlane constraints 244 floating point parameters (ParameterTypeEnum) 161
Flush constraint 181
Flush Mate And Axis Constraint Example 265 formulas 278
FullDocumentName 238
FullDocumentName changing 50
FullFileName in the Autodesk Inventor API 131 Fully Contrained sketches 282
Function calls in Autodesk Inventor C++
programming 144
functions in AutoDesk Inventor 169
fx: 278
- G
general dimensions 59
geometric proxies in Autodesk Inventor C++ Programming 184
get a named object in Autodesk Inventor
Programming in C++ 157
get a named workplane 172
get a view from a sheet 96
Get and Set the name of an Inventor document 179
get list of sketches 172
get list of workplanes 172
get name of dimension 66
get name of parameter 66
get number of occurences 135
Get or get_ differences 211
get sketch by index 187
get sketch by name 187
get the name of a sketch programatically 190 Get the part document from the document 84 get_ or Get differences and
AutoDesk Inventor Programming in C++ 211
get_... function return values, and Autodesk Inventor Programming 95
get_ActiveDocument 84
get_ActiveDocument in Autodesk Inventor Programming in C++ 178
get_ComponentDefinition and parameters 137 get_ComponentDefinition example 135
get_Constraints for a Mate constraint 91 get_Constraints from an
AssemblyComponentDefinition 173
get_Count example 121
get_Count for documents 69
get_Count of dimensions 63
get_DisplayName 179
get_FileManager 216
get_FileManager for creating documents 75 get_FullDocumentName 238
get_item 217
get_Item and IDispatch**, in Autodesk Inventor Programming 118
get_Item by name 157
get_Item examples in Autodesk Inventor
Programming in C++ 213

get_Item for views 213


get_Item for views in a sheet 96
get_Item in for loops 212
get_Item parameter type in AutoDesk Inventor Programming 139
get_Item to access objects in an Inventor object list

213
get_Item vs GetItem 144
get_Item vs Item in Autodesk Inventor Programming

139
get_Name and BSTR and CComBSTR 199 get_Name of occurence 135
get_Name of view 80
get_Occurrences example 135
get_Profiles 201
get_ReferencedDocumentDescriptor 53 get_Sketches (Planar) 172
get_SketchPoints 209
get_SubOccurrences 130, 135
get_SurfaceBodies 163
get_SurfaceType 217
get_TransientObjects Autodesk Inventor
Programming 103
get_Value double example 142
get_Version 67
get_Workplanes 129, 172
get_XCount 153
get_XCount from a RectangularPatternFeature 119
get_YCount from a RectangularPatternFeature 119
get_YCount in Autodesk Inventor Programming in C++ 153
GetActiveObject failure Autodesk Inventor
Programming 46
GetComponentOccurrenceByName 121 GetCount for documents 69
GetInvAppPtr 26
GetInventorDocTypeDesc 84
GetItem vs get_Item 144
GetObjTypeDesc 64
GetRetrievableDimensions and picking one of them

59
GetSketchByName 157
GetStdWorkAxisByIndex 99
GetTemplateFile (Inventor programming) 171 getting data about a RectangularPatternFeature 119
Getting hold of the surfaces and faces of a solid object 217
Getting into and out of sketches 283
Getting normal part back from iPart with table 234 getting objects by name 157
Getting or running an Inventor Instance 215 Getting the document in Autodesk Inventor C++ Programming 84
getting the document type 84
Getting the version of AutoDesk Inventor
programatically 67
Getting the version of Inventor programatically 67 Getting the workplanes of a part occurrence in an assembly 129
Getting to the constrain icon in Inventor 258 GetTransGeomPtr 26
GetTransientObjectsPtr 26
getType and ObjectTypeEnum in Autodesk Inventor Programming 64
GetValue() of a Parameter 153
GetWorkAxisByIndex 99
GetWorkAxisByName 157
GetWorkPlaneByName 157
GetWorkPointByName 157
global pointers for useful objects 26
graphics crash 239
Green and Yellow Dot Constraints 282
Grounded Parts 288
GUI 267
GUID for Sheetmetal and Weldment 171
- H
Hidden in the .AddIn file 180
Hierarchy of objects and AutoDesk Inventor Programming in C++ 215
hole making from a center point 258
HoleCenter programatically 170
holes in a tube 258
holes, making them with extrusions 106 hollow tube making manually 278
home view setting customization 279
How to add a RectangularPattern to a
PartComponentDefinition. 149
How to add views to a drawing sheet (Inventor API)

76
How to change colors of the Inventor screen 267

How to change the background of the Inventor screen 267


how to count the number of occurences in an Inventor part 181
how to extrude a sketch (Inventor Programming) 106
how to get the name of a component occurrence 121
How to get the parameters of an assembly 137 How to get the RectangularPatterns in a
PartComponentDefinition 159
How to get the value of a user parameter in Autodesk Inventor C++ Programming 142 how to list constraints in an Inventor
assembly programatically 97
how to loop over the constraints in a part document

213
How to make a hollow tube manually 278 how to make an iPart 227
How to move a 3D object 276
How to start the contrain command 263
how to use get_Item to access objects in an Inventor object array 213
how to use get_Item with a string name in Autodesk Inventor Programming in C++ 213
how to use get_Item with an integer index 213 HRESULT codes in AutoDesk Inventor COM programming 89
HRESULT in high level and low level function calls

144
- I
iam 241
icon sizes 220
icons 220
icons, marking 278
ide 241
IDispatch, casting to, in Autodesk Inventor Programming 118
IDispatchPtr to DimensionConstraint conversion 66
idw 241, 242
IDW and CustomTable 71
IDW Views and Sheets programming 96 IDW, create a new one 75
iFeature file .ide 241
iLogic 277
inch and mm 254
iPartMember programming 128
iParts (custom, how to make and use them) 229 iParts and Assemblies and WorkFeatures 115 iParts and WorkFeatures 115
iParts and WorkPlane, WorkPoint, WorkAxis 115 iParts general info 227
iPartTableCell and iPartTableRow 125
iPartTableRow and iPartTableCell 125
ipj 240, 241
ipn 241
ipt 241
Item parameter type 139
Item vs get_Item in Autodesk Inventor Programming

inches , but I want mm 280


inches feet (Inventor Programming) 101 inclined workplane creation 273
include files in Inventor Programming 47 include SafeArrayUtil.h 71
including WorkFeatures for iparts 115
Insert constraint does not worl 272
insert, Autodesk Inventor Programming in C++ 135
inserting a part into an assembly 42
Inserting an inclined workplane 273
Installing the SDK 201
integer variant 212
interference 276
internal name of material 224
internal units of Autodesk Inventor Programming 101
Interrogating rectangular patterns in Autodesk Inventor Programming 119
Invalid parameters in COM call, and Autodesk Inventor Programming 95
Inventor Apprentice 286
Inventor COM error reporting 95
Inventor document types 84
Inventor documents programatically 144 Inventor errors and reporting them 95
Inventor part opening programatically API 51 Inventor Programming in C++ introduction 13 Inventor Project Wizard 50
Inventor Projects 240
Inventor warnings 95
Inventor.Application 215
Inventor.exe instance 215
InventorUtils.h and stdafx.h 47
invisibility of a part or assembly 82
invisible 281
invisible Inventor app 112
invisible opening of parts and assemblies 76 iPart 241
iPart - standard vs custom 227
iPart author 228
iPart Author to make custom iParts 229 iPart Author, suppression of features 234 iPart creation 227
iPart insertion problems 250
iPart Member 227
iPart Member and PartNumber 228
iPartFactory listing the members 125

139
- K
kA3DrawingSheetSize drawing page sheet size 86 kA4DrawingSheetSize drawing page sheet size 86 kADrawingSheetSize
drawing page sheet size 86 kAssemblyDocumentObject 64, 84, 202
kBackViewOrientation 76
kBDrawingSheetSize drawing page sheet size 86 kBottomViewOrientation 76
kBottomViewOrientation in sheets 76
kBSplineSurface 217
kCDrawingSheetSize drawing page sheet size 86 kComponentOccurrenceObject in Autodesk Inventor Programming 64
kConeSurface 217
kCurrentViewOrientation 76
kCustomDrawingSheetSize drawing page sheet size

86
kCylinderSurface 217
kDefaultPageOrientation drawing page orientation 86
kDefaultSystemOfMeasure 171
kDerivedParameter : Parameters automatically created from derived component. 161
kDesignElementDocumentObject 84
kDrawingDocumentObject creating one 75 kEnglishSystemOfMeasure 171
kFeaturePatternElementObject 64
kForeignModelDocumentObject 84
kFrontViewOrientation 76
kg mass Inventor Programming 101
kHiddenLineDrawingViewStyle 83
kHiddenLineDrawingViewStyle, , Inventor API 76 kHiddenLineRemovedDrawingViewStyle 83 kLandscapePageOrientation
drawing page orientation 86
kLeftViewOrientation 76
kMetricSystemOfMeasure 171
kModelParameter : Parameter created automatically by Inventor when a command requires it. 161 kModelParameterObject
64
kObjectCollectionObject 64
kPartComponentDefinitionObject 64
kPartDocumentObject 84
kPlaneSurface 217
kPortraitPageOrientation drawing page orientation 86
kPresentationDocumentObject 84
kReferenceParameter : Parameter created automatically by Inventor while creating a driven dimension, for example. 161
kRightViewOrientation 76
kRightViewOrientation in sheets 76
kSATFileDocumentObject 84
kShadedDrawingViewStyle, Inventor API 76 kSphereSurface 217
kTableParameter : Parameters created from a table; like a spreadsheet. 161
kTopViewOrientation 76
kTorusSurface 217
kUnknownDocumentObject 84
kUserParameter : Parameters explicitly created by the user. 161
kWorkAxisObject 117
kWorkPlaneObject 64, 117
kWorkPointObject 64, 117
kWorkPointProxyObject 64
- L
length (Inventor Programming) 101
library of components 240
Line, getting from an object 114
list occurences inside an assembly 135 list of constraints 213
list of constraints in an assembly programatically 97
list of Inventor objects and get_Item 213 list of workplanes 176
Listing constraints in an assembly programatically 124

Listing members in an iPartFactory programatically 125


Listing types of dimensions in a view 66
loading the addin DLL in Autodesk Inventor C++
Programming 187
look at command 281
loop of edges 256, 272
loop over assets 224
loop over materials 224
loop over open documents 69
loop over views in a sheet 96
- M
maetrial name 224
Major version 67
make a hole extruding 106
MakeInventorGlobals and DestroyInventorGlobals,

Autodesk Inventor Programming in C++ 26 making a tube with holes in it 258


making an iPart 227
manipulator snap 288
marking menu 278
mass kg (Inventor Programming) 101
Mate constraint with two planes programatically 91 material and color of a solid 274
material category 224
material display name 224
material internal name 224
material looping 224
materials API 223
materials editor 223
Matrix and Vector 102
matrix for rotation 112
matrix in Autodesk Inventor Programming in C++ 216
matrix point vector in Autodesk Inventor
Programming 110
measurement units 171
Member and PartNumber in iParts 228
member name of an iPartFactory programatically 125
menu customization 278
menu, marking 278
metal concrete wood 224
MethodAdd vs Add 144
MFC compiling for Autodesk Inventor Programming

50
minibar autofade option 289
Minor version 67
mirrored parts suppressed 237
MK_E_UNAVAILABLE 0x800401e3 Autodesk Inventor Programming 46
mm and inch 254
mm cm (Inventor Programming) 101
mm instead of inches 280
mm parameters in Autodesk Inventor Programming in C++ 161
Model and User parameters programatically in Autodesk Inventor Programming in C++ 154 Model Parameter Change 253
Model Parameter Display 253
Model Parameter Type 64
model parameters 227
model parameters vs user parameters. 278 mouse gestures 278
Move a 3D object 276
MoveFile warning, Autodesk Inventor Programming

50
moving a workplane 264
MSB3073 error 219
MSB3075 in Inventor Programming 46
multi user 286
Multiple Document Viewing in Inventor 275 multiple lines within table cells 73
- N
name of an Inventor sketch programatically 194 name of an occurrence 121
Name of document, getting and setting 179 name of DrawingView 80
name of occurrence 135
name of view 80
named objects, getting them 157
names and sketch objects 145
Names of objects inside sketches in Autodesk Inventor Programming in C++ 145
names of parameters which control dimensions 66 naming model parameters 278
new assembly and new document (creation of) 202
new document and new assembly (creation of) 202
new drawing document 75
new DWG document 75

new features and old patterns 245


new IDW document 75
New line within table cells 73
new views in a sheet 76
No visible unadaptive sketches 277
normal face viewing 279
normal of a plane 91
NULL return values , and Autodesk Inventor Programming 95
number of documents open in Inventor (C++) 69
- O
object descripion getting function 64
Object Hierarchy 215
object types 64
ObjectCollection 199
ObjectCollection Autodesk Inventor Programming 103
ObjectCollections in the Inventor API 103 ObjectsEnumerator and Patterns 160
ObjectsEnumerator, a list of objects in Autodesk Inventor Programming in C++ 161
ObjectTypeEnum and getType 64
Occurences as Xrefs 198
Occurences, Autodesk Inventor Programming in C++ 135
occurrence adding 123
Occurrence and EdgeProxy 162
occurrences and component definitions 135 occurrences and iPart members 128
occurrences and PartComponentDefinition of them 127
occurrences assemblies custom iparts
programatically 134
occurrences, sub, in Autodesk Inventor C++ programming 130
occurrences, workplanes, parts, assemblies 129 offset from plane command 264
offset of a plane 246
Offsetting a workplane 264
Old Versions To Keep 280
OldVersions directory of backups 280
OLECHAR BSTR wchar_t 199
OnExecute of a button 220
open a part from a view 238
open a document programatically 144
Open a part and change its parameters Autodesk Inventor Programming in C++ 39
open an assembly or part invisibly 82
Open an assembly programatically 75
Open an Inventor assembly programatically 75 Open an Inventor part programatically 51 open invisible 76
OpenPart API for Inventor 51
OpenPart function 39
Optional parameters and empty COM values in Autodesk Inventor Programming in C++ 169 options programatically 204
Options Settings 289
options, sketch plane, part tab 283
Orientation of a sheet on a page 86
overwriting existing Inventor files with SaveAs in the Autodesk Inventor API 130
- P
parallel workplanes 176, 264
parameter adding 268
parameter changing in Autodesk Inventor
Programming in C++ 39
parameter deletion 243
parameter diameter 282
parameter erasure 243
parameter export from a part 102
parameter getting programatically 137
parameter name changing 253
Parameter Type 64
parameter types (ParameterTypeEnum) in Autodesk Inventor Programming in C++ 161
Parameter units 161
parameter visibility at a higher level 102 ParameterPtr in COM for Inventor 153
parameters 278
parameters API 137
parameters for driven dimensions 268
parameters in a custom iPart programatically 134 Parameters in Inventor programatically 154 parameters invalid in COM call,
and Autodesk Inventor Programming 95
parameters, getting the value programatically 142 part .ipt 241
Part Close programatically 83
Part containing sketches in Autodesk Inventor C++ Programming 187

Part Document creation 104


part document from the document 84
Part document opening API 51
part document pointer from a document pointer. 179
part file opening 39
part files 241
part position 102
PartComponentDefinition and occurrences 127 PartComponentDefinition and PartDocument open the file 51
PartComponentDefinition and RectangularPatterns

159
PartComponentDefinition and Sketches 187 PartComponentDefinition from an occurrence 127 PartDocument and
PartComponentDefinition 173, 187
PartDocument and PartComponentDefinition open the file 51
PartDocument creation programatically 104 PartFeatureExtentDirectionEnum 106
PartFeatureOperationEnum 106
PartNumber and Member in iParts 228
Parts and Constraints from a programmer's point of view in Autodesk Inventor C++ Programming 185 parts and views 238
path for tlb files 208
path to RxInventor.tlb 208
pattern (how ro add a feature to an existing pattern)

245
Pattern Feature Suppression of features
programatically 142
pattern making 235
pattern of features 235
Pattern programatically 149
PatternElements 140
PatternElements in the Inventor API

Autodesk Inventor Programming Pattern Elements 116


PatternElements, suppression of 142
pDocuments->Add 76
placed features 284
Placing a work axis 267
placing parts in space 102
PlanarSketch 106
PlanarSketch (adding to workplane) 172 Plane on the surface of a tube at an angle 251 plane position editing 246
Plane Surface 217
put_Visible 132

point 2d 3d in Autodesk Inventor Programming 110


point adding to tube manually. 244
point display 170
Point in center of a hole 256
point vector matrix in Autodesk Inventor
Programming 110
Points and CenterPoints in Autodesk Inventor Programming in C++ 170
points in a sketch 209
Position a 3D object 276
post build event step 219
printf BSTR 199
problems encountered while executing this command. 237
Problems encountered while saving the document. 250
Profile example (extrusion) 168
profile of two circles 258
profile, what is it? 201
profiles and AddForSolid 200
profiles and extrusions (Inventor Programming) 106
profiles and sketches 201
programatically add a rectangle to a sketch 209 programatically occurrences assemblies custom iparts 134
Programming Autodesk Inventor in C++ to add a circle to a sketch 30
Programming Autodesk Inventor in C++ to make a solid object 36
Programming Inventor in C++ introduction 13 project file 240, 241
project file programatically 204
Project files for the book, Autodesk Inventor Programming in C++ 21
project template default setting 280
projected views and base views 80
proxies and constraints (planes) Autodesk Inventor Programming 91
proxies in constraints 124
Proxies, why and what? in Autodesk Inventor Programming 92
Proxy in Autodesk Inventor Programming 92 put_FullFileName example in the Autodesk Inventor API, Save function 131
put_Name of view 80
put_Suppressed 140
put_Suppressed in patterns 142
- Q
QI QueryInterface 68
QueryInterface and Release Etc 68 QueryInterface example 66
QueryInterface(DIID_PartDocument 84
- R
radians and degrees and Autodesk Inventor Programming 101
radians and degrees SetToRotation 112 rectangle in sketch and AutoDesk Inventor Programming in C++ 209
rectangular pattern 235
Rectangular pattern programatically 149 rectangular patterns 159
RectangularPatternFeature, getting data about one

119
RectangularPatternFeature::Add function 149 RectangularPatterns and PartComponentDefinition

159
red and blue workplane sides 244
referenced doc filename 238
Referenced Document of a View 53
ReferencedDocumentDescriptor 53
ReferencedFileDescriptor and
ComponentOccurence 121
regen = Update 140
registering COM DLL 206
registration of Visual Studio Inventor Wizard failure

50
Registry Free AddIns 199, 206
Registry Free AddIns in Inventor Programming 46 regsvr32 206
regsvr32 in Inventor Programming 46
Remove table from an iPart 234
Removing a constraint 258
removing a driven dimension 268
Removing material with the cut extrusion command

247
rename warning, Autodesk Inventor Programming 50
ResultFeatures and Patterns in Autodesk Inventor Programming in C++ 160
ResultFeatures and workplanes, workpoints, worksurfaces 160
retrievable dimension showing 59
Retrievable Dimensions 54
return codes from COM (Autodesk Inventor) 89 ReturnAndShowCOMError 95
rgs file for Inventor AddIns, what is it? 199 ROT Running Object Table Autodesk Inventor Programming 46
rotate an object inserted as an occurrence in an assembly 112
rotate around the Z Axis 112
rotation around the X axis in Inventor programming

112
rotation around the Z axis in Inventor programming
112
rotation of objects programatically in AutoDesk Inventor 112
rotation with FlipNormal (constraints) 91 running Inventor 215
RxInventor.tlb and AutoDesk Inventor Programming in C++ 208
RxInventor.tlb path in Autodesk Inventor
Programming in C++ 208
RxInventor.tlh 208
rxinventor.tlh and enum values 64
RxInventor.tli 208
- S
S_FALSE com success macro and Autodesk Inventor Programming 89
S_OK and S_FALSE, and Autodesk Inventor Programming 95
S_OK com success macro and Autodesk Inventor Programming 89
SAFEARRAY 74
SAFEARRAY with CustomTables 71
SafeArrayUtil.h include 71
Samples (UserTools.msi) 201
save not working 98
Save programatically in the Autodesk Inventor API 131
SaveAs and Close Autodesk Inventor API C++ 132
SaveAs programatically in the Autodesk Inventor API

130
saving apparently disabled 98
Saving without dialogs 83

scale of view drawing 242


SDK Installing 201
set document filename when saving Inventor documents 131
Set the visibility of all workplanes in a part 178 SetEnvironmentVariable warning, Autodesk Inventor Programming 50
setting the visibility if Inventor 112
settings of the document 289
Settings Options 289
SetToRotation 112
SetTranslation 102
SetTranslation (pVector,VARIANT_TRUE) 102 Sheet Metal GUID 171
Sheet View Referenced Document 53
sheets, views, drawings, Inventor C++ API 76 Sheets.Add 86
shell getting 217
Show a dimension programatically 59
ShowCOMError and Autodesk Inventor Programming

95
Showing dimensions temporarily 279
showing expressions in a sketch 277
SilentOperation 98
SilentOperation and save dialogs 83
single user 286
sketc expressions 277
sketch and part 187
Sketch by name 157
Sketch constraints 282
sketch edit 283
sketch extrusion (Inventor Programming) 106 sketch finish 283
sketch name getting 194
sketch name programatically 190
sketch name setting 194
sketch plane 283
sketch plane default 280
sketch plane from 3 points 287
sketch, add a circle to it 189
sketch, exiting 283
sketch, getting into 283
SketchCircle, adding a circle to a sketch 189 SketchCircles in Autodesk Inventor C++
Programming 189
Sketches and Features in Inventor 285
sketches and names 145
sketches and parts 187
SysFreeString 199

sketches and profiles 201


sketches and workplanes programatically 190 Sketches in an Inventor Part 187
sketches programatically 168
SketchPoint in Autodesk Inventor Programming in C++ 209
SkipSave when Close in Inventor API 132 SkipSave when closing a document 83
smart pointers, COM and Autodesk Inventor programming 30
snap changing for 3D dragging 288
snap spacing 3D 288
snaps hard and soft 282
solid feature 2d sketch 285
solid material and color 274
solid object creation in the Inventor COM API,

Autodesk Inventor Programming in C++ 36 source code for AutoDesk Inventor Book 19 Sphere Surface 217
standard iPart 227
standard units in Inventor 101
standard work axis 99
stdafx.h and InventorUtils.h Autodesk Inventor Programming 47
strings in Inventor and OLE and COM 199 SubOccurrences 135
SubOccurrences in the Autodesk Inventor C++ API

130
suppress feature 140
suppress feature in a pattern in Autodesk Inventor Programming in C++ 142
Suppress or Compute 234
Suppressed boolean API 140
suppressed parts and mirrors thereof 237 Suppression of features in patterns programatically in Autodesk Inventor C++
Programming 142 Suppression of features parametrically using the iPart Author 234
Suppression of features programatically in Autodesk Inventor Programming 140
surface bodies 217
surface enumeration and AutoDesk Inventor Programming in C++ 217
SurfaceBodies and EdgeProxies 162
SurfaceBodiesList - Hierarchy 215
SurfaceBody - Hierarchy 215
SurfaceTypeEnum in Autodesk Inventor
Programming in C++ 217
switch on the browser pane 288
- T
table cells with multiple lines 73
table editing of custom iparts 232
table iparts 234
Tables in Sheets and Drawings 71
tangent to surface through point 251
temperature (Inventor Programming) 101 template file in Autodesk Inventor Programming in C++ 171
template files 248
TemplateFile 216
text tables in IDW files 71
The database blah blah .ipt could not be saved 250
The filename, directory name, or volume label syntax is incorrect. 250
The hierarchy is like this: 215
throw exceptions 144
time (Inventor Programming) 101
tips and tricks for Autodesk Inventor programming in C++ 44
tlb 208
tlh 208
Torus Surface 217
transient geometry 216
transient geometry and AutoDesk Inventor
Programming in C++ 102
transient geometry points and SketchPoint 209 TransientGeometry 102
TransientGeometry Autodesk Inventor Programming

110
TransientObjects in the Inventor API 103 translation 102
tricks and tips for Autodesk Inventor programming in C++ 44
Trim and Fillet 284
TRUE VARIANT_BOOL 153
tube hollow manually 278
type library 208
type of objects 64
types of dimension 66
types of parameters (ParameterTypeEnum) 161
- U
ul as a dimension 281
unadaptive sketches 277
UNICODE and ASCII 199
UNICODE, Autodesk Inventor Programming in C++

30
UNICODE, wchar_t and programming Inventor 199
unitless 281
units 254
units (internal) 101
units in a template file 171
units of parameters 161
units when programming Autodesk Inventor 101 units, inches or mm programatically 171 units, internal and use 42
UnitVector, getting an axis 114
Update a Part after a parameter change 154 User and Model parameters programatically 154 User Interface 267
user parameters as dimensions 278
user parameters, getting the value programatically 142
UserInterfaceVersion in .AddIn files for Inventor 211
UserParameters and ModelParameters 154
- V
variant (default) 212
variant (empty) 212
VARIANT and CComVariant and AutoDesk Inventor Programming in C++ 212
VARIANT arrays of strings 134
VARIANT which is an array of doubles 71 VARIANT, an array of double values for Inventor 73
VARIANT_BOOL Autodesk Inventor Programming in C++ 153
VARIANT_FALSE 153
VARIANT_TRUE 153
Vault 286
VB.NET 201
VBA 201
VBA to C++ 169
Vector and Matrix 102

Version of Inventor, getting it programatically 67 view assembly as a drawing 242


view face 279
view face normal 279
view from a sheet 96
view names 80
View orientation, Inventor API 76
View Referenced Document 53
view scale 242
View scale, Inventor API 76
view style 83
Viewing Multiple Documents in Inventor 275 ViewOrientationTypeEnum of views in sheets 76 views and parts 238
Views Sheets Drawings programatically 96 views, base 76
views, sheets, drawings, Inventor C++ API 76 visibility 281
visibility of a part or assembly 82
Visibility of all workplanes in a part 178 Visibility programatically 132
visible Inventor app 112
VT_I4 COM data type and AutoDesk Inventor Programming in C++ 198
- W
wchar_t 30
wchar_t and CComBSTR in the Autodesk Inventor API 130
wchar_t, UNICODE and programming Inventor 199
weld file 241
weldment file .iam 241
Weldment GUID 171
what are PatternElements in the Inventor API? 116
What sort of WorkFeature is this in Autodesk Inventor Programming? 117
where .AddIn files are placed 187
where sketches are stored in an Inventor Part 187 wide char 199
WinError.h and Autodesk Inventor 89
Wizard 201, 219
Wizard failed to register 50
wood concrete metal 224
Work Axis Thru Circular Hole 267
WorkAxes programatically 99
WorkAxis collection 99
WorkAxis programatically Autodesk Inventor Programming in C++ 99
workaxis visibility 178
WorkFeatures and iParts in Autodesk Inventor Programming 115
WorkFeatures, what type is this one? ( in Autodesk Inventor Programming) 117
WorkPlane and FlipNormal and constraints 244 workplane and sketch 287
workplane from 3 points 287
workplane inclination 273
workplane indices (standard) Inventor programming

190
workplane offset 264
workplane offset editing 246
workplane on surface of tube at an angle 251 workplane positioning 264
workplane visibility 178
workplane, adding programatically, Inventor. 176 WorkPlane, WorkPoint, WorkAxis and iParts 115 WorkPlaneProxy in
Autodesk Inventor Programming

92
workplanes (default) 287
Workplanes and sketches programatically 190 workplanes in parallel 264
workplanes, parts, assemblies, occurrences, programatically 129
WorkPoint by name 157
workpoint creation in Autodesk Inventor C++ Programming 192
workpoint from sketch point 192
WorkPoint in center of a hole 256
workpoint making 192
workpoint visibility 132, 178
WorkPoint WorkPlane WorkAxis, which is it? 117 WorlkPlane by name 157
wprintf BSTR 199
- X
X Axis programatically 157
X Axis programatically by index 99
x64 219
XCount and YCount of patterns 119
XData in Inventor programming in Autodesk Inventor Programming in C++ 163

Xrefs as Occurences and AutoDesk Inventor Programming in C++ 198


xy plane 258
- Y
Y Axis programatically 157
Y Axis programatically by index 99
Yellow Dot Green Dot Constraints 282
yz plane 258
YZ Plane in Autodesk Inventor C++ Programming 176
- Z
Z Axis programatically 157
Z Axis programatically by index 99 Z Axis rotation 112

311

You might also like