• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    Posts: 11
    Registered: ‎06-09-2003

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

    256 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.

    Please use plain text.
    Mentor
    BrentBurgess1980
    Posts: 158
    Registered: ‎06-16-2008

    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"
    Please use plain text.
    Contributor
    Posts: 11
    Registered: ‎06-09-2003

    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"

    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,178
    Registered: ‎04-09-2008

    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

    Please use plain text.
    *Expert Elite*
    Posts: 1,649
    Registered: ‎04-29-2006

    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
    Please use plain text.