+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Lisp To Vba

  1. #1
    Senior Member
    Using
    Civil 3D 2008
    Join Date
    Feb 2008
    Posts
    294

    Default Lisp To Vba

    Guys 2009 acad has a action recoredr function - is there some way of recording what a lisp does to transform it into Vba??

    Long shot i know - but does anyone know is there some sort of interface between a lisp and vba??

    Because id like to transfer a couple of lisps into vba

  2. #2
    Luminous Being dbroada's Avatar
    Computer Details
    dbroada's Computer Details
    Operating System:
    Windows 7 Professional
    Computer:
    Dell
    CPU:
    Intel Xeon E5-1603@2,80GHz
    RAM:
    4GB
    Graphics:
    NVIDA Quadro K600
    Monitor:
    DELL 23" & SAMSUNG 21"
    Discipline
    Electro/Mech
    dbroada's Discipline Details
    Occupation
    Design Engineer
    Discipline
    Electro/Mech
    Using
    Electrical 2013
    Join Date
    Nov 2005
    Location
    Sussex, UK
    Posts
    5,503

    Default

    I can't answer the first bit as I don't have 2009 but for the second bit, I doubt it. They are completely different languages. I have had to re-write my routines to take from LISP to VBA.
    "That's it. It's one thing for a ghost to terrorize my children, but quite another for him to play my Theremin." Homer Simpson
    "Everything in drafting is logical. Except what isn’t." - Gavin Guile. (from the Lightbringer series of books by Brent Weeks)

    Dave

  3. #3
    Super Member ASMI's Avatar
    Using
    AutoCAD 2008
    Join Date
    Nov 2005
    Location
    Oceanus Procellarum, Moon
    Posts
    1,427

    Default

    At practise just every AutoCAD VBA code can translate into AutoLISP without any alhorithm changes, but you cannot translate every AutoLISP code into VBA. LISP can use all ActiveX methods and properties VBA use, otherwise VBA has't functions and data processing/storage methods use LISP. LISP is LISt Processing Language, VBA hasn't such data type as 'list' and functions to process it. If the program is written on real LISP you can't to use this algorithm for VBA, but can write the VBA-program with similar result.

  4. #4
    Senior Member
    Using
    AutoCAD 2009
    Join Date
    May 2008
    Location
    Philadelphia, Pa.
    Posts
    407

    Default

    Russell
    That is very wishful thinking
    Wouldn't that be nice?

    I have code that will allow you to pass Sting Variables and Integers between the two. VBA and LISP

    Please see the next post

  5. #5
    Senior Member
    Using
    AutoCAD 2009
    Join Date
    May 2008
    Location
    Philadelphia, Pa.
    Posts
    407

    Default

    The examples I created will hopefully get you going.
    At the bottom are the 2 needed functions
    If you have questions, feel free to ask.
    ML

    *The original source of this code came from The VLAX Class Module*

    Code:
    Sub Lisp2VBA() 'Uses The GetLispSym Function
      Dim Variable1 As String
      Dim Variable2 As String
      Dim Variable3 As String
      Dim Variable4 As String
     
     'T1 and T2 are your LISP variables
      Variable1 = GetLispSym("T1") 'At the command line, set your variable ie (setq T1 "Test1")
      Variable2 = GetLispSym("T2") 'At the command line, set your variable ie (setq T2 "Test2")
     
     'Return Values
      Debug.Print Variable1 'Should return Test1
      Debug.Print Variable2 'Should return Test2
      MsgBox Variable1 'Should return Test1
      MsgBox Variable2 'Should return Test2
     
     'Setting and retreiving multiple variables at once.
     
      'B and C are your LISP variables
      'At the command line, set your variables ie (setq B 123 C 4.7)
       Variable3 = GetLispSym("B")
       Variable4 = GetLispSym("C")
     
      'Return Values
       Debug.Print Variable3 'Should return 123
       Debug.Print Variable4 'Should return 4.7
       MsgBox Variable3 'Should return 123
       MsgBox Variable4 'Should return 4.7
     
     End Sub
     Sub VBA2Lisp() 'Uses The PutLispSym Function
      Dim Num As Integer
      Dim Txt As String
     
      Num = 120
      Txt = "String of Text"
     
     'V1 and V2 are your LISP variables
      PutLispSym "V1", Num 'At the command line, type !V1. The variable (V1) should return 120
      PutLispSym "V2", Txt 'At the command line, type !V2. The variable (V2) should return: String of Text
    End Sub
     Sub VBA2LispBack2VBA() 'Uses The Put and GetLispSym Functions combined
      Dim Num As Integer
      Dim Txt As String
      Dim Variable1 As Integer
      Dim Variable2 As String
     
      Num = 120
      Txt = "String of Text"
     
     'Int and Tx are your LISP variables
      PutLispSym "Int", Num 'Same as setting your variable (setq Int 120)at the command line
      PutLispSym "Tx", Txt 'Same as setting your variable (setq Tx "String of Text")at the command line
     
      Variable1 = GetLispSym("Int") 'Retreive the variable Int
      Variable2 = GetLispSym("Tx") 'Retreive the variable Tx
     
      'Return Values
       Debug.Print Variable1
       Debug.Print Variable2
       MsgBox Variable1
       MsgBox Variable2
     End Sub
    Code:
    Function GetLispSym(symbolName As String) As Variant 'Retrieves a variable from ACAD (LISP)
      Dim sym As Object
      Set VL = CreateObject("VL.Application.16")
      Set sym = VL.ActiveDocument.Functions.Item("read").funcall(symbolName)
      GetLispSym = VL.ActiveDocument.Functions.Item("eval").funcall(sym)
      Set VL = Nothing
      Set sym = Nothing
     End Function
     
    Function PutLispSym(symbolName As String, Value As Variant) 'Sends a variable from VBA to ACAD (LISP)
      Dim sym As Object
      Set VL = CreateObject("VL.Application.16")
      Set sym = VL.ActiveDocument.Functions.Item("read").funcall(symbolName)
      VL.ActiveDocument.Functions.Item("set").funcall sym, Value
      Set VL = Nothing
      Set sym = Nothing
     End Function

  6. #6
    Forum Deity
    Using
    Civil 3D 2013
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    4,979

    Default

    There was some time ago a lisp to C converter it rewrote the code the authors may have written a lisp to VBA the code is very similar. It requires a dictionary of lisp command = VBA command

    Try l2c lisp to c on google

  7. #7
    Senior Member
    Using
    Civil 3D 2008
    Join Date
    Feb 2008
    Posts
    294

    Default

    Thank you all - good response

    So i just supposed i'll have to simply learn VBA -
    thanks all i will delv more into the VBA world.

    Thank you kindly

  8. #8
    Senior Member
    Using
    AutoCAD 2009
    Join Date
    May 2008
    Location
    Philadelphia, Pa.
    Posts
    407

    Default

    Hi Russell

    Learning VB(A) is never a bad idea.

    I am not really a LISP guy but I have dabbled a bit in the past

    I developed the above code more out of curiosity then practicality

    While it is not a translator and you will likely not find one, the above code can be used effectively in some real examples

    For instance, in the first example, where I have:
    Dim Variable1 as String

    Variable1 = GetLispSym("T1")

    Let's suppose you did some Lisp code and used The getfiled method.

    (setq fn (getfiled "Select Block" (getvar "dwgprefix") "dwg" );

    In VBA, you could use the above to do something like this:


    Code:
    Sub BlknamefromLISP ()
     
    Dim Blkref as AcadBlockReference
    Dim blkname as String
    Dim InsPnt As Variant
     
    ThisDrawing.ActiveSpace = acModelSpace
     
    'Prompt the user to pick a point
     InsPnt = ThisDrawing.Utility.GetPoint(, "Select an insertion point")
     
    blkname = GetLispSym("fn")
     
    Set Blkref = ThisDrawing.ModelSpace.InsertBlock(InsPnt, Blkname, 1, 1, 1, 0)
     
    End Sub
    This example would work if well if you had an ACAD menu macro run a Lisp routine that you already created, that is using GetFiled to prompt a user for a block (variable fn) to be inserted, then with the same menu macro, you load and run the VBA macro with the above code in it.

    Example:
    Code:
    (load "LispProject")Blocks;^c^c-vbarun;"K:/Path/BlockProj.dvb!Blocks.BlkRef";
    In a case like that, this method would work

    If I were using The LISPtoVBA code (above), I would be more inclined to send a few variables from VBA to LISP so that I could use them at the command line in ACAD.

    It just all just depends on what you are doing specifically.

    Good Luck

    ML

  9. #9
    Senior Member
    Using
    AutoCAD 2009
    Join Date
    May 2008
    Location
    Philadelphia, Pa.
    Posts
    407

    Default

    Actually, in that example, it would be somethinng like this:

    Code:
    (load "LispProject")Blocks;^c^c-vbarun;"K:/Path/BlockProj.dvb!Blocks.BlknamefromLISP";

  10. #10
    Senior Member
    Using
    Civil 3D 2008
    Join Date
    Feb 2008
    Posts
    294

    Default

    Registered forum members do not see this ad.

    hey thanks for that - ive been using it and looking into the vba..

    thanks for you extensive reply mate - it has gotten me off to a good start with VBA.

    Cheers

Similar Threads

  1. problem, trying to running a list of lisp from within a lisp
    By twind2000 in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 20th Aug 2007, 04:27 pm
  2. calling another lisp from within my lisp
    By thalon in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 22nd Feb 2006, 09:56 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts