Author Topic: Invoke LISP  (Read 4008 times)

0 Members and 1 Guest are viewing this topic.

Odoshi

  • Guest
Invoke LISP
« on: December 31, 2011, 11:04:28 AM »
Hi,

I am trying to invoke LISP, such as:

Dim args As ResultBuffer = New ResultBuffer()

args.Add(New TypedValue(5005, "c:wd_retag_update_noprompts"))
args.Add(New TypedValue(5005, "nil"))
args.Add(New TypedValue(5005, sSymbol_Name))

Dim rbRes As ResultBuffer = Autodesk.AutoCAD.ApplicationServices.Application.Invoke(args)

But AutoCAD returns unknown command.

In LISP, it would look like: (c:wd_retag_update_noprompts nil "SYMBOL")

Shouldn't this run synchronously, just fine?

Thanks,
Mike

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Invoke LISP
« Reply #1 on: December 31, 2011, 12:21:28 PM »
Hi

nil is not a string.
use:
Code: [Select]
args.Add(New TypedValue(CInt(LispDataType.Nil)))or
Code: [Select]
args.Add (New TypedValue(5019))
Speaking English as a French Frog

Odoshi

  • Guest
Re: Invoke LISP
« Reply #2 on: December 31, 2011, 01:22:50 PM »
Hmm.. I tried it on another and keep getting:

Command: ; error: invalid AutoCAD command: nil

        Dim args As ResultBuffer = New ResultBuffer()
        args.Add(New TypedValue(5005, "c:wd_in_ladder"))
        args.Add(New TypedValue(5010, 1))
        args.Add(New TypedValue(5016))
        args.Add(New TypedValue(5001, 1.8))
        args.Add(New TypedValue(5001, 21.425))
        args.Add(New TypedValue(5001, 0.0))
        args.Add(New TypedValue(5017))
        args.Add(New TypedValue(CInt(LispDataType.Nil)))
        args.Add(New TypedValue(5001, 18.0))
        args.Add(New TypedValue(5005, "H"))
        args.Add(New TypedValue(5001, 12.5))
        args.Add(New TypedValue(5001, 0.75))
        args.Add(New TypedValue(5001, 0.75))
        args.Add(New TypedValue(5010, 1))
        args.Add(New TypedValue(CInt(LispDataType.Nil)))
        args.Add(New TypedValue(5010, -1))
        args.Add(New TypedValue(5005, "01"))
        args.Add(New TypedValue(5010, 2))

        Dim rbRes As ResultBuffer = Autodesk.AutoCAD.ApplicationServices.Application.Invoke(args)

Is the invoke returning nil, and then AutoCAD receiving it as a command?

Thanks,
Mike

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Invoke LISP
« Reply #3 on: December 31, 2011, 01:36:39 PM »
The result buffer must match the way you'd call your LISP function.

Post your LISP expression.
Speaking English as a French Frog

Odoshi

  • Guest
Re: Invoke LISP
« Reply #4 on: December 31, 2011, 02:03:37 PM »
This was the old VB way:

ThisDrawing.SendCommand("(c:wd_in_ladder 1 (list 1.8 21.425 0.0) nil 18.00 " & Chr(34) & "H" & Chr(34) & " 12.5 0.75" _
        '    & " 0.75 1 nil -1 " & Chr(34) & "01" & Chr(34) & " 2)" & vbCr)

which I think equates to:

(c:wd_in_ladder 1 (list 1.8 21.425 0.0) nil 18.00 "H" 12.5 0.75 0.75 1 nil -1 "01" 2)

Maybe I've miplaces a param.


gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Invoke LISP
« Reply #5 on: December 31, 2011, 02:11:29 PM »
Does the LISP expression work fine ?
Is the LISP file loaded ?

Try replacing:
Code: [Select]
args.Add(New TypedValue(5016))
args.Add(New TypedValue(5001, 1.8))
args.Add(New TypedValue(5001, 21.425))
args.Add(New TypedValue(5001, 0.0))
args.Add(New TypedValue(5017))
with
Code: [Select]
args.Add(New TypedValue(5009, new Point3d(1.8, 21.45, 0.0)))
Speaking English as a French Frog

Odoshi

  • Guest
Re: Invoke LISP
« Reply #6 on: December 31, 2011, 02:27:51 PM »
Yes, I can cut and paste that line of LISP and it gets drawn.

I tried substituting in a Point type for the list of 3 doubles.

        Dim args As ResultBuffer = New ResultBuffer()
        args.Add(New TypedValue(5005, "c:wd_in_ladder"))
        args.Add(New TypedValue(5010, 1))

        args.Add(New TypedValue(CInt(LispDataType.Point3d), New Point3d(1.8, 21.425, 0.0)))

        args.Add(New TypedValue(CInt(LispDataType.Nil)))
        args.Add(New TypedValue(5001, 18.0))
        args.Add(New TypedValue(5005, "H"))
        args.Add(New TypedValue(5001, 12.5))
        args.Add(New TypedValue(5001, 0.75))
        args.Add(New TypedValue(5001, 0.75))
        args.Add(New TypedValue(5010, 1))
        args.Add(New TypedValue(CInt(LispDataType.Nil)))
        args.Add(New TypedValue(5010, -1))
        args.Add(New TypedValue(5005, "01"))
        args.Add(New TypedValue(5010, 2))

        Dim rbRes As ResultBuffer = Autodesk.AutoCAD.ApplicationServices.Application.Invoke(args)

for the following:

(c:wd_in_ladder 1 (list 1.8 21.425 0.0) nil 18.00 "H" 12.5 0.75 0.75 1 nil -1 "01" 2)

But no joy....

Perhaps it's the context from which I am calling it?

It comes from a button click off a floating palette. But all the block insertion routines before it run fine.

Thanks,
Mike


Odoshi

  • Guest
Re: Invoke LISP
« Reply #7 on: January 03, 2012, 09:17:34 AM »
So I confirmed that I can call the following from the command line:

    <CommandMethod("INVOKE")>
    Public Sub INVOKE()
        Dim args As ResultBuffer = New ResultBuffer()
        args.Add(New TypedValue(5005, "c:ace_update_WFRM2ALL"))
        args.Add(New TypedValue(5003, 1))
        Dim rbRes As ResultBuffer = Autodesk.AutoCAD.ApplicationServices.Application.Invoke(args)
    End Sub

But using the code from a Palette on a new document object does not work. The LISP started to run, but bombed out when the LISP tried to return messages.

The command prompt gave:

; error: invalid AutoCAD command: nil

Any thoughts,
Mike

Odoshi

  • Guest
Re: Invoke LISP
« Reply #8 on: January 03, 2012, 01:55:10 PM »
Judging by this thread http://www.theswamp.org/index.php?topic=39957.0 it looks like AcedInvoke is limited to the one drawing it my command gets called from.

Any tips on how to start a command in one drawing, open another drawing and run some LISP synchronously?

Thanks,




Odoshi

  • Guest
Re: Invoke LISP
« Reply #9 on: January 03, 2012, 02:49:56 PM »
Well, looks like I'll need to add in the Interops. SendCommand will run synchronously if the Session flag is used.

Case closed :)