Link Parameters question

Link Parameters question

nowell.colsenXK53F
Enthusiast Enthusiast
193 Views
4 Replies
Message 1 of 5

Link Parameters question

nowell.colsenXK53F
Enthusiast
Enthusiast

I have a code that will link parameters from a Source file .ipt to a Destination File .ipt or .iam. The issue with my code is that it brings in ALL the user parameters from the Source file even if they are not being used in the Destination File. I would like it if when linking the Source file and the Destination it only brings in the user parameters being linked between the two files. Can anyone tell me how to get the code to only bring in user parameters that are consumed by the Destination file or at the end of the code how to remove the unused user parameters. 

nowellcolsenXK53F_0-1742900791253.png

 

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

WCrihfield
Mentor
Mentor

How can the destination file already be 'using' any parameters that are about to be 'derived into' it from another file?  Without knowing how to answer that, we won't know which parameters to not include from the source file.  The basic Parameter object defined in the Inventor API does have a couple properties that you can inspect though.

Parameter.Dependents 

Parameter.DrivenBy 

Without seeing your original code, and which method(s) you are currently using for this task, not sure how we can suggest specific changes to it, to make it work the way you want.  When 'linking' parameters between Inventor documents, that is using the 'derive' process, and therefore will start with accessing the Parameters.DerivedParameterTables property value, which is the DerivedParameterTables collection object.  That gives us two 'Add' type methods (DerivedParameterTables.Add and DerivedParameterTables.Add2).  The original Add method only lets us specify the 'FullFileName' of the source file, while the second method gives us the additional ability to specify an ObjectCollection with Parameter objects in it that we want to 'Link'.  If that ObjectCollection is not provided, then the only way to control which ones will get 'Linked' is by marking each Parameter for export in 'Export Parameter column of the Parameters dialog, which is the same as setting the Parameter.ExposedAsProperty property's value to True.  And if the 'Link' has already been created, but you want/need to change which ones are included/Linked, then you can set the DerivedParameterTable.LinkedParameters property value with a different ObjectCollection of Parameters that you want to be Linked from the source.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

C_Haines_ENG
Collaborator
Collaborator

Is it possible to just add one new parameter, without removing all the currently added ones? This code below throws an error because of the For loop adding what Parameters are already in the document:

 

If you remove the for loop in the "LinkParameter" sub, it works but replaces all linked Parameters with just the one you clicked on.

 

The code below asks you to click on a dimension from a part in an assembly, and will link said dimension parameter to your assembly.

Sub Main

	Dim oDoc As Document = ThisDoc.Document

	Dim oLinkDim As DimensionConstraint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchDimConstraintFilter, "Select Dimension")

	Dim oLinkPath As String = oLinkDim.Parameter.Parent.FullFileName

	Dim oDocParams As Parameters = oDoc.ComponentDefinition.Parameters
	Dim oLinkedTable As DerivedParameterTable = CheckIfLinked(oDocParams, oLinkPath)

	Call LinkParameter(oLinkDim.Parameter, oLinkedTable)

	Call ShowCurrLinked(oLinkedTable)

End Sub

Function CheckIfLinked(oDocParams As Parameters, oLinkPath As String)

	For Each oDerivedTable As DerivedParameterTable In oDocParams.DerivedParameterTables

		If oDerivedTable.ReferencedDocumentDescriptor.FullDocumentName = oLinkPath Then Return oDerivedTable

	Next

	Return oDocParams.DerivedParameterTables.Add(oLinkPath)

End Function

Sub LinkParameter(oNewParam As Parameter, oLinkedTable As DerivedParameterTable)

	Dim oCollect As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

	For Each oLinkedParam As Parameter In oLinkedTable.LinkedParameters
		oCollect.Add(oLinkedParam)
		Logger.Info(oLinkedParam.Name)
	Next

	oCollect.Add(oNewParam)

	oLinkedTable.LinkedParameters = oCollect

End Sub

