Autodesk Inventor Programming in C++
Autodesk Inventor Programming in C++
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.
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
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
Part XVI Acknowledgements 291 Index 292 Autodesk Inventor Prog ramming in C++ 13
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.
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
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
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
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 () ;
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:
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:
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.
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.
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
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.
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:
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 () ;
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.
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
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
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.
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:
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
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.
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
"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.
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.
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:
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.
This funcion opens an Inventor part, and returns the PartDocument and the
PartComponentDefinition, both of which are usually useful to the caller.
pPartDoc = pDoc ;
if (pPartDoc == nullptr) {
return ReturnAndShowCOMError (hRes,L"OpenPart, failed to cast to PartDocument");
}
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:
{
CComPtr<DrawingDimensions> pDimensions = nullptr ; hRes = pSheet-
>get_DrawingDimensions (&pDimensions) ; if (FAILED(hRes)) {
long lNumDims;
hRes = pDimensions->get_Count(&lNumDims);
if (FAILED(hRes)) {
The full set of values can be found in rxinventor.tlh, which will be somewhere like:
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:
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.
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:
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.
(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...
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.
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:
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:
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
( :
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) ;
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:
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) ;
You'll see the two drawings in a single sheet in the browser like this:
// Catastrophic failure
//
#define E_UNEXPECTED _HRESULT_TYPEDEF_(0x8000FFFFL)
#if defined(_WIN32) && !defined(_MAC)
// Not implemented
#define E_NOTIMPL _HRESULT_TYPEDEF_(0x80004001L)
// 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)
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) ;
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.
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
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.
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).
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
}
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)) {
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.
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.
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:
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:
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:
CComVariant pSubDocType;
CComBSTR sTemplate;
HRESULT hr = pInventorApp->GetTemplateFile
return hr; }
CComPtr<Document> pDoc;
hr = pInventorApp->Documents->Add (kPartDocumentObject, sTemplate,
VARIANT_TRUE,
&pDoc);
if (hr != S_OK) {
return hr;
}
pPartDoc = CComQIPtr<PartDocument>(pDoc);
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))
{
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
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");
}
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");
}
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
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))
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
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:
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.
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:
} 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* :
CComPtr<WorkPlane> pWorkPlane ;
hRes = pSketches->Add (_variant_t((IDispatch*)pWorkPlane), VARIANT_FALSE,
&pNewSketch);
CComPtr<WorkPlane> pWorkPlane... ;
CComPtr<WorkPlane> pOffsetWorkPlane ;
hRes = pWorkPlanesList->AddByPlaneAndOffset (
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:
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)
{
pAssemblyDoc->get_ComponentDefinition(&pAssemblyCompDef); if (FAILED(hRes) ||
(pAssemblyCompDef == nullptr)){ return ReturnAndShowCOMError(hRes,L
"GetComponentOccurrenceByName, get_ComponentDefinition failed "); }
long lNoOccs;
hRes = pOccs->get_Count(&lNoOccs);
if (FAILED(hRes)) {
}
}
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:
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) {
iPartFactory" ,gkcsTroncFactory) ;
// This is NOT an iPartFactory
return ;
/*
* Get the iPartFactory from the component definition... */
"member"...
*/
CComPtr<iPartTableRows> piPartTableRows = nullptr ; piPartFactory->get_TableRows
(&piPartTableRows) ;
/*
* Loop over the members in the table, printing Member... */
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:
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:
pPosMatrix,
You can also specify directly the member to insert using the Member string:
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:
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:
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.
} else {
pWorkPoint->put_Visible (VARIANT_FALSE) ;
}
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.
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
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 ;
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:
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;
// It is a part component definition, so we can get the // parameters of the part definition
pParams = pPartCompDef->Parameters;
const long ikNumParams = pParams->Count ;
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.
Sometimes, if the item in the list has a text name, you can use the name in the call to get_Item.
For example:
(CComVariant(pszUserParamName),&pUserParam) ;
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) ;
(CComVariant(iFeat),&pFeature) ;
if (FAILED(hRes) || (pFeature == nullptr)) {
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.
} 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) ;
// 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:
(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)
// 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 :
...and...
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:
// 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);
(pTronHoleWp,"NAME_OF_WP",pPartCompDef) ;
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) ;
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:
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> XCountParam ;
pRectPatFeat->get_XCount (&XCountParam) ; const int ikXCount = XCountParam->GetValue
() ;
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:
CComPtr<ModelParameter> pModelParam ;
HRESULT hRes = pModelParameters->get_Item (CComVariant
(pszModelParamName),&pModelParam) ;
if (FAILED(hRes) || (pModelParam == nullptr)) {
return ReturnAndShowCOMError (hRes,L"ChangeDoubleModelParam, get_Item failed") ;
}
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.)
pPartCompDef)
{
// Get the sketch in the part by name...
HRESULT hRes =
pPartCompDef->Sketches->get_Item(CComVariant(pszSketchName), &pSketch);
return (S_OK) ; }
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) ; }
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) ;
}
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) {
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:
Apart from Model parameters and User parameters each parameter also has a type
ParameterTypeEnum which specifies who and why a parameter was created.
ParameterTypeEnum eParamType ;
pModelParam->get_ParameterType (&eParamType) ;
TRACE (L"The ParameterTypeEnum is %d\n",eParamType) ;
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:
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)) {
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:
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.
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);
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
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:
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...
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:
//
Get the list of workplanes in the part...
CComPtr<WorkPlanes> pWorkPlanesList ;
pPartCompDef->get_WorkPlanes (&pWorkPlanesList) ; if (FAILED(hRes) ||
(pWorkPlanesList == nullptr)) {
// 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) ;
// For fun, again, get the name of the new workplane... hRes = pOffsetWorkPlane->get_Name
(&bstrWrkplaneName) ; if (FAILED(hRes)) {
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)) {
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.
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"...
*/
/*
* 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... */
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);
// Get the list of constraints of the assembly so you can add a new one
CComPtr<AssemblyConstraints> pConstraintList = nullptr ;
hRes = pAssemblyCompDef->get_Constraints(&pConstraintList) ;
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.
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.
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.
They are inside a list which is itself inside a component definition. Programatically here is
how to get a sketch by name:
"MAIN_TUBE_CIRCS"), &pSketch);
if (FAILED(hRes)) {
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.
{
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;
templateFilename,
VARIANT_TRUE, // create visible
&pDocument); // return value if (FAILED(hr))
return hr;
(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;
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:
CComPtr<SketchPoints> pSkPoints;
pSketch->get_SketchPoints (&pSkPoints) ;
long iNumPoints ;
hRes = pSkPoints->get_Count (&iNumPoints) ;
if (FAILED(hRes) || (iNumPoints < 1)) {
CComPtr<SketchPoint> pSketchPoint ;
hRes = pSkPoints->get_Item (1,&pSketchPoint) ; if (FAILED(hRes) || (pSketchPoint ==
nullptr)) {
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
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).
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:
Next...
14.117VBA, VB.NET, C# or C++
VBA is only recommended for small macros.
// Get Profiles
CComPtr<Profiles> pSkProfiles;
hr = pSketch->get_Profiles(&pSkProfiles) ;
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:
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);
}
CComBSTR bstrCaption;
HRESULT Result = pInvApp->get_Caption(&bstrCaption); if (SUCCEEDED(Result))
CComBSTR bstrLanguage;
Result = pInvApp->get_LanguageName(&bstrLanguage); if (SUCCEEDED(Result))
CComBSTR bstrUserName;
Result = pInvApp->get_UserName(&bstrUserName); if (SUCCEEDED(Result))
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);
}
CComPtr<Document> pDoc;
Result = pInvApp->get_ActiveDocument(&pDoc);
if (FAILED(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:
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))
CComPtr<SketchPoint> pSpt2;
hr = pSkPoints->Add(pPt2,VARIANT_FALSE,&pSpt2); if (FAILED(hr))
// Get SketchLines
CComPtr<SketchLines> pSkLines;
hr = pSketch->get_SketchLines(&pSkLines);
if (FAILED(hr))
*)pSpt1),
_variant_t((IDispatch
*)pSpt2),
&pRectangleLines);
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.
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:
.
14.129VARIANT and CComVariant
CComVariant is a C++ encapsulation of VARIANT.
Another way of getting an item from a collection uses get_Item with an cast index:
}
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
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
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:
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.
"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...
m_inventorApplication.UserInterfaceManager;
// Get the "Part" ribbon, a list of tabs active when editing a part...
Inventor.Ribbon partRibbon;
partRibbon = ribbons["Part"];
// Inside the "Tools" tab there are many panels... RibbonPanels ribbonPanels;
ribbonPanels = partSketchRibbonTab.RibbonPanels;
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>.
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:
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...
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
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.
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.
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.
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.
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".
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.
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:
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.
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.
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.
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.
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.
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.
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.
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.
16 Acknowledgements
Thanks to, in alphabetical order (most , but not all, of these people work for AutoDesk):
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
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
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
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
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
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
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
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
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
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
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
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
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
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
311