Exchanging info between VB-VLisp-VB

Exchanging info between VB-VLisp-VB

Anonymous
Not applicable
995 Views
20 Replies
Message 1 of 21

Exchanging info between VB-VLisp-VB

Anonymous
Not applicable
I have many programs in Visual Lisp and I would like to add some VB to them. I need to read visual lisp lists in my VB program and I don't know how to do it.

Any help?
0 Likes
996 Views
20 Replies
Replies (20)
Message 2 of 21

Anonymous
Not applicable
One way would be to use Frank Oquendo's Vlax Class. This allows you to access lisp functions & symbols. It has been posted here numerous times. If you can't find it, post back and I'll see if I still have the zip file here. -- Jeff check out www.cadvault.com "Yvon" wrote in message news:3813363.1106949924166.JavaMail.jive@jiveforum2.autodesk.com... >I have many programs in Visual Lisp and I would like to add some VB to >them. I need to read visual lisp lists in my VB program and I don't know >how to do it. > > Any help?
0 Likes
Message 3 of 21

Anonymous
Not applicable
I have not tried the vlax class, but when trying to mix the two, I make dll's of my VB code and call them in process. I know you want to read the global vars in an acad session which is different. I think you should consider writing info to a text file with your lisp as a go-between. Its an odd thing because you can make dll's with VB, but not with lisp. Curious to see what you decide. Yvon |>I have many programs in Visual Lisp and I would like to add some VB to them. I need to read visual lisp lists in my VB program and I don't know how to do it. |> |>Any help? James Maeding jmaeding at hunsaker dot com Civil Engineer/Programmer
0 Likes
Message 4 of 21

Anonymous
Not applicable
Hi Yvon In addition to the other answers: You can build an interface to 'transport' the values from/to... - Single values by system vars USERI1-5 USERR1-5 or USERS1-5 - For complex informations use dictionaries This sample shows you how to do it with system vars: [code] ; ; == Function MeMsgBox ; Displays the VBA MsgBox. ; Arguments [Type]: ; Pmt = Prompt [STR] ; But = Buttons [INT] *) ; Tit = Title [STR] ; Return [Type]: ; > Return value [INT] *) ; Notes: ; *) Details see VBA help, for LISP use the 'vlax-' prefix. ; (defun MeMsgBox (Pmt But Tit) (setvar "USERS1" Pmt) (setvar "USERS2" Tit) (setvar "USERI1" But) (vl-vbarun "YourVba.dvb!MacroFunctions.ShowMsgBox") (getvar "USERI1") ) ' VBA Macro (in modul 'MacroFunctions') ' Sub ShowMsgBox() With ThisDrawing .SetVariable "USERI1", MsgBox(.GetVariable("USERS1"), _ .GetVariable("USERI1"), _ .GetVariable("USERS2")) End with End Sub [/code] Sample: (MeMsgBox "This is a test." (+ vlax-vbOKOnly vlax-vbInformation) "Title") Cheers -- Juerg Menzi MENZI ENGINEERING GmbH, Switzerland http://www.menziengineering.ch
0 Likes
Message 5 of 21

