- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Step-1: Select the desired reference document
Step-2: Select the desired custom iProperty. Can I select more from this list?
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
Solved! Go to Solution.