.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

4 REPLIES 4
Reply
Message 1 of 5
tech
1271 Views, 4 Replies

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

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.

4 REPLIES 4
Message 2 of 5
BrentBurgess1980
in reply to: tech

C# strAttValue = ("3/16" + "\"=1'-0\""); VB.NET strAttValue = ("3/16" & """=1'-0""") both return 3/16"=1'-0"
Message 3 of 5
tech
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"

Message 4 of 5
Alexander.Rivilis
in reply to: tech

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

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 5 of 5
_gile
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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost