Message 1 of 5
To Change Reference Document in Derived part
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I was using the rule shown below some times ago.
When I use it today, it does not do any thing: the derived reference is not replaced with the document selected. I spent so much time without success.
Could someone help.
Thanks.
Public Sub Main()
Dim iL_NO As String = "0004DP"
Dim iL_Name As String = "Replace Derived Part Refeence"
Dim iL_FullName As String = iL_NO & ": " & iL_Name
Dim openDoc As Document
openDoc = ThisDoc.Document
'MessageBox.Show("openDoc: " & openDoc.FullFileName, iL_FullName)
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!", iL_FullName)
Exit Sub
End If
oPosition_LFN_oRefFile = InStrRev(oName_DerivedFile, "\", - 1)
oLFN_oRefFile = Right(oName_DerivedFile, Len(oName_DerivedFile) - oPosition_LFN_oRefFile)
oLFN_DerivedParts_Array.Add(oLFN_oRefFile)
Next
'oLFN: Local File Name
oLFN_Selected_DerivedPart = InputListBox("Prompt", oLFN_DerivedParts_Array, oLFN_DerivedParts_Array(0), Title := iL_FullName, ListName := "LIST OF REFERENCE DOCS")
oIndex = oLFN_DerivedParts_Array.IndexOf(oLFN_Selected_DerivedPart)
oReferenceDoc_of_Selected_DerivedPart = oFFN_DerivedParts_Array(oIndex)
oReplace_DP(oReferenceDoc_of_Selected_DerivedPart)
iLogicVb.UpdateWhenDone = True
End Sub
Sub oReplace_DP(ByVal oReferenceDoc_of_Selected_DerivedPart As String)
Dim oThisActiveDoc As PartDocument = ThisApplication.ActiveEditDocument
Dim oThisActiveDerivedDoc As PartDocument = ThisApplication.ActiveEditDocument 'Use where applicable
Dim oThisActiveDocDef As PartComponentDefinition = oThisActiveDoc.ComponentDefinition
Dim oDoc As Document
oDoc = ThisDoc.Document
Dim oRefFile As FileDescriptor
Dim oOrigRefName As Object
For Each oRefFile In oDoc.File.ReferencedFileDescriptors
'get the full file path to the original internal references
oOrigRefName = oRefFile.FullFileName
If oRefFile.FullFileName = oReferenceDoc_of_Selected_DerivedPart Then
'If oRefFile = oReferenceDoc_of_Selected_DerivedPart Then
'present a File Selection dialog
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.InitialDirectory = oOrigRefName
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
Return
ElseIf oFileDlg.FileName <> "" Then
selectedfile = oFileDlg.FileName
End If
MessageBox.Show("oRefFile: " & oRefFile.FullFileName _
& vbLf & "selectedfile " & selectedfile, iL_FullName)
'Replace the reference
oRefFile.ReplaceReference(selectedfile)
End If
Next
InventorVb.DocumentUpdate()
'oOrigRefName = “”
iLogicVb.UpdateWhenDone = True
End Sub