Anonymous
Not applicable
Hi "Jürg, Just in case some other program is relying on data from the User group, would not it be a good idea to append your value to the current value with a unique divider and remove the additional data after reading it. psuedo code only. eg (setvar "USERS1" (strcat (getvar "USERS1") "|||" Pmt) And at the far end. sTmp = Getvariable ("USER1") vTmp = Split (sTmp, "|||") SetVariable "USER1" vTmp(0) TransferredVariable = vTmp(1) -- Regards, Laurie Comerford www.cadapps.com.au "Jürg Menzi" wrote in message news:41FB67FD.D2103130@menziengineering.ch... > Hi Yvon > > In addition to the other answers: > > You can build an interface to 'transport' the values from/to... > - Single values by system vars USERI1-5 USERR1-5 or USERS1-5 > - For complex informations use dictionaries > > This sample shows you how to do it with system vars: > [code] > ; > ; == Function MeMsgBox > ; Displays the VBA MsgBox. > ; Arguments [Type]: > ; Pmt = Prompt [STR] > ; But = Buttons [INT] *) > ; Tit = Title [STR] > ; Return [Type]: > ; > Return value [INT] *) > ; Notes: > ; *) Details see VBA help, for LISP use the 'vlax-' prefix. > ; > (defun MeMsgBox (Pmt But Tit) > (setvar "USERS1" Pmt) > (setvar "USERS2" Tit) > (setvar "USERI1" But) > (vl-vbarun "YourVba.dvb!MacroFunctions.ShowMsgBox") > (getvar "USERI1") > ) > > ' VBA Macro (in modul 'MacroFunctions') > ' > Sub ShowMsgBox() > > With ThisDrawing > .SetVariable "USERI1", MsgBox(.GetVariable("USERS1"), _ > .GetVariable("USERI1"), _ > .GetVariable("USERS2")) > End with > > End Sub > [/code] > > Sample: > (MeMsgBox "This is a test." (+ vlax-vbOKOnly vlax-vbInformation) "Title") > > Cheers > -- > Juerg Menzi > MENZI ENGINEERING GmbH, Switzerland > http://www.menziengineering.ch
0 Likes
Message 6 of 21

Anonymous
Not applicable
"Jeff Mishler" wrote in message news:41fae3e3_3@newsprd01... > One way would be to use Frank Oquendo's Vlax Class. This allows you to access lisp functions & symbols. It has been > posted here numerous times. If you can't find it, post back and I'll see if I still have the zip file here. It would be nice if we didn't represent third party tools that are nothing but 'wrappers' around already existing functionality, as essential. The Visual LISP ActiveX API is readily accessable from any language without the need for any wrapper. Learning to use the core functionality directly can have benefits in the long run. -- http://www.caddzone.com AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005 http://www.acadxtabs.com
0 Likes
Message 7 of 21

Anonymous
Not applicable
My advice is to use Visual Basic (not VBA), and develop your code as ActiveX servers, which you can call from Visual LISP. -- http://www.caddzone.com AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005 http://www.acadxtabs.com "Yvon" wrote in message news:3813363.1106949924166.JavaMail.jive@jiveforum2.autodesk.com... >I have many programs in Visual Lisp and I would like to add some VB to them. I need to read visual lisp lists in my VB >program and I don't know how to do it. > > Any help?
0 Likes
Message 8 of 21

Anonymous
Not applicable
"Laurie Comerford" wrote > Hi "Jürg, > > Just in case some other program is relying on data from the User group, would not it be a good idea to append your > value to the current value with a unique divider and remove the additional data after reading it. > > psuedo code only.... I have to take exception to promoting this sort of hacking. If there were no other way to do what the subject line seeks to do, I would not condemn it in the stongest possible terms, but given the broad range of alternatives, this is about as horrible as it gets. -- http://www.caddzone.com AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005 http://www.acadxtabs.com
0 Likes
Message 9 of 21

Anonymous
Not applicable
"Tony Tanzillo" wrote > > The Visual LISP ActiveX API is readily accessable from > any language without the need for any wrapper. > > Learning to use the core functionality directly can > have benefits in the long run. > Would you care to share so I might learn? In all of the posts with this, or similar, question, I have not seen any response from you, or anyone else, as to how this may be done. Say I have my "xtraspecial.lsp" that I have been using since Eisenhower was president, it works great and sets a global var named "*xtra_spcl_var*" that contains a list of dotted pairs. How can I access the data in this var in my new VBA project? Thanks, Jeff
0 Likes
Message 10 of 21

Anonymous
Not applicable
Hi Tony, You may be surprised that I agree with you that it's a kludge as are several of the obvious ways of swapping data between lisp and VBA, but if it is done, then better to do it safely. The other thing for you to realise is that you have an extraordinary knowlege of customising AutoCAD. Most (if any) users do not have your skills, or the time and intellect to develop them. Unfortunately you tend to keep your skills secret - usualy preferring to present them as criticism of others' attempts to solve problems from their personal range of experience an knowledge. A positive response would have been to publish an elegant method of swapping variable values between Lisp and VBA. If users can get a kludge to work and meet their needs, then they are happy. In general they are not faced with the implications of making sure the code works in all situations. -- Regards, Laurie Comerford www.cadapps.com.au "Tony Tanzillo" wrote in message news:41fbe9ec_1@newsprd01... > "Laurie Comerford" wrote >> Hi "Jürg, >> >> Just in case some other program is relying on data from the User group, >> would not it be a good idea to append your value to the current value >> with a unique divider and remove the additional data after reading it. >> >> psuedo code only.... > > I have to take exception to promoting this sort of > hacking. If there were no other way to do what the > subject line seeks to do, I would not condemn it in > the stongest possible terms, but given the broad > range of alternatives, this is about as horrible as it > gets. > > > -- > http://www.caddzone.com > > AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005 > http://www.acadxtabs.com > >
0 Likes
Message 11 of 21

