获取entities线型 line type - 小众知识

获取entities线型 line type

2013年01月27日 14:18:05 苏内容
  标签: C#/cad/Entity
阅读:7328

Each curve entity stores the line type it uses to draw. The information is stored as object id (“LinetypeId”) in each curve object. But some cases, the curve will be using its layer’s line type.  In such cases, you need to get the layer line type to identify the actual line type used be the curve.

[CommandMethod("LineTypeName")]

public void LineTypeName()

{

    Document doc = Application.DocumentManager.MdiActiveDocument;

    Database db = doc.Database;

    Editor ed = doc.Editor;

 

    PromptEntityOptions options =

              new PromptEntityOptions("\nSelect curve : ");

    options.SetRejectMessage("\nSelect only curves");

    options.AddAllowedClass(typeof(Curve), false);

 

    PromptEntityResult acSSPrompt = ed.GetEntity(options);

 

    if (acSSPrompt.Status != PromptStatus.OK)

        return;

 

    using (Transaction tx = db.TransactionManager.StartTransaction())

    {

        Curve ent = tx.GetObject(acSSPrompt.ObjectId,

                               OpenMode.ForRead) as Curve;

 

        ObjectId id = ent.LinetypeId;

 

        if (id == db.ByLayerLinetype)

        {

            //get the layer..

            ObjectId layerId = ent.LayerId;

            LayerTableRecord layer = tx.GetObject(layerId,

                               OpenMode.ForRead) as LayerTableRecord;

 

            id = layer.LinetypeObjectId;

        }

        //open the linetype table record

        LinetypeTableRecord linetype = tx.GetObject(id,

                            OpenMode.ForRead) as LinetypeTableRecord;

 

        ed.WriteMessage("Line type used by curve is " +

                                               linetype.Name + "\n");

 

        tx.Commit();

    }

}


扩展阅读