Jump to content

Passing data to VBA from the AutoCAD command line


hawstom

Recommended Posts

Hi, guys. I'm pretty new here, and I'm most of all looking for just insight on this thread. I'm working with a CAD customization that successfully used the following method to pass data from AutoLISP to VBA in version 2004:

 

In AutoLISP

(command "-vbarun" "file.dvb!module.function" "arg1" "arg2" "arg3" "arg4" "arg5")

 

In VBA

arg1 = ThisDrawing.Utility.GetString(False)

arg2 = ThisDrawing.Utility.GetString(False)

arg3 = ThisDrawing.Utility.GetString(False)

arg4 = ThisDrawing.Utility.GetString(False)

arg5 = ThisDrawing.Utility.GetString(False)

 

This approach is new to me as of today. I have also apparently discovered today that this approach doesn't work in version 2010.

 

Questions:

1. Is anybody familiar with this approach, or where the original programmer may have learned it?

 

2. Can anybody confirm that this approach stopped working somewhere along the way?

 

FYI, I realize assuming this approach is dead, I will need to pass the data via user setvar/getvars, registry entries, or files.

 

Thanks!

 

Tom

Link to comment
Share on other sites

Heh. We will see what the budget allows. I am primarily interested at the moment in confirming that this trick method they used was good, but is no longer good. My personal preference going forward would be to use ActiveX with Visual LISP.

 

Tom

Link to comment
Share on other sites

Heh. We will see what the budget allows.

 

 

Visual Studio Express, and the AutoCAD ObjectARX SDK's are *free*.

 

 

I am primarily interested at the moment in confirming that this trick method they used was good, but is no longer good.

 

 

Understood. I am relegated to using 2009 software at the moment, so I'm afraid I am not much help on this particular question.

 

My personal preference going forward would be to use ActiveX with Visual LISP.

 

 

... A man after my own heart; Visual LISP (i.e., ActiveX COM API) is my language of choice, personally. But that doesn't stop me from 'chiming in' with VBA every now and then. :wink:

 

Cheers! :beer:

Link to comment
Share on other sites

Going back a couple of steps how are arg1-arg5 originaly given a value is it by another lisp program ? Can it be re written into VBA ? Can live in the same DVB

 

If you on want 5 then maybe use the user variables users1-5 useri1-5 user1-5, Also i am sure this topic has been discussed before did you search.

Link to comment
Share on other sites

Thanks for the kind words, RenderMan. Bigal, what I decided to to is go ahead and convert everything to pass the data using users5 as a comma-delimited list I easily parsed in VBA with the Split function. I think that's probably a more respectable way to do it that the arguments hack that no longer works. And it's more "local" and fleeting than a registry write and less messy than a file write.

Link to comment
Share on other sites

Update: After considering everything, I switched directions and went with registry data storage and passing. It was just a lot easier. If I were developing for the world where I can't rely on vl-, I would probably use the User setvars or maybe even file writing, but for this in-house application, the registry seems best.

 

For good programming practice, I wrote two functions each in Visual LISP and in VBA. Replace "MYAPP" with your application or company identifier. The reason this is good programming practice is that you may later change your mind about (or be forced by new software to change) how to store and pass data. Having the "engine" in central functions not only saves you typing today, but eases your changes later.

 

Visual LISP (works great for persistent storage in Visual LISP alone too):

 

;;;SaveSetting saves a string value to the registry to be read by VBA or Visual LISP
;;;Usage: (MYAPP:SaveSetting "BasePath" (vl-file-directory (findfile "MYAPP.mnl")))
(defun MYAPP:SaveSetting (key setting)
 (vl-registry-write 
   "HKEY_CURRENT_USER\\Software\\VB and VBA Program Settings\\MYAPP\\General" 
   key 
   setting
 )
)
;;;GetSetting reads a string value from the registry as saved by VBA or Visual LISP
;;;Usage: (MYAPP:GetSetting "BasePath")
(defun MYAPP:GetSetting (key)
 (vl-registry-read 
   "HKEY_CURRENT_USER\\Software\\VB and VBA Program Settings\\MYAPP\\General" 
   key 
 )
)

VBA

'SaveSetting saves a string value to the registry to be read by VBA or Visual LISP
'Usage: SaveSetting "BasePath", "R:\AutoCAD\MYAPP"
Public Function MYAPP:SaveSetting(Key As String, Setting As String)
   SaveSetting "MYAPP", "General", Key, Setting
End Function
'GetSetting reads a string value from the registry as saved by VBA or Visual LISP
'Usage: BasePath = GetSetting("BasePath")
Public Function MYAPP:GetSetting(Key As String)
   MYAPP:GetSetting = GetSetting("MYAPP", "General", Key)
End Function

Edited by hawstom
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...