iLogic User Parameter of Derive Part

iLogic User Parameter of Derive Part

Anonymous
Not applicable
792 Views
4 Replies
Message 1 of 5

iLogic User Parameter of Derive Part

Anonymous
Not applicable

Hello, I would like to be able to retrieve a user parameter inside of a source part of a derived part.

I have a code that works, but it does NOT retrieve User Parameters, just regular parameters.

How could I modify it so I can retrieve user parameters as well please?

Note: I made a MsgBox to make sure it would get the user parameter, but it doesn't. The user parameter variable is called "TypePiece" and it is in a text format. Thanks !

 

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.UseColorOverridesFromSource = False
oDerComp.Definition = oDerDef

oDerPartComp = oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents(1)
Dim oDerivedPartDef As DerivedPartUniformScaleDef
oDerivedPartDef = oDerPartComp.Definition
Dim oDerEntity As DerivedPartEntity

Dim oDerPart As Document = oDerComp.ReferencedDocumentDescriptor.ReferencedDocument
If TypeOf (oDerPart.ComponentDefinition) Is SheetMetalComponentDefinition _
AndAlso TypeOf (oDoc.ComponentDefinition) Is SheetMetalComponentDefinition
oDoc.ComponentDefinition.SheetMetalStyles(oDerPart.ComponentDefinition.ActiveSheetMetalStyle.Name).Activate
End If

For Each oDerEntity In oDerivedPartDef.Parameters
MsgBox(oDerEntity.ReferencedEntity.Name)
Next

0 Likes
Accepted solutions (1)
793 Views
4 Replies
Replies (4)
Message 2 of 5

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

I don't think you can derive text parameters. Try to edit the derived part and you'll see there's no option to derive the parameter from there either. Thats why it doesn't show up... A numeric user parameter would however...

 

If you just want to get the parameter object for the text parameter you can though:

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.UseColorOverridesFromSource = False
oDerComp.Definition = oDerDef

oDerPartComp = oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents(1)
Dim oDerivedPartDef As DerivedPartUniformScaleDef
oDerivedPartDef = oDerPartComp.Definition
Dim oDerEntity As DerivedPartEntity

Dim oDerPart As Document = oDerComp.ReferencedDocumentDescriptor.ReferencedDocument
If TypeOf (oDerPart.ComponentDefinition) Is SheetMetalComponentDefinition _
AndAlso TypeOf (oDoc.ComponentDefinition) Is SheetMetalComponentDefinition
oDoc.ComponentDefinition.SheetMetalStyles(oDerPart.ComponentDefinition.ActiveSheetMetalStyle.Name).Activate
End If

For Each oParam As UserParameter In oDerPart.ComponentDefinition.Parameters.UserParameters
MsgBox(oParam.Name & vbCrLf & oParam.Expression)
Next
End If
0 Likes
Message 3 of 5

Anonymous
Not applicable

Yeah sorry, I am french so it may have came across as if I wanted to derive the parameter. I just want to copy the value over from the original to the derived parts.

 

Right now, I modified the code so it is this:

 

For Each oParam As UserParameter In oDerPart.ComponentDefinition.Parameters.UserParameters
oMyParameter=oDoc.ComponentDefinition.Parameters.UserParameters
oParameter=oMyParameter.AddByValue("TypePiece", oParam.Expression, UnitsTypeEnum.kTextUnits)
Next

 

But, it gives me for example *Hello*, instead of Hello. Is there a way to modify that, or do I need to use "left" and "right"? Otherwise, it is perfect.

Also, I would like for it to not add 50 times the parameter if I run the rule 50 times, I don't know if there is something else than "AddByValue" to just create the variable if it doesn't exist and/or modify it to the expression without the "s leading and trailing.

0 Likes
Message 4 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

Use oParam.Value instead of oParam.Expression:

For Each oParam As UserParameter In oDerPart.ComponentDefinition.Parameters.UserParameters
oMyParameter=oDoc.ComponentDefinition.Parameters.UserParameters
oParameter=oMyParameter.AddByValue("TypePiece", oParam.Value, oParam.Units)
Next
Message 5 of 5

Anonymous
Not applicable

Nevermind, my brain was mush this morning. A simple Try/Catch worked. Thanks!

0 Likes