Copy custom iProperty from Child to parent

Copy custom iProperty from Child to parent

RoyWickrama_RWEI
Advisor Advisor
847 Views
6 Replies
Message 1 of 7

Copy custom iProperty from Child to parent

RoyWickrama_RWEI
Advisor
Advisor

In my modelling, I come across with situations where I have to create an assembly for a part or an assembly (only one of them exists in this new assembly)  itself.

However, now I need to import the iProperties from the child part (or assembly) to this new assembly.

I havbe a rule, but not doing well: it creates additional custom iProperties 

2018-06-03 11_58_11-MAIN iProperties.png

I request help.

Attached sample file.

Inventor 2015/2018

Thanks.

0 Likes
Accepted solutions (2)
848 Views
6 Replies
Replies (6)
Message 2 of 7

RoyWickrama_RWEI
Advisor
Advisor

Basically, I need to get copied Part Number, Description and Total Qty custom iProperty.

My code below does not work. Request help!

Note: This assembly has only one child (either one part or one assembly) always.

 

Sub Main()
oRuleNo = "iL0050"
Dim openAssy As Document
oRun_or_Not = MessageBox.Show("DO YOU WANT TO RUN THIS RULE?", oRuleNo, MessageBoxButtons.YesNo)
If oRun_or_Not = vbNo Then Exit Sub

openAssy = ThisDoc.Document
Dim oPropertySet_openAssy As PropertySet
Dim oChildDoc As Document
oPropertySet_openAssy = openAssy.PropertySets.Item("Inventor User Defined Properties")

If openAssy.DocumentType = kAssemblyDocumentObject Then 
	oChildDoc = openAssy.AllReferencedDocuments.item(1)
	MessageBox.Show("oChildDoc: " & oChildDoc.FullFileName, "Title")
	iProperties.Value("Project", "Part Number") = iProperties.Value(oChildDoc, "Project", "Part Number")
	iProperties.Value("Project", "Description") = iProperties.Value(oChildDoc, "Project", "Description")
	iProperties.Value("Custom", "TOTAL QTY") = iProperties.Value(oChildDoc, "Custom", "TOTAL QUANTITY")
Else
	MessageBox.Show("This document is not an assembly!", "INFORMATION")
End If 
End Sub
0 Likes
Message 3 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@RoyWickrama_RWEI,

 

Try below iLogic code to update iProperties from child document to main assembly. Before running this code, make sure that custom iProperties are defined with same name. Otherwise, code throws exception.

 

Sub Main()
oRuleNo = "iL0050"
Dim openAssy As Document
oRun_or_Not = MessageBox.Show("DO YOU WANT TO RUN THIS RULE?", oRuleNo, MessageBoxButtons.YesNo)
If oRun_or_Not = vbNo Then Exit Sub

openAssy = ThisDoc.Document
Dim oPropertySet_openAssy As PropertySet
Dim oChildDoc As Document
oPropertySet_openAssy = openAssy.PropertySets.Item("Inventor User Defined Properties")

If openAssy.DocumentType = kAssemblyDocumentObject Then 
	oChildDoc = openAssy.AllReferencedDocuments.Item(1)
	MessageBox.Show("oChildDoc: " & oChildDoc.FullFileName, "Title") 
	iProperties.Value("Project", "Part Number") = oChildDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
	iProperties.Value("Project", "Description") = oChildDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
	iProperties.Value("Custom", "TOTAL QTY") = oChildDoc.PropertySets.Item("User Defined Properties").Item("TOTAL QTY").Value
Else
	MessageBox.Show("This document is not an assembly!", "INFORMATION")
End If 


oSave()
End Sub

Sub oSave()
ThisDoc.Save
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 4 of 7

RoyWickrama_RWEI
Advisor
Advisor

The code worked perfectly.

I thought I will be doing with an assembly of either one part or or assembly. But, I got to do with a weldment where I inserted a part (this is a sketch anyway).

Weldment.png

To do with any assembly, I think, I need to select the oChildDoc from a list; for example,

Dim oChildren_Assy As New ArrayList

For Each oChildDoc In openAssy.AllReferencedDocuments
	oChildren_Array.add(oChildDoc.FullFileName)
	-------

Next oChildDoc

oChildDoc = InputListBox("Prompt", oChildren_Assy, oChildren_Assy(0), Title := "Title", ListName := "List")

Could you provide some solution. Sorry to disturb you.

 

 

 

 

 

the assembly is going to have a

0 Likes
Message 5 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@RoyWickrama_RWEI,

 

Try below iLogic code to select child document from assembly.

 

Dim oChildren_Assy As New ArrayList
Dim openAssy As AssemblyDocument
openAssy = ThisApplication.ActiveDocument 
Dim oChildDoc As Document 

For Each oChildDoc  In openAssy.AllReferencedDocuments
	oChildren_Assy.Add(oChildDoc.FullFileName) 
	

Next oChildDoc

childName = InputListBox("Prompt", oChildren_Assy, oChildren_Assy(0), Title := "Title", ListName := "List")


Dim selectedDoc As Document 

For Each oChildDoc  In openAssy.AllReferencedDocuments
	If oChildDoc.FullFileName = childName Then
		selectedDoc = oChildDoc 		
		Exit For 
	End If

Next oChildDoc

MessageBox.Show(selectedDoc.DisplayName, "Title")

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Like".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 6 of 7

RoyWickrama_RWEI
Advisor
Advisor

Thanks a lot again. The help was almost perfect.

 

The little issue was, I could not read the file name in the message box because full file name is too long. Therefore, I revised the code as shown below (mostly it is your code: Thanks):

I would like to ask, is it possible to increase the width of the message box?

Dim oChildren_in_Assy As New ArrayList
Dim FName_Children As New ArrayList	'FN: File Name
Dim openAssy As AssemblyDocument
openAssy = ThisApplication.ActiveDocument 
Dim oChildDoc As Document 

If openAssy.DocumentType = kAssemblyDocumentObject Then 

	For Each oChildDoc  In openAssy.AllReferencedDocuments
		oChildren_in_Assy.Add(oChildDoc.FullFileName) 
		FName_Pos = InStrRev(oChildDoc.FullFileName, "\", -1)
		FName_Child = Right(oChildDoc.FullFileName, Len(oChildDoc.FullFileName) - FName_Pos)
		FName_Children.Add(FName_Child)
	Next oChildDoc
	
	Child_Selected = InputListBox("SELECT SOURCE DOCUMENT", FName_Children, FName_Children(0), Title := "TO COPY PROPERTIES FROM", ListName := "REFERENCE DOCUMENTS")
'	oIndex = FName_Children.IndexOf(Child_Selected)

	iProperties.Value("Project", "Part Number") = oChildDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
	iProperties.Value("Project", "Description") = oChildDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
	iProperties.Value("Custom", "TOTAL QTY") = oChildDoc.PropertySets.Item("User Defined Properties").Item("TOTAL QTY").Value
Else
	MessageBox.Show("This document is not an assembly!", "INFORMATION")
End If

Capture.PNG

 

 

0 Likes
Message 7 of 7

RoyWickrama_RWEI
Advisor
Advisor

Hi Chandra Shekar Gopal;

Starting from your help (thanks a lot), I further developed the code to:

  • copy all custom properties from the selected child
  • copy only pre-defined (in the rule) properties

 

0 Likes