Set or Get Lisp Symbol in .NET

By Madhukar Moogala

We are pretty much aware of pinvoke acedGetSymacedPutSym in .NET to manipulate lisp symbols , we can avoid pinvoking with help of  SetLispSymbol and GetLispSymbol.

In the following example ,my attention is towards "how to store retireve multiple fragements of information in lisp symbol " ,to achieve this we can use TypedValue object data type along with LispDataType enumerations as values.

 

public static void PutSymbol()
{
 
Document d = Application.DocumentManager.MdiActiveDocument;
Database db = d.Database;
// Create a list
TypedValue[] tValue = new TypedValue[7];
tValue.SetValue(new TypedValue((int)LispDataType.ListBegin), 0);
tValue.SetValue(new TypedValue((int)LispDataType.Text,
                                "Main List Item 1"), 1);
tValue.SetValue(new TypedValue((int)LispDataType.ListBegin), 2);
tValue.SetValue(new TypedValue((int)LispDataType.Text,
                                "Nested List Item 1"), 3);
tValue.SetValue(new TypedValue((int)LispDataType.Text,
                                "Nested List Item 2"), 4);
tValue.SetValue(new TypedValue((int)LispDataType.ListEnd), 5);
tValue.SetValue(new TypedValue((int)LispDataType.ListEnd), 6);
 
d.SetLispSymbol("lst", tValue);
}
 
public static void GetSymbol()
{
Document d = Application.DocumentManager.MdiActiveDocument;
Editor ed = d.Editor;
PromptResult res = ed.GetString("nName of lisp-Symbol name: ");
if (res.Status == PromptStatus.OK)
{
    TypedValue[] tValue = (TypedValue[])d.GetLispSymbol(res.StringResult);
    if (tValue == null) return;
    foreach (TypedValue tV in tValue)
    {
        ed.WriteMessage("n");
        ed.WriteMessage(tV.TypeCode + "," + tV.Value);
    }
 
}
 
}

Comments

One response to “Set or Get Lisp Symbol in .NET”

  1. Hi Madhukar Moogala, I copied GetSymbol and built the solution but it’s not working (Windows 7 and AutoCAD 2016):
    System.InvalidCastException: Unable to cast object of type ‘System.String’ to type ‘Autodesk.AutoCAD.DatabaseServices.TypedValue[]’.
    the error occurs at this line:
    TypedValue[] tValue = (TypedValue[])d.GetLispSymbol(res.StringResult);
    (I was typing the name of a string var. A real number symbol leads to the same kind of error at the same line: System.InvalidCastException: Unable to cast object of type ‘System.Double’ to type ‘Autodesk.AutoCAD.DatabaseServices.TypedValue[]’.)
    What am I missing?

Leave a Reply to sam1Cancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading