qq1254582201 发表于 2024-9-6 11:22:30

【转载】将C# class 序列化后存储到AutoCAD实体的XRecord中

Serialize a .NET class into an AutoCAD drawing databaseBy Adam NagyI would like to serialize my .NET class into an AutoCAD drawing database, so it is saved into the drawing, and I can recreate my class again (deserialize it), when the drawing is reopened. How could I do it?
SolutionYou could use the .NET serialization technique to serialize your class into a binary stream and then you can save it in the drawing as a bunch of binary chunks. You could save the ResultBuffer to an object's XData or into an Xrecord.Data of an entity or an item in the Named Objects Dictionary (NOD). DevNote TS2563 tells you what the difference is between using XData and Xrecord. If you are saving it into an XData, then the ResultBuffer needs to start with a registered application name. Here is a sample which shows this:using System;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Security.Permissions;

using Autodesk.AutoCAD.Runtime;
using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;



namespace MyClassSerializer
{
// We need it to help with deserialization

public sealed class MyBinder : SerializationBinder
{
    public override System.Type BindToType(
      string assemblyName,
      string typeName)
    {
      return Type.GetType(string.Format("{0}, {1}",
      typeName, assemblyName));
    }
}

// Helper class to write to and from ResultBuffer

public class MyUtil
{
    const int kMaxChunkSize = 127;

    public static ResultBuffer StreamToResBuf(
      MemoryStream ms, string appName)
    {
      ResultBuffer resBuf =
      new ResultBuffer(
          new TypedValue(
            (int)DxfCode.ExtendedDataRegAppName, appName));

      for (int i = 0; i < ms.Length; i += kMaxChunkSize)
      {
      int length = (int)Math.Min(ms.Length - i, kMaxChunkSize);
      byte[] datachunk = new byte;
      ms.Read(datachunk, 0, length);
      resBuf.Add(
          new TypedValue(
            (int)DxfCode.ExtendedDataBinaryChunk, datachunk));
      }

      return resBuf;
    }

    public static MemoryStream ResBufToStream(ResultBuffer resBuf)
    {
      MemoryStream ms = new MemoryStream();
      TypedValue[] values = resBuf.AsArray();

      // Start from 1 to skip application name

      for (int i = 1; i < values.Length; i++)
      {
      byte[] datachunk = (byte[])values.Value;
      ms.Write(datachunk, 0, datachunk.Length);
      }
      ms.Position = 0;

      return ms;
    }
}


public abstract class MyBaseClass : ISerializable
{
    public const string appName = "MyApp";

    public MyBaseClass()
    {
    }

    public static object NewFromResBuf(ResultBuffer resBuf)
    {
      BinaryFormatter bf = new BinaryFormatter();
      bf.Binder = new MyBinder();

      MemoryStream ms = MyUtil.ResBufToStream(resBuf);

      MyBaseClass mbc = (MyBaseClass)bf.Deserialize(ms);

      return mbc;
    }

    public static object NewFromEntity(Entity ent)
    {
      using (
      ResultBuffer resBuf = ent.GetXDataForApplication(appName))
      {
      return NewFromResBuf(resBuf);
      }
    }

    public ResultBuffer SaveToResBuf()
    {
      BinaryFormatter bf = new BinaryFormatter();
      MemoryStream ms = new MemoryStream();
      bf.Serialize(ms, this);
      ms.Position = 0;

      ResultBuffer resBuf = MyUtil.StreamToResBuf(ms, appName);

      return resBuf;
    }

    public void SaveToEntity(Entity ent)
    {
      // Make sure application name is registered
      // If we were to save the ResultBuffer to an Xrecord.Data,
      // then we would not need to have a registered application name

      Transaction tr =
      ent.Database.TransactionManager.TopTransaction;

      RegAppTable regTable =
      (RegAppTable)tr.GetObject(
          ent.Database.RegAppTableId, OpenMode.ForWrite);
      if (!regTable.Has(MyClass.appName))
      {
      RegAppTableRecord app = new RegAppTableRecord();
      app.Name = MyClass.appName;
      regTable.Add(app);
      tr.AddNewlyCreatedDBObject(app, true);
      }

      using (ResultBuffer resBuf = SaveToResBuf())
      {
      ent.XData = resBuf;
      }
    }

