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: 

DERIVED PART: To copy multiple selected Custom iProperties from the selected

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
RoyWickrama_RWEI
1002 Views, 8 Replies

DERIVED PART: To copy multiple selected Custom iProperties from the selected

RoyWickrama_RWEI
Advisor
Advisor

In case the derived part has multiple reference documents, I need to select the desired reference document and then select the required custom iProperties (multiple) from the drop-down list.

 

By searching in the forum, I managed to crate a rule. It is doing a kind of well except I am not able to select multiple items from the drop down list. Please see below. I believe, I am not capable of writing a code and I would like to request someone help me with a code.

 

Sample files (Inventor 2019) is provided. Please run the rule in p0003

2019-04-19 2333.png

 

 

2019-04-19 2256.png

Step-1: Select the desired reference document

 

2019-04-19 2259.png

 Step-2: Select the desired custom iProperty. Can I select more from this list?

 

2019-04-19 2312.png

Step-3: Currently, I select the next by hitting YES button to copy another custom iProperty.

 

Sub main()
Dim iL_NO As String = "002DP"
Dim iL_Name As String = "Copy Custom Property in Derived Part"
Dim iL_FullName As String = "Rule " & iL_NO & ": " & iL_Name

Dim openDoc As Document
openDoc = ThisDoc.Document

If openDoc.DocumentType <> kPartDocumentObject Then 
	MessageBox.Show("This rule is for a part docuent only!", "File Type Mismatch!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
	Exit Sub
End If

Dim oRefFile As FileDescriptor
Dim oName_DerivedFile As Object     
Dim oFFN_DerivedParts_Array As New ArrayList
Dim oLFN_DerivedParts_Array As New ArrayList
Dim oCancel As String = "Cancel"

For Each oRefFile In openDoc.File.ReferencedFileDescriptors
oName_DerivedFile = oRefFile.FullFileName
oFFN_DerivedParts_Array.Add(oName_DerivedFile)

If oFFN_DerivedParts_Array.Count = 0 Then
MessageBox.Show("NO DERIVED PART(S) FOUND: Exit Sub!", "Title")
Exit Sub
End If	

oPosition_LFN_oRefFile = InStrRev(oName_DerivedFile, "\", - 1) 
oLFN_oRefFile = Right(oName_DerivedFile, Len(oName_DerivedFile) - oPosition_LFN_oRefFile)
'MessageBox.Show("Len(oFFN): " & Len(oFFN) _
'& vbLf & "oPosition_LFN: " & oPosition_LFN _
'& vbLf & "oLFN (Delected ref doc): " & oLFN, "SELECTED DOC")	
oLFN_DerivedParts_Array.Add(oLFN_oRefFile)
Next

oLFN_Selected_DerivedPart = InputListBox("Prompt", oLFN_DerivedParts_Array, oLFN_DerivedParts_Array(0), Title := "Title", ListName := "List")
oIndex = oLFN_DerivedParts_Array.IndexOf(oLFN_Selected_DerivedPart)

oSourceSelected_DerivedPart = oFFN_DerivedParts_Array(oIndex)
'oSourceSelected_DerivedPart = InputListBox("Prompt", oFFN_DerivedParts_Array, oFFN_DerivedParts_Array(0), Title := "Title", ListName := "List")

    Dim oDoc_CurrDerivedPart As Document
    oDoc_CurrDerivedPart = ThisApplication.ActiveDocument
    
    Dim oDerivedPartSource_Selected As Document
    oDerivedPartSource_Selected = ThisApplication.Documents.Open(oSourceSelected_DerivedPart, False)
'    MessageBox.Show("oDerivedPartSource_Selected: " & oDerivedPartSource_Selected.FullFileName, "Title")

    Copy_iProperties_Sub(oDerivedPartSource_Selected, oDoc_CurrDerivedPart)

    ' Skip save
    oDerivedPartSource_Selected.Close(True)
iLogicVb.UpdateWhenDone = True

End Sub

Sub Copy_iProperties_Sub(ByVal oDerivedPartSource_Selected As Document, ByVal oDoc_CurrDerivedPart As Document)
oFFN = oDerivedPartSource_Selected.FullFileName
oPosition_LFN = InStrRev(oFFN, "\", - 1) 
oLFN = Right(oFFN, Len(oFFN) - oPosition_LFN)
'MessageBox.Show("Len(oFFN): " & Len(oFFN) _
'& vbLf & "oPosition_LFN: " & oPosition_LFN _
'& vbLf & "oLFN (Delected ref doc): " & oLFN, "SELECTED DOC")
	
Dim to_PropertySet As PropertySet
to_PropertySet = oDoc_CurrDerivedPart.PropertySets.Item("Inventor User Defined Properties")

Dim from_PropertySet As PropertySet
from_PropertySet = oDerivedPartSource_Selected.PropertySets.Item("Inventor User Defined Properties")
'	For Each oCustProp In oCustomPropertySet
'	oCustProp.Delete
'	Next
'docFile.PropertySets.Item("Inventor User Defined Properties") 
'Dim oDerived As Inventor.Document = ThisApplication.ActiveDocument
'If oDerived.ReferencedDocuments.Count = 0 Then Exit Sub

Dim oProps_DerivedPart As PropertySet = oDoc_CurrDerivedPart.PropertySets.Item("Inventor User Defined Properties")
Dim oProps_SelectedSource As PropertySet = oDerivedPartSource_Selected.PropertySets.Item("Inventor User Defined Properties")

Dim oCustProps_Availble_To_Copy As New ArrayList

Dim oProList() As String = {"*" }	'"CMF_DESGINATION", "OTHER_iPRO"} 'Use "*" to copy all iPros
'Dim oProList() As String = {"Finished_Length_1", "OTHER_iPRO" }
	For Each oProp_RefDoc As Inventor.Property In oProps_SelectedSource
	    Dim oSkip As Boolean = True
	    For Each oProp_oProList As String In oProList
'			MessageBox.Show("oProp_oProList: " & oProp_oProList _
'			& vbLf & "oProp_RefDoc.Name:" & oProp_RefDoc.Name, "Title")
	        If UCase(oProp_oProList) <> UCase(oProp_RefDoc.Name) And oProp_oProList <> "*" Then Continue For
	        oSkip = False
	        Exit For
	    Next
'		MessageBox.Show("oSkip: " & oSkip, "Title")
	    If oSkip = True Then Continue For
'		MessageBox.Show("iProp found in (Ref. doc): " & oLFN _
'		& vbLf & "oProp_RefDoc.Name: " & oProp_RefDoc.Name, "Title")
		oCustProps_Availble_To_Copy.Add(oProp_RefDoc.Name)
	Next
		
L_oProp_Selected:
oProp_Selected = InputListBox("Prompt", oCustProps_Availble_To_Copy, oCustProps_Availble_To_Copy(0), Title := "Title", ListName := "List")

	    Dim oDerPro As Inventor.Property
	    Try
	        oDerPro = oProps_DerivedPart(oProp_Selected)
	    Catch
	        oDerPro = oProps_DerivedPart.Add("", oProp_Selected)
	    End Try
	    oDerPro.Value = oProp_Selected

oYesNo = MessageBox.Show("Selected custom iProperty:" _
& vbLf & "" & oProp_Selected _
& vblf & "Created. Do you want To Select again ?", " Select AGAIN! ", MessageBoxButtons.YesNo)
If oYesNo = vbYes Then GoTo L_oProp_Selected:

End Sub
0 Likes

DERIVED PART: To copy multiple selected Custom iProperties from the selected

In case the derived part has multiple reference documents, I need to select the desired reference document and then select the required custom iProperties (multiple) from the drop-down list.

 

By searching in the forum, I managed to crate a rule. It is doing a kind of well except I am not able to select multiple items from the drop down list. Please see below. I believe, I am not capable of writing a code and I would like to request someone help me with a code.

 

Sample files (Inventor 2019) is provided. Please run the rule in p0003

2019-04-19 2333.png

 

 

2019-04-19 2256.png

Step-1: Select the desired reference document

 

2019-04-19 2259.png

 Step-2: Select the desired custom iProperty. Can I select more from this list?

 

2019-04-19 2312.png

Step-3: Currently, I select the next by hitting YES button to copy another custom iProperty.

 

Sub main()
Dim iL_NO As String = "002DP"
Dim iL_Name As String = "Copy Custom Property in Derived Part"
Dim iL_FullName As String = "Rule " & iL_NO & ": " & iL_Name

Dim openDoc As Document
openDoc = ThisDoc.Document

If openDoc.DocumentType <> kPartDocumentObject Then 
	MessageBox.Show("This rule is for a part docuent only!", "File Type Mismatch!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
	Exit Sub
End If

Dim oRefFile As FileDescriptor
Dim oName_DerivedFile As Object     
Dim oFFN_DerivedParts_Array As New ArrayList
Dim oLFN_DerivedParts_Array As New ArrayList
Dim oCancel As String = "Cancel"

For Each oRefFile In openDoc.File.ReferencedFileDescriptors
oName_DerivedFile = oRefFile.FullFileName
oFFN_DerivedParts_Array.Add(oName_DerivedFile)

If oFFN_DerivedParts_Array.Count = 0 Then
MessageBox.Show("NO DERIVED PART(S) FOUND: Exit Sub!", "Title")
Exit Sub
End If	

oPosition_LFN_oRefFile = InStrRev(oName_DerivedFile, "\", - 1) 
oLFN_oRefFile = Right(oName_DerivedFile, Len(oName_DerivedFile) - oPosition_LFN_oRefFile)
'MessageBox.Show("Len(oFFN): " & Len(oFFN) _
'& vbLf & "oPosition_LFN: " & oPosition_LFN _
'& vbLf & "oLFN (Delected ref doc): " & oLFN, "SELECTED DOC")	
oLFN_DerivedParts_Array.Add(oLFN_oRefFile)
Next

oLFN_Selected_DerivedPart = InputListBox("Prompt", oLFN_DerivedParts_Array, oLFN_DerivedParts_Array(0), Title := "Title", ListName := "List")
oIndex = oLFN_DerivedParts_Array.IndexOf(oLFN_Selected_DerivedPart)

oSourceSelected_DerivedPart = oFFN_DerivedParts_Array(oIndex)
'oSourceSelected_DerivedPart = InputListBox("Prompt", oFFN_DerivedParts_Array, oFFN_DerivedParts_Array(0), Title := "Title", ListName := "List")

    Dim oDoc_CurrDerivedPart As Document
    oDoc_CurrDerivedPart = ThisApplication.ActiveDocument
    
    Dim oDerivedPartSource_Selected As Document
    oDerivedPartSource_Selected = ThisApplication.Documents.Open(oSourceSelected_DerivedPart, False)
'    MessageBox.Show("oDerivedPartSource_Selected: " & oDerivedPartSource_Selected.FullFileName, "Title")

    Copy_iProperties_Sub(oDerivedPartSource_Selected, oDoc_CurrDerivedPart)

    ' Skip save
    oDerivedPartSource_Selected.Close(True)
iLogicVb.UpdateWhenDone = True

End Sub

Sub Copy_iProperties_Sub(ByVal oDerivedPartSource_Selected As Document, ByVal oDoc_CurrDerivedPart As Document)
oFFN = oDerivedPartSource_Selected.FullFileName
oPosition_LFN = InStrRev(oFFN, "\", - 1) 
oLFN = Right(oFFN, Len(oFFN) - oPosition_LFN)
'MessageBox.Show("Len(oFFN): " & Len(oFFN) _
'& vbLf & "oPosition_LFN: " & oPosition_LFN _
'& vbLf & "oLFN (Delected ref doc): " & oLFN, "SELECTED DOC")
	
Dim to_PropertySet As PropertySet
to_PropertySet = oDoc_CurrDerivedPart.PropertySets.Item("Inventor User Defined Properties")

Dim from_PropertySet As PropertySet
from_PropertySet = oDerivedPartSource_Selected.PropertySets.Item("Inventor User Defined Properties")
'	For Each oCustProp In oCustomPropertySet
'	oCustProp.Delete
'	Next
'docFile.PropertySets.Item("Inventor User Defined Properties") 
'Dim oDerived As Inventor.Document = ThisApplication.ActiveDocument
'If oDerived.ReferencedDocuments.Count = 0 Then Exit Sub

Dim oProps_DerivedPart As PropertySet = oDoc_CurrDerivedPart.PropertySets.Item("Inventor User Defined Properties")
Dim oProps_SelectedSource As PropertySet = oDerivedPartSource_Selected.PropertySets.Item("Inventor User Defined Properties")

Dim oCustProps_Availble_To_Copy As New ArrayList

Dim oProList() As String = {"*" }	'"CMF_DESGINATION", "OTHER_iPRO"} 'Use "*" to copy all iPros
'Dim oProList() As String = {"Finished_Length_1", "OTHER_iPRO" }
	For Each oProp_RefDoc As Inventor.Property In oProps_SelectedSource
	    Dim oSkip As Boolean = True
	    For Each oProp_oProList As String In oProList
'			MessageBox.Show("oProp_oProList: " & oProp_oProList _
'			& vbLf & "oProp_RefDoc.Name:" & oProp_RefDoc.Name, "Title")
	        If UCase(oProp_oProList) <> UCase(oProp_RefDoc.Name) And oProp_oProList <> "*" Then Continue For
	        oSkip = False
	        Exit For
	    Next
'		MessageBox.Show("oSkip: " & oSkip, "Title")
	    If oSkip = True Then Continue For
'		MessageBox.Show("iProp found in (Ref. doc): " & oLFN _
'		& vbLf & "oProp_RefDoc.Name: " & oProp_RefDoc.Name, "Title")
		oCustProps_Availble_To_Copy.Add(oProp_RefDoc.Name)
	Next
		
L_oProp_Selected:
oProp_Selected = InputListBox("Prompt", oCustProps_Availble_To_Copy, oCustProps_Availble_To_Copy(0), Title := "Title", ListName := "List")

	    Dim oDerPro As Inventor.Property
	    Try
	        oDerPro = oProps_DerivedPart(oProp_Selected)
	    Catch
	        oDerPro = oProps_DerivedPart.Add("", oProp_Selected)
	    End Try
	    oDerPro.Value = oProp_Selected

oYesNo = MessageBox.Show("Selected custom iProperty:" _
& vbLf & "" & oProp_Selected _
& vblf & "Created. Do you want To Select again ?", " Select AGAIN! ", MessageBoxButtons.YesNo)
If oYesNo = vbYes Then GoTo L_oProp_Selected:

End Sub
8 REPLIES 8
Message 2 of 9

bradeneuropeArthur
Mentor
Mentor

Please check one of the topics in my signature about derived parts and copy properties. You could vote it!

Regards,

Autodesk Software: Inventor Professional 2018 | Vault Professional 2018 | Autocad Mechanical 2018
Programming Skills: Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Dimension Component! | Partlist Export! | Derive I-properties! | Vault Prompts Via API! | Vault Handbook/Manual!
Drawing Toggle Sheets! | Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Please check one of the topics in my signature about derived parts and copy properties. You could vote it!

Regards,

Autodesk Software: Inventor Professional 2018 | Vault Professional 2018 | Autocad Mechanical 2018
Programming Skills: Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Dimension Component! | Partlist Export! | Derive I-properties! | Vault Prompts Via API! | Vault Handbook/Manual!
Drawing Toggle Sheets! | Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 3 of 9

RoyWickrama_RWEI
Advisor
Advisor

I revised the rule a little bit: it removes the item selected from the list (diminishing list) so that I don't have to re-selected what I selected already.

 

L_oProp_Selected:
oProp_Selected = InputListBox("Prompt", oCustProps_Availble_To_Copy, oCustProps_Availble_To_Copy(0), Title := "Title", ListName := "List")

	    Dim oDerPro As Inventor.Property
	    Try
	        oDerPro = oProps_DerivedPart(oProp_Selected)
	    Catch
	        oDerPro = oProps_DerivedPart.Add("", oProp_Selected)
	    End Try
	    oDerPro.Value = oProp_Selected

oYesNo = MessageBox.Show("Selected custom iProperty:" _
& vbLf & "" & oProp_Selected _
& vbLf & "Created. Do you want To Select again ?", " Select AGAIN! ", MessageBoxButtons.YesNo)
If oYesNo = vbYes Then 
	oIndex_X = oCustProps_Availble_To_Copy.IndexOf(oProp_Selected)
	oCustProps_Availble_To_Copy.Remove(oCustProps_Availble_To_Copy(oIndex_X))
	GoTo L_oProp_Selected :
End If

 

0 Likes

I revised the rule a little bit: it removes the item selected from the list (diminishing list) so that I don't have to re-selected what I selected already.

 

L_oProp_Selected:
oProp_Selected = InputListBox("Prompt", oCustProps_Availble_To_Copy, oCustProps_Availble_To_Copy(0), Title := "Title", ListName := "List")

	    Dim oDerPro As Inventor.Property
	    Try
	        oDerPro = oProps_DerivedPart(oProp_Selected)
	    Catch
	        oDerPro = oProps_DerivedPart.Add("", oProp_Selected)
	    End Try
	    oDerPro.Value = oProp_Selected

oYesNo = MessageBox.Show("Selected custom iProperty:" _
& vbLf & "" & oProp_Selected _
& vbLf & "Created. Do you want To Select again ?", " Select AGAIN! ", MessageBoxButtons.YesNo)
If oYesNo = vbYes Then 
	oIndex_X = oCustProps_Availble_To_Copy.IndexOf(oProp_Selected)
	oCustProps_Availble_To_Copy.Remove(oCustProps_Availble_To_Copy(oIndex_X))
	GoTo L_oProp_Selected :
End If

 

Message 4 of 9

RoyWickrama_RWEI
Advisor
Advisor

I would vote. Could you provide me with the link.

0 Likes

I would vote. Could you provide me with the link.

Message 5 of 9

chandra.shekar.g
Autodesk Support
Autodesk Support

@RoyWickrama_RWEI ,

 

https://forums.autodesk.com/t5/inventor-ideas/derived-part-and-assembly-copy-i-properties/idi-p/6349... is the link referred by @bradeneuropeArthur.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



@RoyWickrama_RWEI ,

 

https://forums.autodesk.com/t5/inventor-ideas/derived-part-and-assembly-copy-i-properties/idi-p/6349... is the link referred by @bradeneuropeArthur.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 6 of 9

RoyWickrama_RWEI
Advisor
Advisor

Thanks for the reply.

I voted.

Somehow, I got my rule developed and it is fine now:

 

Sub main()
	'https://forums.autodesk.com/t5/inventor-forum/custom-iproperties-carrying-over-to-derived-components/td-p/8414311
	'https://forums.autodesk.com/t5/inventor-customization/ilogic-add-custom-property-and-value-to-selected-assembly-parts/td-p/8381018
	'https://forums.autodesk.com/t5/inventor-customization/ilogic-arraylist-acting-strange/td-p/3805800
	
Dim iL_NO As String = "002DP"
Dim iL_Name As String = "Copy Custom Property in Derived Part"
Dim iL_FullName As String = "Rule " & iL_NO & ": " & iL_Name

Dim openDoc As Document
openDoc = ThisDoc.Document
'MessageBox.Show("openDoc: " & openDoc.FullFileName, "Title")

If openDoc.DocumentType <> kPartDocumentObject Then 
	MessageBox.Show("This rule is for a part docuent only!", "File Type Mismatch!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
	Exit Sub
End If

Dim oRefFile As FileDescriptor
Dim oName_DerivedFile As Object     
Dim oFFN_DerivedParts_Array As New ArrayList
Dim oLFN_DerivedParts_Array As New ArrayList
Dim oCancel As String = "Cancel"

For Each oRefFile In openDoc.File.ReferencedFileDescriptors
oName_DerivedFile = oRefFile.FullFileName
oFFN_DerivedParts_Array.Add(oName_DerivedFile)

If oFFN_DerivedParts_Array.Count = 0 Then
MessageBox.Show("NO DERIVED PART(S) FOUND: Exit Sub!", "Title")
Exit Sub
End If	

oPosition_LFN_oRefFile = InStrRev(oName_DerivedFile, "\", - 1) 
oLFN_oRefFile = Right(oName_DerivedFile, Len(oName_DerivedFile) - oPosition_LFN_oRefFile)
'MessageBox.Show("Len(oFFN): " & Len(oFFN) _
'& vbLf & "oPosition_LFN: " & oPosition_LFN _
'& vbLf & "oLFN (Delected ref doc): " & oLFN, "SELECTED DOC")	
oLFN_DerivedParts_Array.Add(oLFN_oRefFile)
Next

oLFN_Selected_DerivedPart = InputListBox("Prompt", oLFN_DerivedParts_Array, oLFN_DerivedParts_Array(0), Title := "Title", ListName := "List")
oIndex = oLFN_DerivedParts_Array.IndexOf(oLFN_Selected_DerivedPart)

oSourceSelected_DerivedPart = oFFN_DerivedParts_Array(oIndex)
'oSourceSelected_DerivedPart = InputListBox("Prompt", oFFN_DerivedParts_Array, oFFN_DerivedParts_Array(0), Title := "Title", ListName := "List")

    Dim oDoc_CurrDerivedPart As Document
    oDoc_CurrDerivedPart = ThisApplication.ActiveDocument
    
    Dim oDerivedPartSource_Selected As Document
    oDerivedPartSource_Selected = ThisApplication.Documents.Open(oSourceSelected_DerivedPart, False)
'    MessageBox.Show("oDerivedPartSource_Selected: " & oDerivedPartSource_Selected.FullFileName, "Title")

    Copy_iProperties_Sub(oDerivedPartSource_Selected, oDoc_CurrDerivedPart)

    ' Skip save
    oDerivedPartSource_Selected.Close(True)
iLogicVb.UpdateWhenDone = True

End Sub

Sub Copy_iProperties_Sub(ByVal oDerivedPartSource_Selected As Document, ByVal oDoc_CurrDerivedPart As Document)
oFFN = oDerivedPartSource_Selected.FullFileName
oPosition_LFN = InStrRev(oFFN, "\", - 1) 
oLFN = Right(oFFN, Len(oFFN) - oPosition_LFN)
'MessageBox.Show("Len(oFFN): " & Len(oFFN) _
'& vbLf & "oPosition_LFN: " & oPosition_LFN _
'& vbLf & "oLFN (Delected ref doc): " & oLFN, "SELECTED DOC")
	
Dim to_PropertySet As PropertySet
to_PropertySet = oDoc_CurrDerivedPart.PropertySets.Item("Inventor User Defined Properties")

Dim from_PropertySet As PropertySet
from_PropertySet = oDerivedPartSource_Selected.PropertySets.Item("Inventor User Defined Properties")

Dim oProps_DerivedPart As PropertySet = oDoc_CurrDerivedPart.PropertySets.Item("Inventor User Defined Properties")
Dim oProps_SelectedSource As PropertySet = oDerivedPartSource_Selected.PropertySets.Item("Inventor User Defined Properties")

Dim oCustProps_Availble_To_Copy As New ArrayList

Dim oProList() As String = {"*" }	'"CMF_DESGINATION", "OTHER_iPRO"} 'Use "*" to copy all iPros
'Dim oProList() As String = {"Finished_Length_1", "OTHER_iPRO" }
Dim oProp_RefDoc As Inventor.Property
Dim oDerPro As Inventor.Property
	'For Each oProp_RefDoc As Inventor.Property In oProps_SelectedSource
	For Each oProp_RefDoc In oProps_SelectedSource
	    Dim oSkip As Boolean = True
	    For Each oProp_oProList As String In oProList
'			MessageBox.Show("oProp_oProList: " & oProp_oProList _
'			& vbLf & "oProp_RefDoc.Name:" & oProp_RefDoc.Name _
'			& vbLf & "oProp_RefDoc.Name: " & oProp_RefDoc.Value, "Title")
	        If UCase(oProp_oProList) <> UCase(oProp_RefDoc.Name) And oProp_oProList <> "*" Then Continue For
	        oSkip = False
	        Exit For
	    Next
'		MessageBox.Show("oSkip: " & oSkip, "Title")
	    If oSkip = True Then Continue For
'		MessageBox.Show("iProp found in (Ref. doc): " & oLFN _
'		& vbLf & "oProp_RefDoc.Name: " & oProp_RefDoc.Name, "Title")
		oCustProps_Availble_To_Copy.Add(oProp_RefDoc.Name)
	Next

Dim oList_NeedToDo As New ArrayList
oCopyAll = "Copy all from Reference Document"
oCopySelected = "Copy Only Selected"
oList_NeedToDo.Add(oCopyAll)
oList_NeedToDo.Add(oCopySelected)
oInput_NeedToDo = InputListBox("Prompt", oList_NeedToDo, oList_NeedToDo(1), Title := "Title", ListName := "List")
If oInput_NeedToDo = oCopySelected Then
	L_oProp_Selected:
	oProp_Selected = InputListBox("Prompt", oCustProps_Availble_To_Copy, oCustProps_Availble_To_Copy(0), Title := "Title", ListName := "List")
'    Dim oDerPro As Inventor.Property
    Try
        oDerPro = oProps_DerivedPart(oProp_Selected)
    Catch
        oDerPro = oProps_DerivedPart.Add("", oProp_Selected)
    End Try
    oDerPro.Value = oProp_RefDoc.Value		'oProp_Selected.Value
	
	oYesNo = MessageBox.Show("Selected custom iProperty:" _
	& vbLf & "" & oProp_Selected _
	& vbLf & "Created. Do you want To Select again ?", " Select AGAIN! ", MessageBoxButtons.YesNo)
	If oYesNo = vbYes Then 
		oIndex_X = oCustProps_Availble_To_Copy.IndexOf(oProp_Selected)
		oCustProps_Availble_To_Copy.Remove(oCustProps_Availble_To_Copy(oIndex_X))
		GoTo L_oProp_Selected :
	End If
Else If oInput_NeedToDo = oCopyAll Then
	For Each oProp_RefDoc In oProps_SelectedSource
	    Try
	        oDerPro = oProps_DerivedPart(oProp_RefDoc.Name)
	    Catch
	        oDerPro = oProps_DerivedPart.Add("", oProp_RefDoc.Name)
	    End Try
	    oDerPro.Value = oProp_RefDoc.Value
	Next oProp_RefDoc
End If

End Sub
0 Likes

Thanks for the reply.

I voted.

Somehow, I got my rule developed and it is fine now:

 

Sub main()
	'https://forums.autodesk.com/t5/inventor-forum/custom-iproperties-carrying-over-to-derived-components/td-p/8414311
	'https://forums.autodesk.com/t5/inventor-customization/ilogic-add-custom-property-and-value-to-selected-assembly-parts/td-p/8381018
	'https://forums.autodesk.com/t5/inventor-customization/ilogic-arraylist-acting-strange/td-p/3805800
	
Dim iL_NO As String = "002DP"
Dim iL_Name As String = "Copy Custom Property in Derived Part"
Dim iL_FullName As String = "Rule " & iL_NO & ": " & iL_Name

Dim openDoc As Document
openDoc = ThisDoc.Document
'MessageBox.Show("openDoc: " & openDoc.FullFileName, "Title")

If openDoc.DocumentType <> kPartDocumentObject Then 
	MessageBox.Show("This rule is for a part docuent only!", "File Type Mismatch!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
	Exit Sub
End If

Dim oRefFile As FileDescriptor
Dim oName_DerivedFile As Object     
Dim oFFN_DerivedParts_Array As New ArrayList
Dim oLFN_DerivedParts_Array As New ArrayList
Dim oCancel As String = "Cancel"

For Each oRefFile In openDoc.File.ReferencedFileDescriptors
oName_DerivedFile = oRefFile.FullFileName
oFFN_DerivedParts_Array.Add(oName_DerivedFile)

If oFFN_DerivedParts_Array.Count = 0 Then
MessageBox.Show("NO DERIVED PART(S) FOUND: Exit Sub!", "Title")
Exit Sub
End If	

oPosition_LFN_oRefFile = InStrRev(oName_DerivedFile, "\", - 1) 
oLFN_oRefFile = Right(oName_DerivedFile, Len(oName_DerivedFile) - oPosition_LFN_oRefFile)
'MessageBox.Show("Len(oFFN): " & Len(oFFN) _
'& vbLf & "oPosition_LFN: " & oPosition_LFN _
'& vbLf & "oLFN (Delected ref doc): " & oLFN, "SELECTED DOC")	
oLFN_DerivedParts_Array.Add(oLFN_oRefFile)
Next

oLFN_Selected_DerivedPart = InputListBox("Prompt", oLFN_DerivedParts_Array, oLFN_DerivedParts_Array(0), Title := "Title", ListName := "List")
oIndex = oLFN_DerivedParts_Array.IndexOf(oLFN_Selected_DerivedPart)

oSourceSelected_DerivedPart = oFFN_DerivedParts_Array(oIndex)
'oSourceSelected_DerivedPart = InputListBox("Prompt", oFFN_DerivedParts_Array, oFFN_DerivedParts_Array(0), Title := "Title", ListName := "List")

    Dim oDoc_CurrDerivedPart As Document
    oDoc_CurrDerivedPart = ThisApplication.ActiveDocument
    
    Dim oDerivedPartSource_Selected As Document
    oDerivedPartSource_Selected = ThisApplication.Documents.Open(oSourceSelected_DerivedPart, False)
'    MessageBox.Show("oDerivedPartSource_Selected: " & oDerivedPartSource_Selected.FullFileName, "Title")

    Copy_iProperties_Sub(oDerivedPartSource_Selected, oDoc_CurrDerivedPart)

    ' Skip save
    oDerivedPartSource_Selected.Close(True)
iLogicVb.UpdateWhenDone = True

End Sub

Sub Copy_iProperties_Sub(ByVal oDerivedPartSource_Selected As Document, ByVal oDoc_CurrDerivedPart As Document)
oFFN = oDerivedPartSource_Selected.FullFileName
oPosition_LFN = InStrRev(oFFN, "\", - 1) 
oLFN = Right(oFFN, Len(oFFN) - oPosition_LFN)
'MessageBox.Show("Len(oFFN): " & Len(oFFN) _
'& vbLf & "oPosition_LFN: " & oPosition_LFN _
'& vbLf & "oLFN (Delected ref doc): " & oLFN, "SELECTED DOC")
	
Dim to_PropertySet As PropertySet
to_PropertySet = oDoc_CurrDerivedPart.PropertySets.Item("Inventor User Defined Properties")

Dim from_PropertySet As PropertySet
from_PropertySet = oDerivedPartSource_Selected.PropertySets.Item("Inventor User Defined Properties")

Dim oProps_DerivedPart As PropertySet = oDoc_CurrDerivedPart.PropertySets.Item("Inventor User Defined Properties")
Dim oProps_SelectedSource As PropertySet = oDerivedPartSource_Selected.PropertySets.Item("Inventor User Defined Properties")

Dim oCustProps_Availble_To_Copy As New ArrayList

Dim oProList() As String = {"*" }	'"CMF_DESGINATION", "OTHER_iPRO"} 'Use "*" to copy all iPros
'Dim oProList() As String = {"Finished_Length_1", "OTHER_iPRO" }
Dim oProp_RefDoc As Inventor.Property
Dim oDerPro As Inventor.Property
	'For Each oProp_RefDoc As Inventor.Property In oProps_SelectedSource
	For Each oProp_RefDoc In oProps_SelectedSource
	    Dim oSkip As Boolean = True
	    For Each oProp_oProList As String In oProList
'			MessageBox.Show("oProp_oProList: " & oProp_oProList _
'			& vbLf & "oProp_RefDoc.Name:" & oProp_RefDoc.Name _
'			& vbLf & "oProp_RefDoc.Name: " & oProp_RefDoc.Value, "Title")
	        If UCase(oProp_oProList) <> UCase(oProp_RefDoc.Name) And oProp_oProList <> "*" Then Continue For
	        oSkip = False
	        Exit For
	    Next
'		MessageBox.Show("oSkip: " & oSkip, "Title")
	    If oSkip = True Then Continue For
'		MessageBox.Show("iProp found in (Ref. doc): " & oLFN _
'		& vbLf & "oProp_RefDoc.Name: " & oProp_RefDoc.Name, "Title")
		oCustProps_Availble_To_Copy.Add(oProp_RefDoc.Name)
	Next

Dim oList_NeedToDo As New ArrayList
oCopyAll = "Copy all from Reference Document"
oCopySelected = "Copy Only Selected"
oList_NeedToDo.Add(oCopyAll)
oList_NeedToDo.Add(oCopySelected)
oInput_NeedToDo = InputListBox("Prompt", oList_NeedToDo, oList_NeedToDo(1), Title := "Title", ListName := "List")
If oInput_NeedToDo = oCopySelected Then
	L_oProp_Selected:
	oProp_Selected = InputListBox("Prompt", oCustProps_Availble_To_Copy, oCustProps_Availble_To_Copy(0), Title := "Title", ListName := "List")
'    Dim oDerPro As Inventor.Property
    Try
        oDerPro = oProps_DerivedPart(oProp_Selected)
    Catch
        oDerPro = oProps_DerivedPart.Add("", oProp_Selected)
    End Try
    oDerPro.Value = oProp_RefDoc.Value		'oProp_Selected.Value
	
	oYesNo = MessageBox.Show("Selected custom iProperty:" _
	& vbLf & "" & oProp_Selected _
	& vbLf & "Created. Do you want To Select again ?", " Select AGAIN! ", MessageBoxButtons.YesNo)
	If oYesNo = vbYes Then 
		oIndex_X = oCustProps_Availble_To_Copy.IndexOf(oProp_Selected)
		oCustProps_Availble_To_Copy.Remove(oCustProps_Availble_To_Copy(oIndex_X))
		GoTo L_oProp_Selected :
	End If
Else If oInput_NeedToDo = oCopyAll Then
	For Each oProp_RefDoc In oProps_SelectedSource
	    Try
	        oDerPro = oProps_DerivedPart(oProp_RefDoc.Name)
	    Catch
	        oDerPro = oProps_DerivedPart.Add("", oProp_RefDoc.Name)
	    End Try
	    oDerPro.Value = oProp_RefDoc.Value
	Next oProp_RefDoc
End If

End Sub
Message 7 of 9

RoyWickrama_RWEI
Advisor
Advisor
Accepted solution

The rule is attached.

The rule is attached.

Message 8 of 9
Jesper_S
in reply to: RoyWickrama_RWEI

Jesper_S
Collaborator
Collaborator

Hi.

 

Great piece of code. Works like a charm. I just did a test and it also works for Inventor Summary Information and Inventor Document Summary Information but not for Design Tracking Properties.

 

It crashes on Catalog Web Link, Part Icon and Template Row. Is there a possibility to add some iProperties to an Exclude List so that it doesn't show up in the List To Select at all?


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes

Hi.

 

Great piece of code. Works like a charm. I just did a test and it also works for Inventor Summary Information and Inventor Document Summary Information but not for Design Tracking Properties.

 

It crashes on Catalog Web Link, Part Icon and Template Row. Is there a possibility to add some iProperties to an Exclude List so that it doesn't show up in the List To Select at all?


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
Message 9 of 9
RoyWickrama_RWEI
in reply to: Jesper_S

RoyWickrama_RWEI
Advisor
Advisor

Thanks for the comment. My need was to extract some custom iProperties from the reference document. Could be expanded to copy all iProperties. I will update (but I am busy for a few days, currently)

0 Likes

Thanks for the comment. My need was to extract some custom iProperties from the reference document. Could be expanded to copy all iProperties. I will update (but I am busy for a few days, currently)

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

Post to forums  

Autodesk Design & Make Report