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: 

vba does not work in inventor 2020

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
rickER9UF
671 Views, 4 Replies

vba does not work in inventor 2020

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

 

Labels (1)
4 REPLIES 4
Message 2 of 5
Rene_Gerlach
in reply to: rickER9UF

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.

Message 3 of 5
WCrihfield
in reply to: rickER9UF

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

EESignature

(Not an Autodesk Employee)

Message 4 of 5
Rene_Gerlach
in reply to: rickER9UF

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"

 

Message 5 of 5
rickER9UF
in reply to: rickER9UF

Thank you Rene!! i appreciate the response

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report