TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Visual DCL Programming => Topic started by: jbuzbee on June 22, 2006, 07:04:07 PM

Title: a Suggestion
Post by: jbuzbee on June 22, 2006, 07:04:07 PM
Since we have this nice ObjectDCL child baord, and since the end of ObjectDCL is nigh - I think this board could also include posts about Hybrid Apps.  I've had little problem using VBA forms in the exact same way I used ObjectDCL.  Only use VBA to control the form and use one of the VL application interfaces that are floating around to communicate with lisp( I posted a great bit of code by Tony Tanzillo over on the show me board).

So I'll be checking in and if I can help anyone convert an ODCL app over to Hybrid I'll be happy to lend a hand as time allows.

jb
Title: Re: a Suggestion
Post by: Kerry on June 23, 2006, 12:07:23 AM
Good idea James.
Title: Re: a Suggestion
Post by: nivuahc on June 23, 2006, 07:06:33 AM
Very good idea indeed
Title: Re: a Suggestion
Post by: T.Willey on June 26, 2006, 02:08:40 PM
James,

  Could you supply a little blurb of how you did this?  I was thinking the next time I write a routine that needed a dialog (don't know when this will be) I would go this route, but am not sure how to even get started since I don't know any VBA.

Could you store the information for/from the VBA form in a dictionary (temporary of not) and then put/grab it from lisp?  Or am I way off?

Thanks, (anyone can answer if they have ideas).
Title: Re: a Suggestion
Post by: jbuzbee on June 26, 2006, 03:08:44 PM
Dictionaries, Registry, Users Sysvars and Lisp Variables are all ways VBA and Lisp can communicate.  I like to use the latter because it's the exact same way ObjectDCL and lisp interact.  Do a search for the code I posted by Tony Tanzillo that defines 3 subs for VBA: setLispVar, getLispVar, and EvalLispExpression.  I use these over the vlax.cls: I had some errors with the latter.  I know there is probably a slicker way but I just add this code in each project.  Once I get time I'll learn how to load it once and access it (like loading a (defun . .))

Lets say you want a user to select an item from a listbox and use that as a variable in a lisp:

Code: [Select]
layer = ListBox1.List(ListBox1.ListIndex)
SetLispVar "jb%LayerSelectName", layer

In that particular case I have the lisp call the VBA form and then check to see if the variable "jb%LayerSelectName" is set.  In the following example I set 2 variables "jb%workingState" and "jb%WSXref" then use the sendcommand method to execute the lisp routine (this could also be done with 'EvalLispExpression).  You can see where I was setting the user variables before I found Tony's stuff.

Code: [Select]
index1 = ListBox1.ListIndex
index2 = ListBox2.ListIndex

If index1 > -1 Then
ws = ListBox1.List(ListBox1.ListIndex)
End If

If index2 > -1 Then
dwg = ListBox2.List(ListBox2.ListIndex)
End If

'ThisDrawing.SetVariable "users2", ws
SetLispVar "jb%WorkingState", ws

'ThisDrawing.SetVariable "users1", dwg
SetLispVar "jb%WSXref", dwg


ThisDrawing.SendCommand _
"(jb:VBA_WorkingStatesForm_Restore)" & vbCr

Really all you need to learn about VBA are the functions to control the forms (and of course you'll learn - and subsequently do - more in VBA as time goes by).  If you want any simple examples - or help - let me know.
Title: Re: a Suggestion
Post by: T.Willey on June 26, 2006, 03:18:29 PM
Thanks James for the heads up, and examples.  I will look more into this when I have some time.
Title: Re: a Suggestion
Post by: raghumn on June 27, 2006, 11:50:30 PM
Hi JamesBuzbee,

Please excuse me of my foolishness. I could not find where (did not understand what it is) the 'show me board'. Could you get the link here for my help?

Thanks,

MNRaghu
Title: Re: a Suggestion
Post by: Serge J. Gianolla on June 28, 2006, 01:05:39 AM
Hi JamesBuzbee,

Please excuse me of my foolishness. I could not find where (did not understand what it is) the 'show me board'. Could you get the link here for my help?

Thanks,

MNRaghu

MNRaghu,
It is actually called Show your stuff and I think you have to be logged in to see it.
Title: Re: a Suggestion
Post by: raghumn on June 28, 2006, 03:51:58 AM
Serge J. Gianolla,

Thanks for the clue. I got it!

MNRaghu
Title: Re: a Suggestion
Post by: GDF on June 29, 2006, 02:22:23 PM
James

I am interested. This should make a good topic. I for one know little about vba....am willing to learn.
VBA is so far aboue me, that I cannot see the bottom.

Gary
Title: Re: a Suggestion
Post by: jbuzbee on June 29, 2006, 10:48:39 PM
Gary.  I think the best way to approach this is by control: just like ObjectDCL.  ListBox, DropDown, TreeView, Buttons, Toggle, TextBox, and Labels I have code for.  BlockView, ListView, DwgView are going to ne a little tougher.  VBA is basic ( no pun intended ) stuff.  You can do just about anything with it: it's the roots of codeing.

Modal and Modeless are no problem: re-sizable looks to be a whole lot of code!!!

Don't worry though - we'll muddle through it.

jb

BTW - let me know what you need.
Title: Re: a Suggestion
Post by: Bob Wahr on June 30, 2006, 10:51:18 AM
re-sizable looks to be a whole lot of code!!!
Resizable is super simple and not a lot of code.  Make a userform called userform1.  Put 2 command buttons and give this a go.
Code: [Select]
Private Sub CommandButton1_Click()
UserForm1.Width = 400
UserForm1.Height = 500
End Sub

Private Sub CommandButton2_Click()
UserForm1.Width = 100
UserForm1.Height = 100
End Sub
Title: Re: a Suggestion
Post by: GDF on June 30, 2006, 10:54:17 AM
Gary.  I think the best way to approach this is by control: just like ObjectDCL.  ListBox, DropDown, TreeView, Buttons, Toggle, TextBox, and Labels I have code for.  BlockView, ListView, DwgView are going to ne a little tougher.  VBA is basic ( no pun intended ) stuff.  You can do just about anything with it: it's the roots of codeing.

Modal and Modeless are no problem: re-sizable looks to be a whole lot of code!!!

Don't worry though - we'll muddle through it.

jb

BTW - let me know what you need.

James

For me, baby steps. I learn best from coping the masters. Simple little examples to begin with.

Gary
Title: Re: a Suggestion
Post by: Bob Wahr on June 30, 2006, 10:54:47 AM
Now that I posted that, I'm guessing you meant dragging the window with the mouse so never mind.
Title: Re: a Suggestion
Post by: jmaeding on July 12, 2006, 08:22:14 PM
Lets walk through a hybrid app with modeless VBA dialog, I'd like to get comments on my thoughts:
1) lisp starts, it gathers data and stores in lisp variables, then runs VBA dialog.
To run dialog, use (vbastmt...).

2) VBA dialog gets opened and uses Tony's functions to access lisp variables to fill its controls in during form_initialize event.  Any strings or data should be prepared as lisp vars ahead of time.

3) VBA dialog is open with controls ready to be picked, the events of those controls are programmed to run lisp functions (or possibly modify lisp variables) using Tony's function.

