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: 

How to get FileDescriptor from a selectset?

5 REPLIES 5
Reply
Message 1 of 6
saseendrankombath
583 Views, 5 Replies

How to get FileDescriptor from a selectset?

 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.

5 REPLIES 5
Message 2 of 6

May you post more details?

 

Can you post a sample code?

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 3 of 6

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

 

Message 4 of 6

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



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 5 of 6

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"

 

Message 6 of 6

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



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------

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

Post to forums  

Autodesk Design & Make Report