Include User Parameters in a Derived Part

Include User Parameters in a Derived Part

MJH_
Contributor Contributor
670 Views
3 Replies
Message 1 of 4

Include User Parameters in a Derived Part

MJH_
Contributor
Contributor

I'm currently trying to automate a way of including only the User Parameters in a derived part.

 

_MJH_1-1636104737031.png

 

 

oDoc = ThisApplication.ActiveDocument
If oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count > 0
Dim oDerComp As DerivedPartComponent = oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents(1)
Dim oDerDef As DerivedPartDefinition = oDerComp.Definition
oDerDef.IncludeAllParameters = True
oDerDef.UseColorOverridesFromSource = False
oDerComp.Definition = oDerDef

 

 

The above code almost works as intended, however it includes all parameters in the Derived Part (due to the line oDerDef.IncludeAllParameters).

 

_MJH_2-1636104757515.png

 

Is there a way to include only the User Parameters?

0 Likes
Accepted solutions (1)
671 Views
3 Replies
Replies (3)
Message 2 of 4

Michael.Navara
Advisor
Advisor

You need to include all parameters and exclude non user parameters. And also you can do another check.

 

Dim activePart As PartDocument = ThisDoc.Document

'Create new part derived from this one
Dim newPart As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject)

Dim derivedPartDef As DerivedPartDefinition = newPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(activePart.FullFileName)

'Include all parameters
derivedPartDef.IncludeAllParameters = True

'Exclude non user parameters
For Each entity As DerivedPartEntity In derivedPartDef.Parameters
	Dim userParam As UserParameter
	userParam = TryCast(entity.ReferencedEntity, UserParameter)
	
	'Exclude non user parameters
	If userParam Is Nothing Then
		entity.IncludeEntity = False
		continue for
	End If

'	'Include only parameters which name starts with "Incl"
'	If Not userParam.Name.StartsWith("Incl") Then
'		entity.IncludeEntity = False
'	End If
Next

newPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Add(derivedPartDef)
newPart.Activate()
0 Likes
Message 3 of 4

MJH_
Contributor
Contributor

Thanks for the response but I may not have fully explained what I'm after. If I create a new parameter in a skeleton, I then have to go in to the part I've created, right-click the derived skeleton and include the new parameter. I'm trying to automate this process and create a Global Form button which will execute the code within existing parts to update my derived user parameters. The aim is to just update the existing User Parameters that have been pulled through from the skeleton.

0 Likes
Message 4 of 4

MJH_
Contributor
Contributor
Accepted solution

After a bit of plugging and playing I've managed to work it out.

 

 

oDoc = ThisApplication.ActiveDocument
If oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count > 0
Dim oDerComp As DerivedPartComponent = oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents(1)
Dim oDerDef As DerivedPartDefinition = oDerComp.Definition
oDerDef.IncludeAllParameters = True
oDerDef.UseColorOverridesFromSource = False

For Each entity As DerivedPartEntity In oDerDef.Parameters
Dim userParam As UserParameter
userParam = TryCast(entity.ReferencedEntity, UserParameter)

If userParam Is Nothing Then
	entity.IncludeEntity = False
	Continue For
	End If
Next

oDerComp.Definition = oDerDef

End If

 

0 Likes