Issue
I have created a derived part from a base part. I would like to programmatically modify the base part parameters that are included in the derived component. Is there a way to do this?
Solution
The Inventor API provides independent control over the base part parameters: The VBA and VB.NET example ModifDerivedParams only includes the parameter named d1 from the base component.
Before running these examples ensure a derived part document is the active document. Note the first two subs are VBA. Below this is a VB.NET example.
Public Sub ModifDerivedParams()
If ThisApplication.ActiveDocument.DocumentType <>
kPartDocumentObject Then
MsgBox("Make a Part Document the active document")
End
End If
Dim oDerPart As PartDocument
oDerPart = ThisApplication.ActiveDocument
Dim oDerPartComp As DerivedPartComponent
If oDerPart.ComponentDefinition.ReferenceComponents.
DerivedPartComponents.Count < 1 Then
MsgBox("No Derived Part Components in this part")
End
End If
oDerPartComp =
oDerPart.ComponentDefinition.
ReferenceComponents.DerivedPartComponents(1)
Dim oDerivedPartDef As DerivedPartUniformScaleDef
oDerivedPartDef = oDerPartComp.Definition
Dim oDerEntity As DerivedPartEntity
For Each oDerEntity In oDerivedPartDef.Parameters
If (oDerEntity.ReferencedEntity.Name = "d1") Then
oDerEntity.IncludeEntity = True
Exit For
End If
Next
'Set Definition back, so DerivedPart Document is updated
oDerPartComp.Definition = oDerivedPartDef
End Sub
This VB.NET code is from a button on a Form in a stand alone exe that connects to Inventor out of process.
Imports Inventor
Public Class Form1
Dim m_inventorApp As Inventor.Application = Nothing
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Try ' Try to get an active instance of Inventor
Try
m_inventorApp =
System.Runtime.InteropServices.
Marshal.GetActiveObject("Inventor.Application")
Catch ' If not active, create a new Inventor session
Dim inventorAppType As Type = System.Type.
GetTypeFromProgID("Inventor.Application")
m_inventorApp = System.Activator.CreateInstance(
inventorAppType)
'Must be set visible explicitly
m_inventorApp.Visible = True
End Try
Catch
System.Windows.Forms.MessageBox.Show(
"Error: couldn't create Inventor instance")
End Try
ModifDerivedParams()
End Sub
Public Sub ModifDerivedParams()
If m_inventorApp.ActiveDocument.DocumentType <>
DocumentTypeEnum.kPartDocumentObject Then
MsgBox("Make a Part Document the active document")
End
End If
Dim oDerPart As PartDocument
oDerPart = m_inventorApp.ActiveDocument
Dim oDerPartComp As DerivedPartComponent
If oDerPart.ComponentDefinition.ReferenceComponents.
DerivedPartComponents.Count < 1 Then
MsgBox("No Derived Part Components in this part")
End
End If
oDerPartComp =
oDerPart.ComponentDefinition.ReferenceComponents.
DerivedPartComponents(1)
Dim oDerivedPartDef As DerivedPartUniformScaleDef
oDerivedPartDef = oDerPartComp.Definition
Dim oDerEntity As DerivedPartEntity
For Each oDerEntity In oDerivedPartDef.Parameters
If (oDerEntity.ReferencedEntity.Name = "d1") Then
oDerEntity.IncludeEntity = True
Exit For
End If
Next
'Set Definition back, so DerivedPart Document is updated
oDerPartComp.Definition = oDerivedPartDef
End Sub
End Class