Sub ShowCurrLinked(oLinkedTable As DerivedParameterTable)

	For Each oLinkedParam As Parameter In oLinkedTable.LinkedParameters
		Logger.Info(oLinkedParam.Name)
	Next

End Sub

 

0 Likes
Message 4 of 5

C_Haines_ENG
Collaborator
Collaborator

Wow, as soon as I ask my question to the world I solve it. 🙃

 

Once the parameters get added to the DerviedParameterTable, they become DerivedParameters, who woulda guessed!? Means you have to get the entity its referencing to add it back in. 

 

Sub Main

	Dim oDoc As Document = ThisDoc.Document

	Dim oLinkDim As DimensionConstraint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchDimConstraintFilter, "Select Dimension")

	Dim oLinkPath As String = oLinkDim.Parameter.Parent.FullFileName

	Dim oDocParams As Parameters = oDoc.ComponentDefinition.Parameters
	Dim oLinkedTable As DerivedParameterTable = CheckIfLinked(oDocParams, oLinkPath)

	Call LinkParameter(oLinkDim.Parameter, oLinkedTable)

End Sub

Function CheckIfLinked(oDocParams As Parameters, oLinkPath As String)

	For Each oDerivedTable As DerivedParameterTable In oDocParams.DerivedParameterTables

		If oDerivedTable.ReferencedDocumentDescriptor.FullDocumentName = oLinkPath Then Return oDerivedTable

	Next

	Return oDocParams.DerivedParameterTables.Add(oLinkPath)

End Function

Sub LinkParameter(oNewParam As Parameter, oLinkedTable As DerivedParameterTable)

	Dim oCollect As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

	For Each oLinkedParam As DerivedParameter In oLinkedTable.LinkedParameters
		oCollect.Add(oLinkedParam.ReferencedEntity)
	Next

	oCollect.Add(oNewParam)

	oLinkedTable.LinkedParameters = oCollect

End Sub
0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Hi @C_Haines_ENG.  That is a very good question.  I do not think there is a way to do it through these objects & properties, but there may be another way.

  • The DerivedParameterTable.DerivedParameters property is ReadOnly.
  • The DerivedParameters collection object does not have an 'Add' method.
  • The DerivedParameter has a Delete method, and a property for accessing the source Parameter (DerivedParameter.ReferencedEntity), but not a method like 'Replace'.
  • The DerivedParameterTable.LinkedParameters property is Read/Write, but its Value type is an Inventor.ObjectCollection, which is a 'transient' object.
    • Transient objects are temporary, and generally only briefly used for relaying a specific collection of data from one place to another, then is destroyed.
    • Therefore, we can not simply add an item into that collection directly to make it work, but instead it expects us to supply a whole ObjectCollection to set as the value of that LinkedParameters property.  And unfortunately, that seems to replace the ones that are already in there, which may break some links between them and other parameters that may be dependent on them.

The 'other' way that comes to mind, but have not tested it, is to:

Either use the DerivedParameterTable.ReferenceComponent property to get the generic ReferenceComponent, then test which more specific sub-type it is, or go through the Document.ComponentDefinition.ReferenceComponents.DerivedPartComponents... code path, to dig back to the 'definition' of the derived component, and attempt to set the Parameter.ExposedAsProperty property of the source parameter(s), then 'flash' (toggle on/of, then back again) its DerivedPartDefinition.IncludeAllParameters (Read/Write Boolean).  But I don't think we can do anything with its DerivedPartDefinition.Parameters property, since that is also ReadOnly, and the collection object it returns (DerivedPartEntities) does not have an 'Add' method either.  Just some thoughts.

 

Edit:  Since this seems like a pretty relevant thing to want to do, either manually, or by code, it may be a good idea to search within the Inventor Ideas forum to see if anyone else has requested this ability, and if you can't find one, maybe make a new Idea post for it, then post a Link to it back on this forum discussion, to direct some traffic & votes towards it.  I would vote for it.

Edit2:  Wow, I did not see your last reply before posting mine.  I obviously had my reply window open for a longer time that I realized.  😅

Wesley Crihfield

EESignature

(Not an Autodesk Employee)