.NET

Reply
Contributor
tech
Posts: 11
Registered: ‎06-09-2003
Message 1 of 5 (679 Views)

Pass a string with quote marks to a lisp command in VB.NET

679 Views, 4 Replies
08-10-2012 03:52 PM

Hi,

 

I have created a string:

strAttValue = ("3/16""=1'-0""")

or alternatively I've tried:

strAttValue = ("3/16" & Chr(34) & "=1'-0" & Chr(34))

 

that I would like to pass to a lisp with the format:

(defun lispTest ( strAttValue / )

 

but when I do it errors with "Too many variables." The passing method is as follows:

acDoc.SendStringToExecute("(lispTest" & Chr(34) & strAttValue & Chr(34) & " ) ", True, False, False)

 

If I get rid of the quotes in the original string it works fine, but the quotes are needed. Does anyone know why this is? How can I make it work?

 

I really should use VB.NET or C# more often, these simple things kill me and I am sure it is something obvious! - Thanks.

Mentor
BrentBurgess1980
Posts: 162
Registered: ‎06-16-2008
Message 2 of 5 (645 Views)

Re: Pass a string with quote marks to a lisp command in VB.NET

08-12-2012 06:47 PM in reply to: tech
C# strAttValue = ("3/16" + "\"=1'-0\""); VB.NET strAttValue = ("3/16" & """=1'-0""") both return 3/16"=1'-0"
Contributor
tech
Posts: 11
Registered: ‎06-09-2003
Message 3 of 5 (633 Views)

Re: Pass a string with quote marks to a lisp command in VB.NET

08-13-2012 11:31 AM in reply to: BrentBurgess1980

EDIT

 

Actually, the " symbol is the culprit. If I create:

strAttValue = ("3/16=1'-0")

 

it works fine, but I need the " symbol to be part of the string so I am stuck. Any ideas?

 

When I use a (princ strAttValue) using ssomething like strAttValue = ("3/16" & """=1'-0""")

I get the following error:

 

bad argument type: FILE "=1'-0"

Moderator
Alexander.Rivilis
Posts: 1,449
Registered: ‎04-09-2008
Message 4 of 5 (624 Views)

Re: Pass a string with quote marks to a lisp command in VB.NET

08-13-2012 01:25 PM in reply to: tech

Every Chr(34) have to be replaced with Chr(92) & Chr(34) in order to passed to lisp.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

*Expert Elite*
_gile
Posts: 2,114
Registered: ‎04-29-2006
Message 5 of 5 (619 Views)

Re : Pass a string with quote marks to a lisp command in VB.NET

08-13-2012 02:06 PM in reply to: tech

Hi,

 

IMO, you'd rather use the Application.Invoke() (A2011 or later), or P/Invoke acedInvoke() (for prior versions) with which you can invoke a LISP function and get its return value.

Your LISP function have to be registered with vl-acad-defun or be prefixed with c:

 

Here's a little example:

 

LISP function

(defun lispTest (strArg)
  (princ (strcat "\nstrArg: " strArg "\n"))
  strArg
)
(vl-acad-defun 'lispTest)

 

C# code with Application.Invoke():

        [CommandMethod("Foo")]        
public void Foo() { ResultBuffer args = new ResultBuffer( new TypedValue((int)LispDataType.Text, "lispTest"), new TypedValue((int)LispDataType.Text, "3/16\"=1'-0\"\"")); ResultBuffer retVal = Application.Invoke(args); Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage( "\nretVal:" + retVal.AsArray()[0].Value); }

 

C# code with P/Invoke acedInvoke:

 

        [System.Security.SuppressUnmanagedCodeSecurity]
        [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
        extern static private int acedInvoke(IntPtr rbIn, out IntPtr rbOut);

        public static ResultBuffer InvokeLisp(ResultBuffer args)
        {
            IntPtr rb = IntPtr.Zero;
            int stat = acedInvoke(args.UnmanagedObject, out rb);
            if (stat == (int)PromptStatus.OK && rb != IntPtr.Zero)
                return (ResultBuffer)DisposableWrapper.Create(typeof(ResultBuffer), rb, true);
            return null;
        }

        [CommandMethod("Bar")]
        public void Bar()
        {
            ResultBuffer args = new ResultBuffer(
                new TypedValue((int)LispDataType.Text, "lispTest"),
                new TypedValue((int)LispDataType.Text, "3/16\"=1'-0\"\""));
            ResultBuffer retVal = Application.Invoke(args);
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(
                "\nretVal:" + retVal.AsArray()[0].Value);
        }

 

 

Gilles Chanteau
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!