I want to replace one reference out of multiple reference files used in a part document. How can I convert a selectset.item(1) to a FileDescriptor object.
May you post more details?
Can you post a sample code?
Bregs
Rossano Praderi
I am able to replace all referenced files if I use the code inside For... Next
For Each oOrgRefFile In oPartDoc.File.ReferencedFileDescriptors Next
and a particular one by giving the sequence number of referenced file.
oOrgRefFile = oPartDoc.File.ReferencedFileDescriptors.Item(2)
for the above I have to modify th code every time to give the sequence number. I want to avoid the same by selecting the required referenced file by selecting from the browser node.
below is the full code I am using
Private Sub Replace_Ref_Part_BtnDef_OnExecute(ByVal Context As Inventor.NameValueMap) Handles btnReplace_Ref_Part_BtnDef.OnExecute Try Dim oPartDoc As PartDocument oPartDoc = m_inventorApplication.ActiveDocument Dim oOrgRefFile As Inventor.FileDescriptor Dim oOrigRefName As Object Dim oNewRefFile As Object = Nothing 'For Each oOrgRefFile In oPartDoc.File.ReferencedFileDescriptors oOrgRefFile = oPartDoc.File.ReferencedFileDescriptors.Item(2) oOrigRefName = oOrgRefFile.FullFileName Dim oFileDlg As Inventor.FileDialog = Nothing m_inventorApplication.CreateFileDialog(oFileDlg) oFileDlg.InitialDirectory = oOrigRefName oFileDlg.CancelError = True Try oFileDlg.ShowOpen() Catch ex As Exception MsgBox(ex.Message) End Try If oFileDlg.FileName <> "" Then oNewRefFile = oFileDlg.FileName End If oOrgRefFile.ReplaceReference(oNewRefFile) oOrigRefName = "" MsgBox("Reference replaced sucessfully with selected File") 'Next Catch ex As Exception MsgBox("Unable to replace the Selected file, Please make sure the replacement file has the same database ID", MsgBoxStyle.Information, "Replace Reference Part") End Try
Hi saseendrakombath,
this function read the fullfilename of the first selected item.
Private Sub Replace_Ref_Part() Try Dim oPartDoc As PartDocument oPartDoc = m_inventorApplication.ActiveDocument 'Dim oOrgRefFile As Inventor.FileDescriptor Dim oOrigRefName As Object Dim oNewRefFile As Object = Nothing 'For Each oOrgRefFile In oPartDoc.File.ReferencedFileDescriptors 'oOrgRefFile = oPartDoc.File.ReferencedFileDescriptors.Item(2) 'oOrigRefName = oOrgRefFile.FullFileName oOrigRefName = GetSelectedItem() Dim oFileDlg As Inventor.FileDialog = Nothing m_inventorApplication.CreateFileDialog(oFileDlg) oFileDlg.InitialDirectory = oOrigRefName oFileDlg.CancelError = True Try oFileDlg.ShowOpen() Catch ex As Exception MsgBox(ex.Message) End Try If oFileDlg.FileName <> "" Then oNewRefFile = oFileDlg.FileName End If oOrgRefFile.ReplaceReference(oNewRefFile) oOrigRefName = "" MsgBox("Reference replaced sucessfully with selected File") 'Next Catch ex As Exception MsgBox("Unable to replace the Selected file, Please make sure the replacement file has the same database ID", MsgBoxStyle.Information, "Replace Reference Part") End Try End Sub Function GetSelectedItem() As String doc As Document = ThisApplication.ActiveDocument Dim bp As BrowserPane = doc.BrowserPanes.ActivePane Dim node As BrowserNode For Each node In bp.TopNode.BrowserNodes If node.Selected Then GetSelectedItem = node.NativeObject.ReferencedFileDescriptor.FullFileName Exit Function End If Next End Function
Bregs
Rossano Praderi
node.NativeObject.ReferencedFileDescriptor.FullFileName
nativeobject dosent have any method or property (ReferencedFiledescripter)
the above code returns an error " Object dosen't support this property or method"
I've checked and adapted the code.
Sub Main Call Replace_Ref_Part() End Sub Private Sub Replace_Ref_Part() Try Dim oOrgRefFile As Inventor.FileDescriptor oOrgRefFile = GetSelectedItems If oOrgRefFile Is Nothing Then Exit Sub Dim oFileDlg As Inventor.FileDialog = Nothing ThisApplication.CreateFileDialog(oFileDlg) oFileDlg.InitialDirectory = oOrgRefFile.FullFileName oFileDlg.CancelError = True Try oFileDlg.ShowOpen() Catch ex As Exception MsgBox(ex.Message) End Try If oFileDlg.FileName <> "" Then oOrgRefFile.ReplaceReference(oFileDlg.FileName) End If MsgBox("Reference replaced sucessfully with selected File") Catch ex As Exception MsgBox("Unable to replace the Selected file, Please make sure the replacement file has the same database ID", MsgBoxStyle.Information, "Replace Reference Part") End Try End Sub Function GetSelectedItems() As Inventor.FileDescriptor doc = ThisApplication.ActiveDocument GetSelectedItems = Nothing bp = doc.BrowserPanes.Item("Model") For Each node In bp.TopNode.BrowserNodes If node.Selected Then GetSelectedItems = node.NativeObject.ReferencedDocumentDescriptor.ReferencedFileDescriptor Exit Function End If Next End Function
Anyway, was not my code to give all the errors.
Bregs
Rossano Praderi