4) If lisp function is run from VBA form, say from a button click to get a point, does VBA form get focus back if user hits escape?  How does VBA form get focus back (main issue I care about...)

5) VBA form is closed, does lisp continue on?

6) with modeless VBA form, how do I update controls of the form from lisp?  If I could tell the form to run a function (method), that would be enough.  Do I use the same old activex techniques, where the form is an object that I run methods and set properties on?  If I did that, I could give the form properties, and have it use that instead of getting values from lisp vars.

The thing of passing lots of data to a form, then getting it back when done is an issue in VB/VBA.  For the more complicated dialogs, I have always programmed the forms so they have properties.  Then I fill the props in before the show event.  Then I get the props back after hiding, but before unloading the form.

I am mainly worried about focus issues though.  Getting focus back to a form when a lisp function is done, or back to a lisp, when the form is done, is very important.
thanks
Title: Re: a Suggestion
Post by: MickD on July 12, 2006, 09:35:47 PM
Is Tony's code open to see how variables are being passed back and forth?
If so, could someone decipher it for me as I'm severely lisp challenged :).
If you know how to get data back and forth, controlling focus can be controlled (by passing other data say).

Luis cut his teeth in arx passing lisp var's back and forth, the big help there though was that arx gives you a 'signature' prefix to add to functions that you wish to do this with, this was 'ads_*****'. Perhaps it can be done with .net as well??
Title: Re: a Suggestion
Post by: jbuzbee on July 13, 2006, 07:35:46 AM
James,