    [SecurityPermission(SecurityAction.LinkDemand,
    public abstract void GetObjectData(
      SerializationInfo info, StreamingContext context);
}


public class MyClass : MyBaseClass
{
    public string myString;
    public double myDouble;

    public MyClass()
    {
    }

    protected MyClass(
      SerializationInfo info, StreamingContext context)
    {
      if (info == null)
      throw new System.ArgumentNullException("info");

      myString = (string)info.GetValue("MyString", typeof(string));
      myDouble = (double)info.GetValue("MyDouble", typeof(double));
    }

    [SecurityPermission(SecurityAction.LinkDemand,
    public override void GetObjectData(
      SerializationInfo info, StreamingContext context)
    {
      info.AddValue("MyString", myString);
      info.AddValue("MyDouble", myDouble);
    }

    // Just for testing purposes

    public override string ToString()
    {
      return base.ToString() + "," +
      myString + "," + myDouble.ToString();
    }
}

public class Commands
{
   
    static public void SaveClassToEntityXData()
    {
      Database db = acApp.DocumentManager.MdiActiveDocument.Database;
      Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;

      PromptEntityResult per =
      ed.GetEntity("Select entity to save class to:\n");
      if (per.Status != PromptStatus.OK)
      return;

      // Create an object

      MyClass mc = new MyClass();
      mc.myDouble = 1.2345;
      mc.myString = "Some text";

      // Save it to the document

      using (
      Transaction tr = db.TransactionManager.StartTransaction())
      {
      Entity ent =
          (Entity)tr.GetObject(per.ObjectId, OpenMode.ForWrite);

      mc.SaveToEntity(ent);

      tr.Commit();
      }

      // Write some info about the results

      ed.WriteMessage(
      "Content of MyClass we serialized:\n {0} \n", mc.ToString());
    }

   
    static public void GetClassFromEntityXData()
    {
      Database db = acApp.DocumentManager.MdiActiveDocument.Database;
      Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;

      PromptEntityResult per =
      ed.GetEntity("Select entity to get class from:\n");
      if (per.Status != PromptStatus.OK)
      return;

      // Get back the class

      using (
      Transaction tr = db.TransactionManager.StartTransaction())
      {
      Entity ent =
          (Entity)tr.GetObject(per.ObjectId, OpenMode.ForRead);

      MyClass mc = (MyClass)MyClass.NewFromEntity(ent);

      // Write some info about the results

      ed.WriteMessage(
          "Content of MyClass we deserialized:\n {0} \n",
          mc.ToString());

      tr.Commit();
      }
    }
}
}


Posted at 09:56 AM in .NET, Adam Nagy, AutoCAD | Permalink



qq1254582201 发表于 2024-9-6 11:30:15

本帖最后由 qq1254582201 于 2024-9-6 11:33 编辑

Adding extension dictionaryBy Virupaksha AithalEach AutoCAD object can store a custom data with it. Normally this functionality is used by AutoCAD graphical entities to store non graphical data. For example, an AutoCAD line can store a string or/and a double with it (in its extension dictionary). Below code shows the procedure to add an extension dictionary strong a double and a string


public void AddExtensionDictionary()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    PromptEntityResult ers = ed.GetEntity("Select entity to add" +
                                           " extension dictionary ");
    if (ers.Status != PromptStatus.OK)
      return;

    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
      DBObject dbObj = tr.GetObject(ers.ObjectId,
                                                   OpenMode.ForRead);

      ObjectId extId = dbObj.ExtensionDictionary;

      if (extId == ObjectId.Null)
      {
            dbObj.UpgradeOpen();
            dbObj.CreateExtensionDictionary();
            extId = dbObj.ExtensionDictionary;
      }

      //now we will have extId...
      DBDictionary dbExt =
                (DBDictionary)tr.GetObject(extId, OpenMode.ForRead);

      //if not present add the data
      if (!dbExt.Contains("TEST"))
      {
            dbExt.UpgradeOpen();
            Xrecord xRec = new Xrecord();
            ResultBuffer rb = new ResultBuffer();
            rb.Add(new TypedValue(
                      (int)DxfCode.ExtendedDataAsciiString, "Data"));
            rb.Add(new TypedValue((int)DxfCode.ExtendedDataReal,
                                                            10.2));

            //set the data
            xRec.Data = rb;

            dbExt.SetAt("TEST", xRec);
            tr.AddNewlyCreatedDBObject(xRec, true);
      }
      else
      {
            ed.WriteMessage("entity contains the TEST data\n");
      }


      tr.Commit();
    }

}



Posted at 03:17 AM in .NET, AutoCAD, Virupaksha Aithal | Permalink



qq1254582201 发表于 2024-9-6 12:03:39

本帖最后由 qq1254582201 于 2024-9-6 12:09 编辑

AutoCAD .NET XData: Read Existing XData from Entity/ObjectAutoCAD has supported the eXtended Data for long time, back to the ADS era. In the AutoCAD .NET world, those functionalities regarding the XData manipulations and even those extended DXF codes are wrapped nicely into some classes, structs, methods and enums.However, because of the different syntaxes in the new AutoCAD .NET and the old ADS, even for people coming from the ADS time and using those old ResultBuffer a lot, they may still be confused about some classes, methods, and enum values as far as XData and ResultBuffer are concerned.Previously, we added various XData types to a single picked AutoCAD entity. In this post, let’s read out those XData with various types and assign them to variables of proper types.

public static void ReadXData_Method()
{
    const string TestAppName = "XDataAppName1";
    Database db = HostApplicationServices.WorkingDatabase;
    Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
    try
    {
      PromptEntityResult prEntRes = ed.GetEntity("Select an Entity");
      if (prEntRes.Status == PromptStatus.OK)
      {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Entity ent = (Entity)tr.GetObject(prEntRes.ObjectId, OpenMode.ForRead);
                ResultBuffer rb = ent.GetXDataForApplication(TestAppName);
                if (rb != null)
                {
                  TypedValue[] rvArr = rb.AsArray();
                  foreach (TypedValue tv in rvArr)
                  {
                        switch ((DxfCode)tv.TypeCode)
                        {
                            case DxfCode.ExtendedDataRegAppName:
                              string appName = (string)tv.Value;
                              ed.WriteMessage("\nXData of appliation name (1001) {0}:", appName);
                              break;
                            case DxfCode.ExtendedDataAsciiString:
                              string asciiStr = (string)tv.Value;
                              ed.WriteMessage("\n\tAscii string (1000): {0}", asciiStr);
                              break;
                            case DxfCode.ExtendedDataLayerName:
                              string layerName = (string)tv.Value;
                              ed.WriteMessage("\n\tLayer name (1003): {0}", layerName);
                              break;
                            case DxfCode.ExtendedDataBinaryChunk:
                              Byte[] chunk = tv.Value as Byte[];
                              string chunkText = Encoding.ASCII.GetString(chunk);
                              ed.WriteMessage("\n\tBinary chunk (1004): {0}", chunkText);
                              break;
                            case DxfCode.ExtendedDataHandle:
                              ed.WriteMessage("\n\tObject handle (1005): {0}", tv.Value);
                              break;
                            case DxfCode.ExtendedDataXCoordinate:
                              Point3d pt = (Point3d)tv.Value;
                              ed.WriteMessage("\n\tPoint (1010): {0}", pt.ToString());
                              break;
                            case DxfCode.ExtendedDataWorldXCoordinate:
                              Point3d pt1 = (Point3d)tv.Value;
                              ed.WriteMessage("\n\tWorld point (1011): {0}", pt1.ToString());
                              break;
                            case DxfCode.ExtendedDataWorldXDisp:
                              Point3d pt2 = (Point3d)tv.Value;
                              ed.WriteMessage("\n\tDisplacement (1012): {0}", pt2.ToString());
                              break;
                            case DxfCode.ExtendedDataWorldXDir:
                              Point3d pt3 = (Point3d)tv.Value;
                              ed.WriteMessage("\n\tDirection (1013): {0}", pt3.ToString());
                              break;
                            case DxfCode.ExtendedDataControlString:
                              string ctrStr = (string)tv.Value;
                              ed.WriteMessage("\n\tControl string (1002): {0}", ctrStr);
                              break;
                            case DxfCode.ExtendedDataReal:
                              double realValue = (double)tv.Value;
                              ed.WriteMessage("\n\tReal (1040): {0}", realValue);
                              break;
                            case DxfCode.ExtendedDataDist:
                              double dist = (double)tv.Value;
                              ed.WriteMessage("\n\tDistance (1041): {0}", dist);
                              break;
                            case DxfCode.ExtendedDataScale:
                              double scale = (double)tv.Value;
                              ed.WriteMessage("\n\tScale (1042): {0}", scale);
                              break;
                            case DxfCode.ExtendedDataInteger16:
                              Int16 int16 = (short)tv.Value;
                              ed.WriteMessage("\n\tInt16 (1070): {0}", int16);
                              break;
                            case DxfCode.ExtendedDataInteger32:
                              Int32 int32 = (Int32)tv.Value;
                              ed.WriteMessage("\n\tInt32 (1071): {0}", int32);
                              break;
                            default:
                              ed.WriteMessage("\n\tUnknown XData DXF code.");
                              break;
                        }
                  }
                }
                else
                  ed.WriteMessage("The entity does not have the {0} XData.", TestAppName);
                tr.Commit();
            }
      }
    }
    catch (System.Exception ex)
    {
      ed.WriteMessage(ex.ToString());
    }
}

Here is he output in the AutoCAD command line window.Command: ADDXDAta
Select an Entity to attach XDATA:
Command: READXDATA
Select an Entity:
XData of appliation name (1001) XDataAppName1:
Ascii string (1000): String1
Layer name (1003): 0
Binary chunk (1004): BinaryChunk
Object handle (1005): A53
Point (1010): (1.1,2.1,3.1)
World point (1011): (1.2,2.2,3.2)
Displacement (1012): (1.3,2.3,3.3)
Direction (1013): (1.4,2.4,3.4)
Control string (1002): {
Real (1040): 12345.6789
Distance (1041): 25.25
Scale (1042): 0.2
Control string (1002): }
Int16 (1070): 16
Int32 (1071): 32The code seems simple and straightforward, but there are quite some tips and tricks there.• The DBObject.GetXDataForApplication() method can retrieve the XData with the specified application name from a DBObject or Entity.
• All XData starts with the 1001 (DxfCode.ExtendedDataRegAppName) code.
• The XData Application Name can be registered through creating a RegAppTableRecord and adding it to the RegAppTable (another kind of AutoCAD symbol table).
• The ResultBuffer is a list of TypedValue which is a pair of type and value.
• The DxfCode.ExtendedDataLayerName enum value (with integer 1003) specifies that the value will be a layer name. Whether the layer has to present or not in the current database may need further exploration.
• The DxfCode.ExtendedDataBinaryChunk enum value (with integer 1004) specifies that the XData value will be some binary chunk. We will address it further in the future.
• The DxfCode.ExtendedDataHandle enum value (with integer 1005) specifies that the XData value is supposed to be a valid AutoCAD object handle. If it is not a good object handle or the object it references to has been deleted, the Audio command will report an error and the Fix option will set it as NULL or empty.
• The DxfCode.ExtendedDataXCoordinate enum value (with integer 1010) and the DxfCode.ExtendedDataWorldXCoordinate (with integer 1011) specify that the XData value will be a 3D point.
• When the two enum values (1010 or 1011) are specified as the XData type, their value objects should be of type Point3d.
• The DxfCode.ExtendedDataYCoordinate (1020) and the DxfCode.ExtendedDataZCoordinate (1030) enum values are there for other purposes. They should not be used in the TypedValue constructors. Otherwise, exceptions would just occur.
• The same apply to the ExtendedDataWorldYCoordinate (1021) and the ExtendedDataWorldYCoordinate (1031) enum values.
• Though the DxfCode.ExtendedDataWorldXDisp (1012) and the DxfCode.ExtendedDataWorldXDir (1013) indicate that the XData value should be a displacement, direction, or a vector, the TypedValue constructor does not accept a Vector3d object! They still only accept the type of Point3d!
• Once again, the DxfCode.ExtendedDataWorldYDisp(1022)/DxfCode.ExtendedDataWorldZDisp(1032) and DxfCode.ExtendedDataWorldYDir(1023)/DxfCode.ExtendedDataWorldZDir(1033) are there for other purposes. They should not be used in the TypedValue constructors. Otherwise, exceptions would just occur.
• The DxfCode.ExtendedDataControlString indicates that the XData value can be either "{" or “}” and the two symbols must be balanced in the whole XData group. They can be nested.
• The DxfCode.ExtendedDataReal (1040), DxfCode.ExtendedDataDist(1041), DxfCode.ExtendedDataScale, (1042), DxfCode.ExtendedDataInteger16 (1070) and DxfCode.ExtendedDataInteger32 (1071) are straightforward as their names suggest.    The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides project wizards in C#, VB.NET and CLI/Managed C++, and various item wizards such as Event Handlers, Command/LispFunction Definers, and Entity/Draw Jiggers in both C# and VB.NET, to help program AutoCAD addins.


