VBA help

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
I found the below code at Mod the Machine , Thanks to Brian Ekins
http://modthemachine.typepad.com/my_weblog/2016/01/open-drawing-from-a-part-or-assembly.html
I do not know any think about VBA ,so help is needed
Because When running a debug it stops at:
Set partDoc = ThisApplication.ActiveDocument
Can anyone tell me if I am doing some think wrong or what is wrong
I use the VBA Editor in Inventor 2017
""""""""""""""""""""""""""""""""""""""""""""
Public Sub FindDrawingTest()
Dim partDoc As PartDocument
Set partDoc = ThisApplication.ActiveDocument
' Call the function to get the drawing.
Dim drawingFilename As String
drawingFilename = FindDrawingFile(partDoc)
' Display the result.
If drawingFilename <> "" Then
MsgBox "The drawing for """ & partDoc.fullFilename & """ was found: " & vbCr & drawingFilename
Else
MsgBox "No drawing was found for """ & partDoc.fullFilename & """"
End If
End Sub
' Find the drawing for the specified part of assembly.
Private Function FindDrawingFile(PartOrAssemblyDoc As Document)
Dim fullFilename As String
fullFilename = PartOrAssemblyDoc.fullFilename
' Extract the path from the full filename.
Dim path As String
path = Left$(fullFilename, InStrRev(fullFilename, "\"))
' Extract the filename from the full filename.
Dim filename As String
filename = Right$(fullFilename, Len(fullFilename) - InStrRev(fullFilename, "\"))
' Replace the extension with "dwg"
filename = Left$(filename, InStrRev(filename, ".")) & "dwg"
' Find if the drawing exists.
Dim drawingFilename As String
drawingFilename = ThisApplication.DesignProjectManager.ResolveFile(path, filename)
' Check the result.
If drawingFilename = "" Then
' Try again with idw extension.
filename = Left$(filename, InStrRev(filename, ".")) & "idw"
' Find if the drawing exists.
drawingFilename = ThisApplication.DesignProjectManager.ResolveFile(path, filename)
' Return the result.
If drawingFilename <> "" Then
FindDrawingFile = drawingFilename
Else
FindDrawingFile = ""
End If
Else
' Return the result.
FindDrawingFile = drawingFilename
End If
End Function
"""""""""""""""""""""""