1 & 2) Correct, except to run a form from lisp I use:

Code: [Select]
(defun c:jbkeynotesdialog  (/ kfile)
  (if (and (setq kfile (jb:GetKeynoteFile nil)) (findfile "jbForms.dvb"))
    (progn
      (setq jb%KeyFile kfile)
      (vl-vbarun "jbForms.dvb!FormControl.jbKeyNotesForm")
      ))
  (princ)
  (princ))

In the above example I'm also setting 'jb%KeyFile to a string of a file for the VBA form to open and read:

Code: [Select]
Public Sub jbKeyNotesFormRefresh()
KeyNotes.ListBox2.Clear
On Error GoTo ErrMessage
Dim file As String, str As String

file = GetLispVar("jb%KeyFile")

If Not file = "" Then
Open file For Input As #1
Do While Not EOF(1)
    Input #1, str
    KeyNotes.ListBox2.AddItem (str)
Loop
Close #1
    End If
ErrMessage:
    Close #1
    Exit Sub
End Sub

3) A double click event from the same form sets a lisp variable and then fires a lisp function:

Code: [Select]
Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim str As String
Dim index As Integer
index = ListBox2.ListIndex

Me.AcFocusCtrl1.KeepFocus = False

If index > -1 Then
str = ListBox2.List(ListBox2.ListIndex)
SetLispVar "jb%KeyInfo", str
EvalLispExpression ("(jbPlaceKeynote)")
End If
End Sub

4) Note the "Me.AcFocusCtrl1.KeepFocus = False" call in the sub above - this is a modeless form, it's a keynoting routine.  There is an activeX control "AcFocus" floating around that maintains the focus on a modeless form.  It's a bit trickey but switching focus can be done.

5) yes

6)  What I do is set up Sub functions in a module that only deal with the controls I want updated.  You could just run the initialize method, but if you have a big form, or only want to update parts then break it up into different subs.  The following is from a modeless, no titlebar, rolled-up, transparent form that handles two differnt routines in a multi-page control (tabs):

Code: [Select]
Public Sub ViewInit()
jbToolPalette.VListBox.Clear
Dim viewname As String
Dim view As AcadView
For Each entry In ThisDrawing.Views
jbToolPalette.VListBox.AddItem entry.Name
Next
End Sub

From lisp this would be called as:

Code: [Select]
(vl-vbarun "jbForms.dvb!FormControl.ViewInit")
This sub is actually called from a Document Event sub (reactor) 'CommandEnded for when the user edits views with the AutoCAD -view and view commands:  (In the "ThisDrawing" module)

Code: [Select]
Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
If CommandName Like "-VIEW" Then
FormControl.ViewInit
End If
If CommandName Like "VIEW" Then
FormControl.ViewInit
End If
If CommandName Like "XREF" Then
FormControl.LSInit
End If
End Sub

For the ObjectDCL equivelent of 'OnDocument_Activated I just use another Document Event sub:

Code: [Select]
Private Sub AcadDocument_Activate()
    FormControl.ViewInit
    FormControl.LSInit
    FormControl.jbKeyNotesFormRefresh
    FormControl.editLSInit