qq1254582201 发表于 2024-9-6 12:11:02

本帖最后由 qq1254582201 于 2024-9-6 15:12 编辑

AutoCAD .NET XData: Add New XData to Entity/ObjectAutoCAD has supported the eXtended Data for long time, back to the ADS era. In the AutoCAD .NET world, those functionalities regarding the XData manipulations and even those extended DXF codes are wrapped nicely into some classes, structs, methods and enums.However, because of the different syntaxes in the new AutoCAD .NET and the old ADS, even for people coming from the ADS time and using those old ResultBuffer a lot, they may still be confused about some classes, methods, and enum values as far as XData and ResultBuffer are concerned.From this post on, let’s look at some aspects about using XData in AutoCAD .NET. Particularly, in this post, let’s add various XData types to a single picked AutoCAD entity. Here is the code and command.

public static void AddXData_Method()
{
    const string TestAppName = "XDataAppName1";
    Database db = HostApplicationServices.WorkingDatabase;
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    try
    {
      PromptEntityResult prEntRes = ed.GetEntity("Select an Entity to attach XDATA");
      if (prEntRes.Status == PromptStatus.OK)
      {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                RegAppTable regAppTable = (RegAppTable)tr.GetObject(db.RegAppTableId, OpenMode.ForRead);
                if (!regAppTable.Has(TestAppName))
                {
                  using (RegAppTableRecord regAppRecord = new RegAppTableRecord())
                  {
                        regAppRecord.Name = TestAppName;
                        regAppTable.UpgradeOpen();
                        regAppTable.Add(regAppRecord);
                        regAppTable.DowngradeOpen();
                        tr.AddNewlyCreatedDBObject(regAppRecord, true);
                  }
                }
                Entity ent = (Entity)tr.GetObject(prEntRes.ObjectId, OpenMode.ForWrite);
                ent.XData = new ResultBuffer
                            (
                              new TypedValue((int)DxfCode.ExtendedDataRegAppName, TestAppName),   //1001
                              new TypedValue((int)DxfCode.ExtendedDataAsciiString, "String1"),    //1000
                              new TypedValue((int)DxfCode.ExtendedDataLayerName, "0"),            //1003
                              new TypedValue((int)DxfCode.ExtendedDataBinaryChunk, Encoding.ASCII.GetBytes("BinaryChunk")), //1004
                              new TypedValue((int)DxfCode.ExtendedDataHandle, ent.Handle),      //1005
                              new TypedValue((int)DxfCode.ExtendedDataXCoordinate, new Point3d(1.1, 2.1, 3.1)), //1010
                              //new TypedValue((int)DxfCode.ExtendedDataYCoordinate, 2.1),          //1020
                              //new TypedValue((int)DxfCode.ExtendedDataZCoordinate, 3.1),          //1030
                              new TypedValue((int)DxfCode.ExtendedDataWorldXCoordinate, new Point3d(1.2, 2.2, 3.2)), //1011
                              //new TypedValue((int)DxfCode.ExtendedDataWorldYCoordinate, 2.2),   //1021
                              //new TypedValue((int)DxfCode.ExtendedDataWorldZCoordinate, 3.2),   //1031
                              new TypedValue((int)DxfCode.ExtendedDataWorldXDisp, new Point3d(1.3, 2.3, 3.3)), //1012
                              //new TypedValue((int)DxfCode.ExtendedDataWorldYDisp, 2.3),         //1022
                              //new TypedValue((int)DxfCode.ExtendedDataWorldZDisp, 3.3),         //1032
                              new TypedValue((int)DxfCode.ExtendedDataWorldXDir, new Point3d(1.4, 2.4, 3.4)), //1013
                              //new TypedValue((int)DxfCode.ExtendedDataWorldYDir, 2.4),            //1023
                              //new TypedValue((int)DxfCode.ExtendedDataWorldZDir, 3.4),            //1033
                              new TypedValue((int)DxfCode.ExtendedDataControlString, "{"),      //1002
                              new TypedValue((int)DxfCode.ExtendedDataReal, 12345.6789),          //1040
                              new TypedValue((int)DxfCode.ExtendedDataDist, 25.25),               //1041
                              new TypedValue((int)DxfCode.ExtendedDataScale, 0.2),                //1042
                              new TypedValue((int)DxfCode.ExtendedDataControlString, "}"),      //1002
                              new TypedValue((int)DxfCode.ExtendedDataInteger16, 16),             //1070
                              new TypedValue((int)DxfCode.ExtendedDataInteger32, 32)            //1071
                            );
                tr.Commit();
            }
      }
    }
    catch (System.Exception ex)
    {
      ed.WriteMessage(ex.ToString());
    }
}


