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

AutoCAD entities additional data

2 REPLIES 2
Reply
Message 1 of 3
terno
737 Views, 2 Replies

AutoCAD entities additional data

Hello!

I'm using VB.NET and i need save additional data of some ACAD objects in DWG-drawing. Can I add List, SortedList (System.Generic.Collection) or other data arrays to ACAD object or DWG-drawing?

2 REPLIES 2
Message 2 of 3
caddzone
in reply to: terno

Not directly, but you can store data in extended entity data or xrecords that

are added to an entity's extension dictionary, and you can write code that

does the conversion between a ResultBuffer and a managed collection type

without too much difficulty.

 

It's just not as automated as you might want it to be.



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


Message 3 of 3
Hallex
in reply to: terno

Hi!

Is there what you need?

(tested on A2009 only)

 
        static public void XdataAttach()
        {
            Document doc = acadApp.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;

            Database db = doc.Database;

            DocumentLock loc = doc.LockDocument();// optional

            using (loc)
            {

                try
                {
                    PromptEntityOptions pso = new PromptEntityOptions("\n  >>  Select polyline >> ");

                    pso.SetRejectMessage("\nMust be a polyline: ");

                    pso.AddAllowedClass(typeof(Polyline), true);

                    PromptEntityResult res = ed.GetEntity(pso);

                    if (res.Status != PromptStatus.OK)

                        return;

                    Transaction tr = doc.TransactionManager.StartTransaction();

                    using (tr)
                    {
                        DBObject obj = tr.GetObject(res.ObjectId, OpenMode.ForRead);

                        Polyline pline = obj as Polyline;

                        if (pline != null)
                        {

                            RegAppTable rgptbl;

                            rgptbl = tr.GetObject(db.RegAppTableId, OpenMode.ForRead) as RegAppTable;

                            if (rgptbl.Has("MYAPP") == false)
                            {
                                RegAppTableRecord rgpbtr = new RegAppTableRecord();

                                rgpbtr.Name = "MYAPP";

                                rgptbl.UpgradeOpen();

                                rgptbl.Add(rgpbtr);

                                tr.AddNewlyCreatedDBObject(rgpbtr, true);
                            }

                            SortedList list = new SortedList();

                            list.Add(5, "echo");

                            list.Add(1, "alpha");

                            list.Add(6, "foxtrot");

                            list.Add(4, "delta");

                            list.Add(7, "golf");

                            list.Add(3, "charlie");

                            list.Add(2, "bravo");

                            ResultBuffer rbuf = new ResultBuffer();

                            rbuf.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, "MYAPP"));

                            foreach (KeyValuePair kvp in list)
                            {

                                rbuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger32, kvp.Key));
                               
                                rbuf.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, kvp.Value.ToString()));
                              
                            }
                                                               
                            pline.UpgradeOpen();
                            
                            pline.XData = rbuf;

                            rbuf.Dispose();

                            TypedValue[] ntv = pline.GetXDataForApplication("MYAPP").AsArray();

                            foreach (TypedValue tv in ntv)
                                ed.WriteMessage("\n{0}\t{1}", tv.TypeCode, tv.Value);
                            
                            tr.Commit();
                        }
                    }

                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    ed.WriteMessage("\nError:\n" + ex.Message);
                }

            }
        }

__________________________________________________________________

"The whole problem with the world is that fools and fanatics are always

so certain of themselves, and wiser people so full of doubts."

Bertrand Russell

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

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