End Sub

And finally, a moment of zen:
Rolled Up -
(http://www.vpiarchitecture.com/images/1-up.jpg)


Just pick a tab:


(http://www.vpiarchitecture.com/images/1.jpg)


Notice the scroller at the bottom for adjusting transparency?

Hope this helps.

jb
Title: Re: a Suggestion
Post by: LE on July 13, 2006, 11:10:46 AM
Luis cut his teeth in arx passing lisp var's back and forth,

 :-)

Do not know, but I am going to use a new word I learn here (@theSwamp) "party pooper"... Why not moving/learning/etc.... into a much powerful programming language?.... why keeping the idea of mix lisp-vba ?

Many are going the C# route, others ObjectARX, and the C++ foundation in there..... Why not all the effort you guys are doing into trying to come up with a mixer or workarounds, put it into a more profitable programming future and how about the ones that work doing programming for living, it will give you more power and foundation for your self.....

The Visual Studio Pro Edition is just 800 dollars and an update 550 plus minus..... a worth spent.

C++/MFC/WinApi/ARX/C# are not to difficult - appears to be, it is required dedication, reading, a lot of research work, but I bet it is the same time spent to learn any other language.......... We have here some of our members experienced with those languages (as always) willing to answer any question(s).....

Just my own personal point of view (sorry).
Title: Re: a Suggestion
Post by: CAB on July 13, 2006, 12:53:39 PM
James, Very nice results. Keep up the good work.

Luis
I think this was an effort to keep using LISP & make up for the loss of ObjectDCL.
Can NET be used to create the dialogs needed AND communicate with lisp?
Forgive my ignorance if this is a silly question.
Title: Re: a Suggestion
Post by: LE on July 13, 2006, 01:05:28 PM
I think this was an effort to keep using LISP & make up for the loss of ObjectDCL.

Yep I know that Alan; I was an user of ObjectDCL... I have a license of the product, now abandoned....

Quote
Can NET be used to create the dialogs needed AND communicate with lisp?

Yes.... as the same you can do with ARX (and it is seriously EASY)
Title: Re: a Suggestion
Post by: CAB on July 13, 2006, 01:12:17 PM
Is NET version dependent like VBA is? That is do you have to recompile for each ACAD version?
What does NET produce a dll or do you compile on-the-fly like lisp?
Title: Re: a Suggestion
Post by: LE on July 13, 2006, 01:17:21 PM
I can say only about ObjectARX (that's what I use now) it is per Acad version... (I have my VS2005 & A2007 still on the box) so, about the .NET (C#) I'll wait for someone that really knows to answer that....
Title: Re: a Suggestion
Post by: TR on July 13, 2006, 01:43:03 PM
Is NET version dependent like VBA is? That is do you have to recompile for each ACAD version?
What does NET produce a dll or do you compile on-the-fly like lisp?

1) .NET is version dependent.

2) .NET produces a dll which you load via the NETLOAD command or via the system registry.
Title: Re: a Suggestion
Post by: jbuzbee on July 13, 2006, 01:54:43 PM
Luis, I hear what your saying and I agree, however:

I'm up and running in VBA in about 2 weeks.  Could I be as proficient in C++ in that time?  I doubt it.

Don't get me wrong - for AutoCAD that's the only way to go - and by getting some exposure to VBA my mind is already developing to the point that I think another language would be easier.  However, this is the only slowdown in work I can see us having for the next 3 years which is why I decided to abandoned ODCL and develope VBA forms.   Heck, by that time we'll probably all be using Revit!

jb
Title: Re: a Suggestion
Post by: LE on July 13, 2006, 02:20:47 PM
Luis, I hear what your saying and I agree, however:

I'm up and running in VBA in about 2 weeks.  Could I be as proficient in C++ in that time?  I doubt it.