After the command is run and an entity is selected in AutoCAD, the various XData will be added to the entity successfully. If the ArxDbg tool has been loaded, we can use it to check the XData on the entity.Here is what the ArxDbgSnoopEnts will tell us about the XData of the entity.
https://spiderinnet1.typepad.com/.a/6a0153928ee38e970b017d3da21b17970c-800wi
The code seems simple and straightforward, but there are quite some tips and tricks there.• The XData has to be started with the 1001 (DxfCode.ExtendedDataRegAppName) code.
• The XData Application Name has to be registered beforehand.
• The XData Application Name can be registered through creating a RegAppTableRecord and adding it to the RegAppTable (another kind of AutoCAD symbol table).
• The RegAppTable had better be opened for READ first to check the existence of the RegAppTableRecord.
• If the RegAppTableRecord does not exist in the RegAppTable, it can be upgraded to WRITE through the UpgradeOpen() call.
• The UpgradeOpen() had better be balanced with the DowngradeOpen() call though not necessary if the object/entity is closed right after the modification.
• The Entity.XData property can be used to retrieve all the XData associated with the entity if any or to set some XData to it.
• The XData property is inherited from the DBObject actually indicating that all AutoCAD database resident objects having graphics or not such as layers and line types all can have XData.
• The ResultBuffer is a list of TypedValue which is a pair of type and value.
• The first element of the ResultBuffer has to be the registered XData application name with the integer 1001 or the enum value DxfCode.ExtendedDataRegAppName.
• The DxfCode.ExtendedDataLayerName enum value (with integer 1003) specifies that the value will be a layer name. Whether the layer has to present or not in the current database may need further exploration.
• The DxfCode.ExtendedDataBinaryChunk enum value (with integer 1004) specifies that the XData value will be some binary chunk. We will address it further in the future.
• The DxfCode.ExtendedDataHandle enum value (with integer 1005) specifies that the XData value is supposed to be a valid AutoCAD object handle. If it is not a good object handle or the object it references to has been deleted, the Audio command will report an error and the Fix option will set it as NULL or empty.
• The DxfCode.ExtendedDataXCoordinate enum value (with integer 1010) and the DxfCode.ExtendedDataWorldXCoordinate (with integer 1011) specify that the XData value will be a 3D point.
• When the two enum values (1010 or 1011) are specified as the XData type, their value objects should be of type Point3d.
• The DxfCode.ExtendedDataYCoordinate (1020) and the DxfCode.ExtendedDataZCoordinate (1030) enum values are there for other purposes. They should not be used in the TypedValue constructors. Otherwise, exceptions would just occur.
• The same apply to the ExtendedDataWorldYCoordinate (1021) and the ExtendedDataWorldYCoordinate (1031) enum values.
• Though the DxfCode.ExtendedDataWorldXDisp (1012) and the DxfCode.ExtendedDataWorldXDir (1013) indicate that the XData value should be a displacement, direction, or a vector, the TypedValue constructor does not accept a Vector3d object! They still only accept the type of Point3d!
• Once again, the DxfCode.ExtendedDataWorldYDisp(1022)/DxfCode.ExtendedDataWorldZDisp(1032) and DxfCode.ExtendedDataWorldYDir(1023)/DxfCode.ExtendedDataWorldZDir(1033) are there for other purposes. They should not be used in the TypedValue constructors. Otherwise, exceptions would just occur.
• The DxfCode.ExtendedDataControlString indicates that the XData value can be either "{" or “}” and the two symbols must be balanced in the whole XData group. They can be nested.
• The DxfCode.ExtendedDataReal (1040), DxfCode.ExtendedDataDist(1041), DxfCode.ExtendedDataScale, (1042), DxfCode.ExtendedDataInteger16 (1070) and DxfCode.ExtendedDataInteger32 (1071) are straightforward as their names suggest.             The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard)provides project wizards in C#, VB.NET and CLI/Managed C++, and various item wizards such as Event Handlers, Command/LispFunction Definers, and Entity/Draw Jiggers in both C# and VB.NET, to help program AutoCAD addins.


页: [1]
查看完整版本: 【转载】将C# class 序列化后存储到AutoCAD实体的XRecord中