I am trying to get a user parameter copied in to a derived part. I got help from the forum and tailored to my requirement.
In my rule, I have a problem in the last line.
I Request help.
Sub main() 'Public Sub ModifDerivedParams() oTDMD = ThisDoc.ModelDocument oFFN_TDMD = oTDMD.FullFileName 'Full File Name (ABS)of THMD oDN_wExt_TDMD = oTDMD.DisplayName 'Display Name (LFN)of THMD 'https://adndevblog.typepad.com/manufacturing/2012/06/includeexclude-parameters-from-the-base-part-in-a-derived-part.html If oTDMD.DocumentType <> kPartDocumentObject Then MsgBox("Make a Part Document the active document") Exit Sub Else MsgBox("This drawig has a part document") End If If oTDMD.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count < 1 Then MsgBox("No Derived Part Components in this part") Exit Sub Else MsgBox("This part has Derived Part Components") End If Dim oDPs As New ArrayList() For Each oDP In oTDMD.ComponentDefinition.ReferenceComponents.DerivedPartComponents MessageBox.Show("oDP: " & oDP.Name, "Title") oDPs.Add(oDP) Next oDP 'oDP_Selected = oDerPart.ComponentDefinition.ReferenceComponents.DerivedPartComponents(1) oDP_Selected = InputListBox("Prompt", oDPs, oDPs(0), Title := "SELECT DP FROM", ListName := "LIST OF DPs") Dim oDerivedPartDef As DerivedPartUniformScaleDef oDerivedPartDef = oDP_Selected.Definition Dim oDerEntity As DerivedPartEntity For Each oDerEntity In oDerivedPartDef.Parameters If oDerEntity.ReferencedEntity.Name.Contains("D3") Then MessageBox.Show("oDerEntity.ReferencedEntity.Name: " & oDerEntity.ReferencedEntity.Name, "Title") oDerEntity.IncludeEntity = True End If Next 'To set Definition back, so DerivedPart Document is updated oDP_Selected.Definition = oDerivedPartDef End Sub
Solved! Go to Solution.
Solved by HideoYamada. Go to Solution.
Hello rwickrama,
Try add this line before you use oDP_Selected and your code will work.
Dim oDP_Selected As DerivedPartComponent
And I think it's better to use the option "option Explicit on".
=====
Freeradica
Hideo Yamada
Thanks for the reply. It works.
I also need this to a little bit user friendly (to carry the part name)
Could you help further. I appreciate your help.
Hello rwickrama,
I'm not good at iLogic, so there must be more better solution... but I tried.
Replace the code
Dim oDPs As New ArrayList() For Each oDP In oTDMD.ComponentDefinition.ReferenceComponents.DerivedPartComponents MessageBox.Show("oDP: " & oDP.Name, "Title") oDPs.Add(oDP) Next oDP oDP_Selected = InputListBox("Prompt", oDPs, oDPs(0), Title := "SELECT DP FROM", ListName := "LIST OF DPs")
with
Dim derivedPartNameList As New ArrayList() For Each oDP In oTDMD.ComponentDefinition.ReferenceComponents.DerivedPartComponents derivedPartNameList.Add(oDP.Name) Next oDP Dim selectedName As String selectedName = InputListBox("Prompt", derivedPartNameList, derivedPartNameList(0), Title := "SELECT DP FROM", ListName := "LIST OF DPs") Dim oDP_Selected As DerivedPartComponent For Each oDP In oTDMD.ComponentDefinition.ReferenceComponents.DerivedPartComponents If oDP.Name = selectedName Then MessageBox.Show("Found : " & selectedName) oDP_Selected = oDP Exit For End If Next oDP
Best Regards,
=====
Freeradical
Hideo Yamada
Can't find what you're looking for? Ask the community or share your knowledge.