Linking parameters to existing derived parameter table crashes

Linking parameters to existing derived parameter table crashes

johnster100
Collaborator Collaborator
472 Views
4 Replies
Message 1 of 5

Linking parameters to existing derived parameter table crashes

johnster100
Collaborator
Collaborator

Hi,

i have two parts, part 1 and part2.

 

Part 2 is already linked to part 1. I would like to link an extra parameter (d3 in this case) to it.

 

i have followed the sample in the help guide but can't get to work. 

 

here is my code and the parts are attached with the code in part 2:

Sub main
	
	Dim param As String = "d3"
	
	Dim oCompDef As Inventor.PartComponentDefinition = ThisDoc.Document.ComponentDefinition
	
	Dim oLinkedPart As Inventor.PartDocument
	Dim oTable As Inventor.DerivedParameterTable = oCompDef.Parameters.DerivedParameterTables.Item(1)

	
	Dim oParamsToLink As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	'oParamsToLink  = oTable.DerivedParameters 
	For Each oPAram In oTable.LinkedParameters
		oParamsToLink.Add(oPAram)
	Next
	
	oLinkedPart = oTable.ReferencedDocumentDescriptor.ReferencedDocument	
	oParamsToLink.Add(oLinkedPart.ComponentDefinition.Parameters.Item(param))
	oTable.LinkedParameters = oParamsToLink
	
	
End Sub

 

any help greatly appreciated,

thanks,

John

0 Likes
473 Views
4 Replies
Replies (4)
Message 2 of 5

bradeneuropeArthur
Mentor
Mentor

If you used the derive method to make a link to the other part, you will need to use here also the derive method to derive a parameter.

Think that you cannot mix both!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 5

johnster100
Collaborator
Collaborator

thanks for that!

 

i'll look into it.

0 Likes
Message 4 of 5

Ralf_Krieg
Advisor
Advisor

Hello

 

As I see in your demo files, the parameters are linked, not derived.  The only little fault in your code is, you can not add the linked parameters to the object collection of parameters to linked. You need to add the original parameters. Try:

 

Sub main()
    
    Dim param As String = "d3"
    Dim oCompDef As Inventor.PartComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
    Dim oTable As Inventor.DerivedParameterTable= oCompDef.Parameters.DerivedParameterTables.Item(1)
    Dim oLinkedPart As Inventor.PartDocument = oTable.ReferencedDocumentDescriptor.ReferencedDocument
    Dim oParamsToLink As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
    
    Dim oParam As DerivedParameter
    Dim oSourceParam As Parameter
    For Each oParam In oTable.LinkedParameters 'returns a DerivedParameter, we need the source
        For Each oSourceParam In oLinkedPart.ComponentDefinition.Parameters
            If oSourceParam.Name = oParam.Name Then Call oParamsToLink.Add(oSourceParam)
        Next
    Next
        
    Call oParamsToLink.Add(oLinkedPart.ComponentDefinition.Parameters.Item(param))
    oTable.LinkedParameters = oParamsToLink
    
End Sub

 o


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 5 of 5

Ralf_Krieg
Advisor
Advisor

In addition, if the part is derived  instead linked, the parameter could included like this:

 

Sub main()
    
    Dim param As String = "d3"
    Dim oCompDef As Inventor.PartComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
    Dim oTable As Inventor.DerivedParameterTable = oCompDef.Parameters.DerivedParameterTables.Item(1)
    Dim oDerivedPartComp As DerivedPartComponent = oTable.ReferenceComponent
    Dim oDerivedPartDef As DerivedPartUniformScaleDef= oDerivedPartComp.Definition
    
    Dim oParam As DerivedPartEntity
    For Each oParam In oDerivedPartDef.Parameters
        If oParam.ReferencedEntity.Name = param Then
            oParam.IncludeEntity = True
        End If
    Next
    
    oDerivedPartComp.Definition = oDerivedPartDef
    
End Sub

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes