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?
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.
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'~