Don't get me wrong - for AutoCAD that's the only way to go - and by getting some exposure to VBA my mind is already developing to the point that I think another language would be easier.  However, this is the only slowdown in work I can see us having for the next 3 years which is why I decided to abandoned ODCL and develope VBA forms.   Heck, by that time we'll probably all be using Revit!

jb

Well.... at least I tried....... no problem.
Title: Re: a Suggestion
Post by: jbuzbee on July 13, 2006, 03:55:22 PM
Luis, please don't be offended!  I'd love to learn C++.  I'm a designer however, not a programmer.  I started all this stuff to "sharpen" my tool of choice: AutoCAD.  If I ever get the luxery of time to start you can bet I'll look to you, and this site, for help!

 ;-)

jb
Title: Re: a Suggestion
Post by: LE on July 13, 2006, 04:07:35 PM
Jim;

I lately just write and try learn new languages simple for the fan of it, and to keep my few cells left busy, that's the main reason I kept doing programming.... and at the same time (as you and many others) found this great site, where I can learn/share/spent a lot of my free time.....  (and no I am not offended at all  :-))

ps... I do (as maybe you) architectural work for living....


Take care.

Title: Re: a Suggestion
Post by: MickD on July 13, 2006, 06:51:48 PM
The reason I ask and suggest .net is how long will AutoCAD support vba now that .net is available??
While .net app's are version dependent the amount of re work to update would be negligable, winforms will be doing the grunt work, you won't be using the .net arx/Interop much if at all. In fact, you could create an visual editor and all sorts of goodies which would/may not be possible with vba.

food for thought!
Title: Re: a Suggestion
Post by: Kerry on July 13, 2006, 09:11:08 PM
The reason I ask and suggest .net is how long will AutoCAD support vba now that .net is available??
.....   food for thought!


Without a crystal ball it's anyone's guess ... but that is one of the reasons I won't be putting any effort into VBA development.
The Office suites now use Visual Studio for apps .. if thats any indicator.

The next couple of years will be interesting, to say the least.

James, I think I may have said this previously, but in case I only thought it, I think the project you have initiated is a great idea and full credit to you.
Title: Re: a Suggestion
Post by: MickD on July 13, 2006, 09:22:50 PM
...

James, I think I may have said this previously, but in case I only thought it, I think the project you have initiated is a great idea and full credit to you.


ditto that.

I think there are 2 important points that have/will come out of all this.
1) If you do any type of programming, don't get too dependent on any lib's UNLESS you know how to work without them!
2) There is always another way to get something done, while building a vba alternative is the path of least resistance - at this time - I think a good alternative is to create and interface between lisp and whatever and thus enabling you do do your UI in the language of your choice. This is what .net is all about.

Would I be correct in assuming that data is being passed back and forth using a xdictionary record? If so is this efficient enough? If not would it be a good idea??
Title: Re: a Suggestion
Post by: Kerry on July 13, 2006, 09:34:40 PM
Mick, this is the original code posting

Written by Tony Tanzillo sometime in the beginning of the 21st Century . . .

Code: [Select]
Private vlapp As Object
Private vlFuncs As Object

Public Function EvalLispExpression(lispStatement As String)

    Dim sym As Object, RET As Object, retVal
   
    Set vlapp = CreateObject("Vl.Application.16")
    Set vlFuncs = vlapp.ActiveDocument.Functions

    Set sym = vlFuncs.Item("read").funcall(lispStatement)
    On Error Resume Next
    retVal = vlFuncs.Item("eval").funcall(sym)
    If Err Then
        EvalLispExpression = ""
    Else
        EvalLispExpression = retVal
    End If

End Function

Public Sub SetLispVar(Symbol As String, Value)
'Dim vlapp As Object
'Dim vlFuncs As Object
Dim vlSet As Object
Dim vSym
Set vlapp = CreateObject("Vl.Application.16")
Set vlFuncs = vlapp.ActiveDocument.Functions
Set vSym = vlFuncs.Item("read").funcall(Symbol)
Set vlSet = vlFuncs.Item("set")
Select Case VarType(Value)
Case vbByte, vbInteger, vbLong
Dim lVal As Long
lVal = Value
vlSet.funcall vSym, lVal
Case vbString
Dim strVal As String
strVal = Value
vlSet.funcall vSym, strVal
Case vbDouble
Dim dblVal As String
dblVal = Value
vlSet.funcall vSym, dblVal
Case vbEmpty
vlSet.funcall vSym, vlFuncs.Item("read").funcall("nil")
Case Else
If IsArray(Value) Then
Dim List As Variant
List = Value
vlSet.funcall vSym, List
Else
vlSet.funcall vSym, Value
End If
End Select
End Sub

Public Function GetLispVar(Symbol As String) As Variant
'Dim vlapp As Object
'Dim vlFuncs As Object
Set vlapp = CreateObject("Vl.Application.16")
Set vlFuncs = vlapp.ActiveDocument.Functions
GetLispVar = vlFuncs.Item("eval").funcall(vlFuncs.Item("read").funcall(Symbol))
End Function

Here are some example uses:

Code: [Select]
If index1 > -1 Then
ws = ListBox1.List(ListBox1.ListIndex)
End If

If index2 > -1 Then
dwg = ListBox2.List(ListBox2.ListIndex)
End If

SetLispVar "jb%WorkingState", ws
SetLispVar "jb%WSXref", dwg

Title: Re: a Suggestion
Post by: MickD on July 13, 2006, 10:07:53 PM
Thanks Kerry, all has become clear. vlisp is COM! I was thinking in pure lisp...doh!
Ok, either way, data has to be coerced (packed and unpacked) at either end, why couldn't we use a resbuf in an xrecord (a common object in all languages that customise acad) and get the real types stored and map them to the dialog being created which passes them back into the same or a results xrecord?

the system -

run a lisp function that gathers data required for the dialog.
pack the data into an xrec with a application "key" value.
use lisp to open the dialog and exit lisp.
In the forms load up, grab the xrec by this key and load up the form
on unloading the form, pack the data back to the key (replace the resbuf) and call the lisp (whose string was packed with the original data) to handle the returned values or exit quietly (for cancel say).

Just thinking out loud...
Title: Re: a Suggestion
Post by: MP on July 13, 2006, 11:24:37 PM
Whoa, interesting thread (understatement). I gotta take some time to digest it, but I'd like to contribute somehow. PS: At  quick glance looks to me like there's an error in SetLispVar (look at Case vbDouble, is that right?). Anyway, very interesting stuff. Pretty cool to see all this talent and grey matter working as one.

:)
Title: Re: a Suggestion
Post by: Bob Wahr on July 14, 2006, 12:08:04 AM
One reason IMO to keep it VBA for now is that there are many people who are pretty interesed in this project judging both by the people who have posted, here and the other thread, and the number of people guests and members alike that have been watching without posting from what I've seen on the who's online page.  The one thing that all of the interested parties have in common right now is VBA (barring anyone using pre-VBA ACAD) which can't be said about .net.  True, sharp develop is out there but is somewhat less user friendly from what I've seen.  Not everyone has the resources to buy Visual Studio and, correct me if I'm wrong, usin VS Express to develop an interface to use at work would violate the EULA.
Title: Re: a Suggestion
Post by: Bob Wahr on July 14, 2006, 12:11:25 AM
All that being said, I think that i'm going to mirror this project (or try to) in C# as a learning experience for myself.
Title: Re: a Suggestion
Post by: Kerry on July 14, 2006, 12:19:17 AM
Code: [Select]
... using VS Express to develop an interface to use at work would violate the EULA.
I have a recollection that special dispensation is available, Bob.

also .. I'd hazzard a guess that a lot more people migrate to NET than most of us imagine. .. I know that C# is a really great language to develop in, < assume VBnet is similar > . Considering that the power is <almost> on a par with C++ and the language syntax is SO much cleaner, it will make a good learner language.  ..

