2016 SP1

2016 SP1

Anonymous
Not applicable
968 Views
6 Replies
Message 1 of 7

2016 SP1

Anonymous
Not applicable

Hi,

 

I have a problem that is driving me insane. We have a program that was written in VBA in our office. It auotmaticallly selects an excel file and then generates drawings based on what's in the file. What we want to do is add a file explorer option so that somebody could select a file rather than having it automatically select. I have seen and tried the suggestions posted here http://forums.augi.com/showthread.php?153961-VBA-Autocad-Office-64-bit-Open-File-dialog-box-using-co..., here https://forums.autodesk.com/t5/visual-basic-customization/vba-open-file-with-dialog-box/td-p/1726554, and here http://forums.autodesk.com/t5/inventor-customization/folder-browser-needed-for-vba-7-64-bit/m-p/4365... but I am not too familier with running class modules and everytime I run those options it does nothing. It supposedly executes the code but I get no errors and no dialog box pops up. The solution I ended up finding was to use a send command and send a LISP getfiled command. This worked fine with AutoCAD 2015. It does not work with AutoCAD 2016 SP1 though. In 2016, when I run this from a drawing with a VBARUN I get "Error # -2145386296 : Invalid execution context." If I instead run this from the VBA IDE it works perfectly, no errors. Has anyone encountered a similar problem? Any other suggestions on a working file selection dialog box would also be helpful.

 

Here is the code I am running for my file dialog. The bold line throws the error.

   'Make sure users1 variable gets reset
   ThisDrawing.SendCommand "(setvar " & """users1""" & """"") "
   'Using the SendCommand method, send getfiled AutoLISP expressions to the AutoCAD command line.
   'Set the return value to a user-defined system variable USERS1.
   ThisDrawing.SendCommand "(setvar " & """users1""" & "(getfiled " & """Select a DWG File""" & """""" & """xlsm""" & "8)) "
   'Use the GetVariable method to retrieve this system variable to store the selected file name
   excelFilePath = ThisDrawing.GetVariable("users1")
0 Likes
Accepted solutions (1)
969 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

I did find that this is a sendcommand issue with 2016 SP1. https://forums.autodesk.com/t5/visual-basic-customization/using-sendcommand-twice-results-in-a-run-t... However, we need SP1 in order to have our PDF's plot correctly. (No SHX Text)

0 Likes
Message 3 of 7

Ed__Jobe
Mentor
Mentor

You should be doing those operations with the vba api and not lisp/SendCommand. The second link you mentioned has a class module that you add to your project. By itself it does nothing. You have to instantiate it and then call its methods. See my post in post 17 of that thread.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 4 of 7

Anonymous
Not applicable

Thanks for the resonse!

 

I saw that post earlier and I was trying mods of the FileDialogs that you posted.I inserted the class module and then pasted your code. My problem was that I am running 64bit not 32bit so there are errors when compiling. I then modified the class module with an If VBA7 statement. Next I tried runnning your code as shown below but when I do nothing happens. I don't get errors, or anything. It just executes and does nothing. I attached my FileDialogs to see if maybe that is the issue?

    Dim objFile As FileDialogs
    Dim strFilter As String
    Dim strFileName As String

    Set objFile = New FileDialogs
    'desc,filter combinations must all be separated with pipe char "|"
    strFilter = "All Files (*.*)|*.*|Drawings (*.dwg)|*.dwg"
    objFile.Title = "Open a drawing"
    'default dir is CurDir
    objFile.StartInDir = "c:\"
    objFile.Filter = strFilter
    'return a valid filename
    strFileName = objFile.ShowOpen
    If Not strFileName = vbNullString Then
    'use this space to perform operation
    MsgBox strFileName
    End If
    Set objFile = Nothing

Caden

0 Likes
Message 5 of 7

Ed__Jobe
Mentor
Mentor
Accepted solution

There was a small problem with the code that was posted. I updated the code and exported to a cls file. See here.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 6 of 7

Anonymous
Not applicable

Thanks for the help Ed! That solution worked really well! The only change I had to do was to modify one line. I will have to work on my searching skills.

objFile.OwnerHwnd = ThisDrawing.HWND32
'changed to 
objFile.OwnerHwnd = ThisDrawing.HWND

 

Caden

0 Likes
Message 7 of 7

Ed__Jobe
Mentor
Mentor

You're welcome. Glad you got it working.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes