i have the below code with a button that exports a drawing to dwf in one click, works great in 2014 however just got 2020 and the program is catching in the red text line.........any ideas would be great as this command is quick and handy, thank you
Sub dwfmaker()
MsgBox "DWF-filer creating", vbInformation
Dim invApp As Inventor.Application
Set invApp = ThisApplication
' invApp.SilentOperation = True
Dim idwDoc As Inventor.DrawingDocument
Set idwDoc = invApp.ActiveDocument
Dim dwfFile As String
Dim laserdir As String
Dim FirstLet As Variant
Dim Output As Integer
Dim MyCheck As String
FirstLet = Left(idwDoc.DisplayName, 1)
MyCheck = IsNumeric(FirstLet)
If MyCheck = True Then
laserdir = "x:\" + "Numbered" + "\"
Else
laserdir = "x:\" + FirstLet + "\"
End If
dwfFile = laserdir + idwDoc.DisplayName + ".dwf"
'determine of dwf already exists
Dim FilePath As String
FilePath = ""
FilePath = Dir(dwfFile)
If FilePath = "" Then
'MsgBox "File doesn't exist"
Output = MsgBox("File Doesn't Exist", vbOKCancel)
'If Output = 1 Then
With invApp.CommandManager
Call .PostPrivateEvent(kFileNameEvent, dwfFile)
Call .StartCommand(kFileSaveCopyAsCommand)
End With
Set idwDoc = Nothing
Else
Output = MsgBox("File Exists", vbOKCancel)
Output = 2
End If
If Output = 2 Then
Output = MsgBox("Do You Want To Overwrite Existing File?", vbYesNoCancel)
End If
If Output = 6 Then
With invApp.CommandManager
Call .PostPrivateEvent(kFileNameEvent, dwfFile)
Call .StartCommand(kFileSaveCopyAsCommand)
End With
ElseIf Output = 7 Then
Else
Output = 2
End If
End Sub
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
From Inv2009(!) documentation:
Note 2. The CommandManager.StartCommand (commandID) method to launch in Inventor command has been depreciated. Please use the ControlDefinition.Execute method instead.
See if this edit works for you instead:
(I replaced your 'With' blocks with a simple SaveAs() method.)
Sub dwfmaker()
MsgBox "DWF-filer creating", vbInformation
Dim invApp As Inventor.Application
Set invApp = ThisApplication
' invApp.SilentOperation = True
Dim idwDoc As Inventor.DrawingDocument
Set idwDoc = invApp.ActiveDocument
Dim dwfFile As String
Dim laserdir As String
Dim FirstLet As Variant
Dim Output As Integer
Dim MyCheck As String
FirstLet = Left(idwDoc.DisplayName, 1)
MyCheck = IsNumeric(FirstLet)
If MyCheck = True Then
laserdir = "x:\" + "Numbered" + "\"
Else
laserdir = "x:\" + FirstLet + "\"
End If
dwfFile = laserdir + idwDoc.DisplayName + ".dwf"
'determine of dwf already exists
Dim FilePath As String
FilePath = ""
FilePath = Dir(dwfFile)
If FilePath = "" Then
'MsgBox "File doesn't exist"
Output = MsgBox("File Doesn't Exist", vbOKCancel)
Call idwDoc.SaveAs(dwfFile, True) 'True = SaveCopyAs
Set idwDoc = Nothing
Else
Output = MsgBox("File Exists", vbOKCancel)
Output = 2
End If
If Output = 2 Then
Output = MsgBox("Do You Want To Overwrite Existing File?", vbYesNoCancel)
End If
If Output = 6 Then
Call idwDoc.SaveAs(dwfFile, True) 'True = SaveCopyAs
ElseIf Output = 7 Then
Else
Output = 2
End If
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.
If you have time, please... Vote For My IDEAS :light_bulb:and Explore My CONTRIBUTIONS
Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield
(Not an Autodesk Employee)
Just a comment:
Please never ever use the DisplayName for the filename! The DisplayName can contain characters that are not allowed for filenames, like "/\<:|".
Try instead:
Dim fso As New Scripting.FileSystemObject
dwfFile = laserdir + fso.GetBaseName(idwDoc.FullFileName) + ".dwf"
Can't find what you're looking for? Ask the community or share your knowledge.