that being said, I don't want to start another language measuring competition ... time will tell. :-)
Title: Re: a Suggestion
Post by: Bob Wahr on July 14, 2006, 12:33:54 AM
I have a recollection that special dispensation is available, Bob.
I will look into that.

Quote
I'd hazzard a guess that a lot more people migrate to NET than most of us imagine
I have no doubt about that myself.  I personally think that a .net solution is probably in the long term a better solution but a VBA solution most likely won't be obsolete for a few years at least.  Personally, I would be more than happy to change languages on it if someone wanted to take over the class in a C#ly manner and more importantly that the majority of the people who have expressed interest in the VBA class said that they wanted to change.  It would be more beneficial to me as a device to learn C# but I am more than happy to help where I can as well.

Why do I feel like I have been typing for 5 minutes without actually saying anything?
Title: Re: a Suggestion
Post by: MP on July 14, 2006, 07:41:17 AM
Whoa, interesting thread (understatement). I gotta take some time to digest it, but I'd like to contribute somehow. PS: At  quick glance looks to me like there's an error in SetLispVar (look at Case vbDouble, is that right?). Anyway, very interesting stuff. Pretty cool to see all this talent and grey matter working as one.

Anyone? Bueller?

(well off to work me goes)
Title: Re: a Suggestion
Post by: Bob Wahr on July 14, 2006, 08:19:16 AM
Agree that it definitely appears by looking that Dim dblVal as Double would make the monkeys that ride around in the wee hours going mmmchichimmmchi spank the tiny lizards way much before Dim dblVal as String.
Title: Re: a Suggestion
Post by: MP on July 14, 2006, 08:36:09 AM
exactly
Title: Re: a Suggestion
Post by: CAB on July 14, 2006, 08:45:04 AM
Perhaps someone should confirm & fix the error?  :-)
Title: Re: a Suggestion
Post by: MP on July 14, 2006, 08:54:07 AM
Changing it to --

Code: [Select]
Case vbDouble
    Dim dblVal As Double
    dblVal = Value
    vlSet.funcall vSym, dblVal

Would put it right imo.

Tho I wonder why that technique is used instead of --

Code: [Select]
Case vbDouble : vlSet.funcall vSym, CDbl(Value)
Title: Re: a Suggestion
Post by: MP on July 14, 2006, 09:19:29 AM
The more I look at that function the more it doesn't look like it was penned by TT -- it's a bit scenic for him.

An alternate --

Code: [Select]
Public Sub SetLispVar(Symbol As String, Value as Variant)

    Dim vlSet As Object, _
        vsym  As Variant
    Set vlapp = CreateObject("Vl.Application.16")
    Set vlFuncs = vlapp.ActiveDocument.Functions
    Set vsym = vlFuncs.Item("read").funcall(Symbol)
    Set vlSet = vlFuncs.Item("set")
    Select Case VarType(Value)
        Case vbByte, vbInteger, vbLong: vlSet.funcall vsym, CLng(Value)
        Case vbString: vlSet.funcall vsym, CStr(Value)
        Case vbDouble: vlSet.funcall vsym, CDbl(Value)
        Case vbEmpty: vlSet.funcall vsym, vlFuncs.Item("read").funcall("nil")
        Case Else: vlSet.funcall vsym, IIf(IsArray(Value), CVar(Value), Value)
    End Select

End Sub
Title: Re: a Suggestion
Post by: T.Willey on July 14, 2006, 12:12:40 PM
So I was looking at maybe studying Common Lisp (clisp) as a .Net language, would that work with AutoCad?  I was doing this just because maybe the syntax would be the same as lisp is, so maybe the learning curve won't be as bad.
Title: Re: a Suggestion
Post by: jbuzbee on July 14, 2006, 12:23:04 PM
MP here's where I found it:

http://discussion.autodesk.com/thread.jspa?messageID=387610