Anonymous
Not applicable
Jeff Mishler wrote: > Would you care to share so I might learn? No need for Tony to share; I already did. The utility you mentioned is a plain text file, readily accessible to anyone who cares to delve into how it works. However, it's silly to balk at the idea of using components in our code when VB and VBA are almost entirely component based. Indeed, that's the idea behind ActiveX in general. The real issue, rather than the red herring presented, is when it is appropriate to use thid-party tools. As a rule of thumb, avoid any closed-source solution not offered by a reputable company with a longstanding, respected reputation. Shareware and freeware authors, myself included, are free to abandon or radically alter their offerings at any time, leaving you without a tool which has become a key component in your coding efforts. Always look for an option to acquire the source, even if the component is free. About the only exception is wrappers for well-documented processes such as CommonDialog control replacements and such. The only time you should ever set these guidelines aside is when you simply need something *now*. -- There are 10 kinds of people: those who understand binary and those who don't.
0 Likes
Message 12 of 21

Anonymous
Not applicable
Yvon wrote: > I have many programs in Visual Lisp and I would like to add some VB to them. I need to read visual lisp lists in my VB program and I don't know how to do it. You have lots of options, including text files, system variables and the registry. I prefer to use VisualLISP itself to tansfer information between LISP and VBA. Attached is a wrapper for the VisualLISP ActiveX interface. It puts a friendly face on an existing API created by Autodesk for just such a task. Once you've added vlax.cls to your project, you use it like this: ' Assumes you have a global list named "lst" Dim obj As VLAX, myList Set obj = New VLAX myList = obj.GetLispList("lst") The var myList now contains an array of elements read from your LISP symbol. There are limits to what the class can do so if you choose to use it, be sure to read the notes in the header. -- There are 10 kinds of people: those who understand binary and those who don't.
0 Likes
Message 13 of 21

Anonymous
Not applicable
"Laurie Comerford" wrote: > The other thing for you to realise is that you have an extraordinary knowlege of customising AutoCAD. Most (if any) > users do not have your skills, or the time and intellect to develop them. > Sorry to disagree. Doing things the right way requires no 'extraordinary' knowledge of AutoCAD. It may require a modest understanding of good/sound programming concepts, principles, and practices, and the common sense to see the pitfalls of kludges like this, before you fall into them. In this case, it doesn't take a guru to see that transferring data via strings, requires the data to be converted to- and from strings, and it requires enough sense to realize that there are things that may need to be transferred (such as entity names, selection sets, etc.), which cannot persist in string form. So, given those simple to understand limitations, I can see no legitmate argument in defense of taking such an unsound and inherintly limited approach to begin with. It doesn't take a guru to see how many hoops VBA users have to jump through to use the SendCommand() kludge, since that also suffers from the same limitations (everything must be a string), except that in the case of SendCommand(), the VBA programmer can compose LISP expressions as a way of passing things that can't be persisted directly in string form. (Kludge on top of Kludge). If the sophistication of the tools you want to develop require this kind of communication wiith LISP, then you've already outgrown VBA, and should just accept that, and the fact that its probably time to think about using a 'grown up' programming system (such as a VB based ActiveX servers).
0 Likes
Message 14 of 21

