Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Rule in Drawing: Need to Copy Selected User Parameter in Derived Part

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
RoyWickrama_RWEI
383 Views, 3 Replies

Rule in Drawing: Need to Copy Selected User Parameter in Derived Part

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.

https://adndevblog.typepad.com/manufacturing/2012/06/includeexclude-parameters-from-the-base-part-in...

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

 

 

3 REPLIES 3
Message 2 of 4

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

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
Message 3 of 4

Thanks for the reply. It works.

 

I also need this to a little bit user friendly (to carry the part name)

 

2019-08-12 18_55_51-Window.png

 

Could you help further.  I appreciate your help.

Message 4 of 4

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

 

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report