jb
Title: Re: a Suggestion
Post by: MP on July 14, 2006, 12:37:51 PM
Thanks James. I remember that thread now. I believe the genesis of the idea (accessing the VL application from VB) originates with Cyrille Fauvel, not the two sparring in that thread (most of which Anne Brown nuked).
Title: Re: a Suggestion
Post by: TR on July 14, 2006, 02:05:55 PM
So I was looking at maybe studying Common Lisp (clisp) as a .Net language, would that work with AutoCad?  I was doing this just because maybe the syntax would be the same as lisp is, so maybe the learning curve won't be as bad.

I suggest you take an hour or two of your time and look into boo (http://boo.codehaus.org/). If that doesn't look to bad you can develop AutoCAD apps in it.
Title: Re: a Suggestion
Post by: T.Willey on July 14, 2006, 03:07:37 PM
So I was looking at maybe studying Common Lisp (clisp) as a .Net language, would that work with AutoCad?  I was doing this just because maybe the syntax would be the same as lisp is, so maybe the learning curve won't be as bad.

I suggest you take an hour or two of your time and look into boo (http://boo.codehaus.org/). If that doesn't look to bad you can develop AutoCAD apps in it.
Thanks Tim.  I will have to look at that tonight, kind of busy at work today.
Title: Re: a Suggestion
Post by: FengK on January 03, 2007, 01:48:25 PM
Can anyone confirm if one can use language like Python to achieve what Tony T did using VBA? I did some testing using Python to interact with vl16.tlb without success.  I always got an error saying "Error in dll".
Thanks.

Mick, this is the original code posting

Written by Tony Tanzillo sometime in the beginning of the 21st Century . . .

Code: [Select]
Private vlapp As Object
Private vlFuncs As Object

Public Function EvalLispExpression(lispStatement As String)

    Dim sym As Object, RET As Object, retVal
   
    Set vlapp = CreateObject("Vl.Application.16")
    Set vlFuncs = vlapp.ActiveDocument.Functions

    Set sym = vlFuncs.Item("read").funcall(lispStatement)
    On Error Resume Next
    retVal = vlFuncs.Item("eval").funcall(sym)
    If Err Then
        EvalLispExpression = ""
    Else
        EvalLispExpression = retVal
    End If

End Function

Public Sub SetLispVar(Symbol As String, Value)
'Dim vlapp As Object
'Dim vlFuncs As Object
Dim vlSet As Object
Dim vSym
Set vlapp = CreateObject("Vl.Application.16")
Set vlFuncs = vlapp.ActiveDocument.Functions
Set vSym = vlFuncs.Item("read").funcall(Symbol)
Set vlSet = vlFuncs.Item("set")
Select Case VarType(Value)
Case vbByte, vbInteger, vbLong
Dim lVal As Long
lVal = Value
vlSet.funcall vSym, lVal
Case vbString
Dim strVal As String
strVal = Value
vlSet.funcall vSym, strVal
Case vbDouble
Dim dblVal As String
dblVal = Value
vlSet.funcall vSym, dblVal
Case vbEmpty
vlSet.funcall vSym, vlFuncs.Item("read").funcall("nil")
Case Else
If IsArray(Value) Then
Dim List As Variant
List = Value
vlSet.funcall vSym, List
Else
vlSet.funcall vSym, Value
End If
End Select
End Sub

Public Function GetLispVar(Symbol As String) As Variant
'Dim vlapp As Object
'Dim vlFuncs As Object
Set vlapp = CreateObject("Vl.Application.16")
Set vlFuncs = vlapp.ActiveDocument.Functions
GetLispVar = vlFuncs.Item("eval").funcall(vlFuncs.Item("read").funcall(Symbol))
End Function

Here are some example uses:

Code: [Select]
If index1 > -1 Then
ws = ListBox1.List(ListBox1.ListIndex)
End If

If index2 > -1 Then
dwg = ListBox2.List(ListBox2.ListIndex)
End If

SetLispVar "jb%WorkingState", ws
SetLispVar "jb%WSXref", dwg