Author Topic: a Suggestion  (Read 18202 times)

0 Members and 2 Guests are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: a Suggestion
« Reply #30 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

Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

MickD

  • Gator
  • Posts: 3314
  • (x-in)->[process]->(y-out)
Re: a Suggestion
« Reply #31 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...
« Last Edit: July 13, 2006, 11:28:32 PM by MickD »
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

MP

  • Seagull
  • Posts: 17479
Re: a Suggestion
« Reply #32 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.

:)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Bob Wahr

  • Guest
Re: a Suggestion
« Reply #33 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.

Bob Wahr

  • Guest
Re: a Suggestion
« Reply #34 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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: a Suggestion
« Reply #35 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. :-)
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Bob Wahr

  • Guest
Re: a Suggestion
« Reply #36 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?

MP

  • Seagull
  • Posts: 17479
Re: a Suggestion
« Reply #37 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)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Bob Wahr

  • Guest
Re: a Suggestion
« Reply #38 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.

MP

  • Seagull
  • Posts: 17479
Re: a Suggestion
« Reply #39 on: July 14, 2006, 08:36:09 AM »
exactly
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10369
Re: a Suggestion
« Reply #40 on: July 14, 2006, 08:45:04 AM »
Perhaps someone should confirm & fix the error?  :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17479
Re: a Suggestion
« Reply #41 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)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MP

  • Seagull
  • Posts: 17479
Re: a Suggestion
« Reply #42 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
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

T.Willey

  • Needs a day job
  • Posts: 5218
Re: a Suggestion
« Reply #43 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.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

jbuzbee

  • Swamp Rat
  • Posts: 833
Re: a Suggestion
« Reply #44 on: July 14, 2006, 12:23:04 PM »
James Buzbee
Windows 8