Anonymous
Not applicable
"Jeff Mishler" wrote > Would you care to share so I might learn? In all of the posts with this, or similar, question, I have not seen any > response from you, or anyone else, as to how this may be done. > There's been quite a few posts here on how to use VL.Application and its aggregates, although I don't know if they're all available. More importantly, I would recommend avoiding that in any case, and just do it the right way (Okay, to me, the 'right way' means not using VBA to begin with, and instead using VB to build ActiveX dlls that you can control directly and in a more supported way, from LISP). One thing that we should all agree on, is that Microsoft very deliberately designed VBA to be limited and easily 'outgrown', to support sales of VB and other programming tools. I don't really see any good purpose in trying to 'buck' that concept and do things with VBA, that it was deliberately designed to not do. -- http://www.caddzone.com AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005 http://www.acadxtabs.com
0 Likes
Message 15 of 21

Anonymous
Not applicable
While I don't disagree with your asessment, I believe your perspective is one not shared by most people in this group. You make your living writing software. Most of us make our living drafting and program as a means to the end of making our drafting operations more efficient and standards compiant. Whether VBA was designed to do something doesn't really matter so long as it *can* do that something since it represents one of the tools readily available to every AutoCAD user. -- There are 10 kinds of people: those who understand binary and those who don't.
0 Likes
Message 16 of 21

Anonymous
Not applicable
Hi Laurie > Just in case some other program is relying on data from the User group, > would not it be a good idea to append your value to the current value with a > unique divider and remove the additional data after reading it. First of all, the USERxn sysvars shouldn't be used as globals. It would be a bad practice to rely on 'untouched' USERxn's. However, everyone has the freedom to reset the variables to the original values: [code] (defun MeMsgBox (Pmt But Tit / RetVal VarLst) (setq VarLst (mapcar 'getvar '("USERS1" "USERS2" "USERI1"))) (setvar "USERS1" Pmt) (setvar "USERS2" Tit) (setvar "USERI1" But) (vl-vbarun "YourVba.dvb!MacroFunctions.ShowMsgBox") (setq RetVal (getvar "USERI1")) (mapcar '(lambda (s v) (setvar s v)) '("USERS1" "USERS2" "USERI1") VarLst) RetVal ) [/code] Cheers -- Juerg Menzi MENZI ENGINEERING GmbH, Switzerland http://www.menziengineering.ch
0 Likes
Message 17 of 21

Anonymous
Not applicable
"Jeff Mishler" wrote > Would you care to share so I might learn? In all of the posts with this, or > similar, question, I have not seen any response from you, or anyone else, as > to how this may be done. > > Say I have my "xtraspecial.lsp" that I have been using since Eisenhower was > president, it works great and sets a global var named "*xtra_spcl_var*" that > contains a list of dotted pairs. How can I access the data in this var in my > new VBA project? You can't bring an association list across, because it has no ActiveX counterpart. A simple list of ActiveX-compatible data types can be fetched as a safearray wrapped in a variant, but forget about directly accessing association lists. In general, directly exposing variables to other modules in the same or other languages, has never been considered a sound practice, regardless of other complications. My objection to the kludge-o-rama approach that got me started in this, is that it embraces the unsound practice of directly exposing private member variables (or global LISP variables) to another API. Regardless of whether you are passing data between LISP and VBA, or not, you don't do it by attempting to directly manipulate variables in one environment from another. Instead, you define a formal interface consisting of functions that can be called from one environment, to manipulate data in the other. So, You can define a LISP functoin that takes a key and calls (assoc) and (cdr) to get a value from the association list, and returns it to its caller. That function can serve as the 'external' interface to the association list, in the same way that you write property get/let functions in VBA, rather than directly exposing an underlying member variable. See the attached files. From the command line, load the LISP file and the VBA module, and call the two public subs in the latter from the VBARUN command. Then, from the command line, inspect the value of the LISP association list. -- http://www.caddzone.com AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005 http://www.acadxtabs.com
0 Likes
Message 18 of 21

Anonymous
Not applicable
Have a look at the code in Frank's class and you should be able to work it out.
Regards - Nathan
0 Likes
Message 19 of 21

Anonymous
Not applicable
Great Frank! It's probably what I was looking for. I will give a try tomorrow.

Thanks
0 Likes
Message 20 of 21

Anonymous
Not applicable
Thanks Tony! I will try this for sure. I like your approach to this problem. So, if it is working from vba it should also be working from vb?

Thanks again
0 Likes