sending lispfunction list of 3 ints fails, shows null input

sending lispfunction list of 3 ints fails, shows null input

JamesMaeding
Advisor Advisor
794 Views
7 Replies
Message 1 of 8

sending lispfunction list of 3 ints fails, shows null input

JamesMaeding
Advisor
Advisor

I have only tested this on 2009, since I dont have VS 2010 yet to test on 2012.

I was trying to make a function to show the acad color selection dialog, so the incoming argument would be a list of 3 intergers for RGB.

But .net is not taking it.  It will take a list of any other integers, but when I send in 3, it shows the resultbuffer as null.

Here is the code to test:

[LispFunction("TestRB")]
public static ResultBuffer ShowAcColorDialog(ResultBuffer args) {
  MessageBox.Show("wow");
}

 

 the body is empty, because we are just testing to see what args is during debug.

If you call it with (TestRB (list 1 2)) in acad, the args shows typical items.

If you call it with (TestRB (list 1 2 3)) in acad, the args shows null.

 

Seems like some kind of bug.  I can work around if so but am wondering if its fixed in higher versions.

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
795 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

I don't know the answer but maybe this might help. My plan is to pass arguments to .NET is to use one single string argument that contains an unlimited number of arguments delineated by the character |. The single argument will be split into the intended arguments. The scheme intends to provide flexibility in the number actual arguments being passed.  

 

aks

0 Likes
Message 3 of 8

JamesMaeding
Advisor
Advisor

yah, what I used to do before I knew about lispfuction attribute (way back) was write args to a text file, then have whatever tool read that file for them.  All we are doing is what the internet does and .net makes easy - serialization.

Its very easy to serialize and deserialize an object in .net, but what about lisp?

So I wrote funtions in lisp to take a lisp list, and convert to xml.  I had to make sure I had the corresponding object in .net, but did not always want to make one to deserialize into, so I also made functions to take in any incoming list as a resultbuffer and convert to arraylist in .net.  Sounds trivial until you get into nested lists.  Its not too hard to convert the linear resultbuffer into a nested structure though.  I also made the reverse - arraylist to resultbuffer so I can pass lists back and forth between lisp and .net.

Sounds like more effort than just switching to .net completely, I know.

But I have a huge lisp library and about 20 significant progs, beyond the little ones, that I must maintain.

Now that I can pass lists easily though, the conversion will happen much faster.

 

This list of three integers is throwing me off though.  Talk about a wierd bug if so.

Note that another wierd thing is when you send in a list of three reals from lisp, .net treats them as a 3d point.

That tells me there is some conversion mechanism that has funny rules.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 4 of 8

JamesMaeding
Advisor
Advisor

I just noticed same thing happens with list of 4 integers.

This is really whacko.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 5 of 8

jeff
Collaborator
Collaborator

I am not a AutoLisp guy but does'nt List(1 2)  or List(1 2 3) create a point?

If so I would not expect it to act any different.

Using List(.........) is creating a nested list.

 

The color black is what was entered in command line and blue is what is returned

 

Command: (TestRB (list 1 2))
Point2d X: 1 Y: 2
Returned from function (nil)

 

Command: (TestRB (list 1 2 3))
Point3d X: 1 Y: 2 Z: 3

Returned from function  (nil)

 

Command: (TestRB (list 1 2 3 4))
***List Begin****
1
2
3
4
***List End****
Returned from function  (nil)

 

Command: (TestRB 2 3 4)
2
3
4
Returned from function  (nil)

 

Command: (TestRB (list 1 2 3 4) 14 2)
***List Begin****
1
2
3
4
***List End****
14
2
Returned from function  (nil)

 

Here is the code that was thrown together quickly just for testing.

 

        [LispFunction("TestRB")]
        public ResultBuffer TestRB(ResultBuffer args)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            TypedValue[] tvs = args.AsArray();           

            for (int i = 0; i < tvs.Length; i++)
            {
                if (tvs[i].TypeCode == (short)LispDataType.ListBegin)
                {
                    ed.WriteMessage("\n***List Begin****");
                    i++;
                    while (tvs[i].TypeCode != (short)LispDataType.ListEnd)
                    {
                        ed.WriteMessage("\n" + tvs[i].Value.ToString());
                        i++;
                    }
                    ed.WriteMessage("\n***List End****");
                }

                else if (tvs[i].TypeCode == (short)LispDataType.Point2d)
                {
                    Point2d pnt = (Point2d)tvs[i].Value;
                    ed.WriteMessage("\nPoint2d X: {0} Y: {1}", pnt.X.ToString(), pnt.Y.ToString());
                }

                else if (tvs[i].TypeCode == (short)LispDataType.Point3d)
                {
                    Point3d pnt = (Point3d)tvs[i].Value;
                    ed.WriteMessage("\nPoint3d X: {0} Y: {1} Z: {2}", pnt.X.ToString(), pnt.Y.ToString(), pnt.Z.ToString());
                }

                else
                {
                    ed.WriteMessage("\n" + tvs[i].Value.ToString());

                }

            }

            ed.WriteMessage("\n\nReturned from function  ");

            return new ResultBuffer(new TypedValue((int)LispDataType.Nil));
        }
You can also find your answers @ TheSwamp
0 Likes
Message 6 of 8

JamesMaeding
Advisor
Advisor

Jeff, which acad version and vertical?  I am on 2009 Civil 3D.

thx


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 7 of 8

jeff
Collaborator
Collaborator

I tested that on 2012 Vanilla and 2011 MEP but looks like that would not help confirm if it is a 2009 issue.

You can also find your answers @ TheSwamp
0 Likes
Message 8 of 8

JamesMaeding
Advisor
Advisor

thx, sounds like it will go away in time.

Note that a list of three integers is nothing special to lisp.  For acad to decide they represent a 3d point is not useful when passing data around so no idea why its done.

 

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes