Common Document Functionalities
Common Document Functionalities
Philippe Leefsma
Developer Technical Services
Autodesk 2012 1
Agenda
Documents Types
Working with Documents
Document Settings
iProperties
Lab: iProperties lab
Unit of Measure
Parameters
Lab: UOM lab
Autodesk 2012 2
Document Types
Unique document types for different types of data.
Part Documents (*.ipt)
Assembly Documents (*.iam)
Drawing Documents (*.idw)
Presentation Documents (*.ipn)
Autodesk 2012 3
Accessing Documents
Creating new documents
Documents.Add
Opening existing documents
Documents.Open
Accessing open documents
Documents.Item
(Enumerates all documents, including those
that have been opened because theyre
referenced by another document.)
Autodesk 2012 4
Templates
The GetTemplateFile method of the FileManager object
allows you to get the full path of any specified template.
GetTemplateFile(DocumentType As DocumentTypeEnum,
[SystemOfMeasure As SystemOfMeasureEnum = kDefaultSystemOfMeasure],
[DraftingStandard As DraftingStandardEnum = kDefault_DraftingStandard],
[DocumentSubType]) As String
Autodesk 2012 5
Opening and Creating Documents
'Opens an existing document
Public Sub OpenDoc()
End Sub
End Sub
End Sub
Autodesk 2012 6
Saving Documents
The first time a new document is saved you should use the
SaveAs method with the SaveCopyAs flag set to False.
Dim oDoc As PartDocument
oDoc = _InvApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject)
oDoc.SaveAs("C:\Temp\SaveTest.ipt", False)
For documents that have been saved to disk you can use the
Save method or the SaveAs with the SaveCopyAs flag set to
True.
oDoc.Save()
oDoc.SaveAs("C:\Temp\SaveTest2.ipt", True)
Autodesk 2012 7
Closing Documents
Document.Close([SkipSave As Boolean = False])
Using the SkipSave argument you can bypass the dialog asking to
save the changes and force the document to close without saving.
This is useful in cases where you use a file as a template by opening
the file, modifying it in some way, and using SaveCopyAs to save it
as a new file. Using this you can close the original without saving
and without forcing the user to interact with a dialog.
Autodesk 2012 8
Document Settings
Autodesk 2012 9
iProperties in the User Interface
iProperties are used to
associate information with a
document.
Property
Properties Methods
Dirty Delete
DisplayName
Autodesk 2012 11 Name
iProperties Property Set
The PropertySet object
contains a group of
properties.
Document
Properties
PropertySets
Most PropertySet objects PropertySets
FlushToFile
dialog. PropertySet
Properties Methods
Count Add
PropertySets
Properties Methods
Property
Properties Methods
Dirty Delete
DisplayName
Name
Parent
PropId
Type
Value
Autodesk 2012 13
iProperties
Property values are stored internally as Variants. The
following types are supported: Integer, Long, Double,
String, Date, and Boolean. (With the exception of the
thumbnail image which is IPictureDisp.)
Autodesk 2012 14
iProperty Names
Name and Internal Name of Inventor defined property
sets:
Autodesk 2012 15
iProperties Accessing Example
Public Sub iPropAccess()
' Access a particular property set. In this case the design tracking property set.
Dim oDTProps As PropertySet
oDTProps = oDoc.PropertySets.Item("{32853F0F-3444-11d1-9E93-0060B03C1CA6}")
' Access the same property set using the display name or name. DisplayName is not
' dependable because it can be localized, so the internal name or name is preferred.
oDTProps = oDoc.PropertySets.Item("Design Tracking Properties")
End Sub
Autodesk 2012 16
iProperties - Creation
Create new property sets.
PropertySets.Add(Name As String, [InternalName]) As PropertySet
Name and InternalName must be unique with respect to other property sets in
the document.
Autodesk 2012 17
iProperties - Saving
In Inventor, any changes made to properties are saved
when the document is saved.
Open a document
Dim oDoc As ApprenticeServerDocument
oDoc = oApprentice.Open("C:\Temp\Part.ipt")
change a property
Dimm oPropSet As PropertySet
oPropSet = oDoc.PropertySets("Design Tracking Properties")
Autodesk 2012 18
Lab: iProperties
Write a .Net program that performs the following steps:
Creates a new part document.
Edits the value of the author property to contain your name.
Creates a new custom (user-defined) property called Supplier
that contains the value Parts R Us.
Save the document to C:\Temp\NewPart.ipt
Close the document.
Autodesk 2012 19
Units of Measure
All Inventor documents use the
same internal units.
Length: Centimeters
Angle: Radians
Time: Second
Mass: Kilogram
Autodesk 2012 20
Units of Measure
Unique UnitsOfMeasure object is
obtained from each document and Application Document
from the Application object for UnitsOfMeasure UnitsOfMeasure
general unit conversion use.
UnitsOfMeasure
Properties Methods
UnitsOfMeasure object obtained AngleDisplayPrecision
AngleUnits
CompatibleUnits
ConvertUnits
from a document provides LengthDisplayPrecision GetDatabaseUnitsFromExpression
LengthUnits GetDrivingParameters
equivalent functionality as MassUnits
Parent
GetLocaleCorrectedExpression
GetPreciseStringFromValue
TimeUnits GetStringFromType
Document Settings command. Type GetStringFromValue
GetTypeFromString
GetValueFromExpression
IsExpressionValid
UnitsOfMeasure object provides
utilities to help with unit handling
within programs, primarily the
conversion between strings and
values.
Autodesk 2012 21
Units of Measure - Unit Types
Whenever a unit type is specified within the API, it can
be defined in two different ways:
Autodesk 2012 22
Units of Measure Internal Units
Internally, Inventor uses a consistent set of units
regardless of what the user has specified as the
document default
The precision is always double-precision floating point,
regardless of the precision specified by the user
Internal units used by Inventor for the various types of
units
Autodesk 2012 23
Units of Measure - Verifying User Input
Private m_oUOM As UnitsOfMeasure
End Sub
Autodesk 2012 24
Units of Measure - Using User Input
' Get the real value of the input string.
Dim dValue As Double
dValue = m_oUOM.GetValueFromExpression(txtInput.Text, _
UnitsTypeEnum.kDefaultDisplayLengthUnits)
Autodesk 2012 25
Units Of Measure - Displaying Values
Private Sub TestLength()
ShowLength(6.5)
End Sub
End Sub
Autodesk 2012 26
Component Definition
For part and assembly documents the
ComponentDefinition objects provide access to the
information that defines the part or assembly.
PartDocument AssemblyDocument
PartComponentDefintion AssemblyComponentDefintion
PartDocument AssemblyDocument
SheetMetalComponentDefintion WeldmentComponentDefintion
Autodesk 2012 27
Parameters - In the User Interface
Autodesk 2012 28
Parameters In the API
PartDocument AssemblyDocument
PartComponentDefinition AssemblyComponentDefinition
Parameters Parameters
Autodesk 2012 29
Parameters UI vs. API
Autodesk 2012 30
Parameters - Setting Values
Public Sub SetParameter()
' Get the Parameters object. Assumes a part or assembly document is active.
Dim oParameters As Parameters
oParameters = _InvApplication.ActiveDocument.ComponentDefinition.Parameters
End Sub
Autodesk 2012 31
Parameters - Units
The Unit property can be set
using either a String or a value
from UnitsTypeEnum.
The Value property sets the actual value of the parameter and
will overwrite any existing equation.
Autodesk 2012 33
Parameters - Tolerances Parameter
Autodesk 2012 34
Parameters Parameter Types
Parameters
The Parameters collection returns all
Parameter
Parameter objects regardless of the type.
Tolerance
ModelParameters
ReferenceParameters
ReferenceParameter
UserParameters
UserParameter
CustomParameterGroups
CustomParameterGroup
Autodesk 2012 35
Parameters Parameter Creation
Parameters are created by using methods on Parameters
the collection for the specific type of Parameter
parameter you want to create. Tolerance
ModelParameters
In
the user-interface you can only create user ModelParameter
parameters. All other types are indirectly ParameterTables
created as a result of other actions. ParameterTable
TableParameters
In
the API you can directly create user, TableParameter
CustomParameterGroups
Autodesk 2012 37
Parameters API Only Functionality
Creation of Model and Reference parameters.
Delete unused Model and Referenced Parameters.
DisabledActionTypes Prohibit deletion of user
parameters.
Dependents, DrivenBy Provides dependency information
between parameters.
Creation of custom parameter groups.
Change the type of a parameter.
Model to Reference
Reference to Model
User to Model
User to Reference
Autodesk 2012 38
Lab: Parameters and UOM
Interactively create a simple part that contains a
parameter named Length to control the size of the part.
Create a .Net program that contains a dialog that looks
similar to the one below.