newer 发表于 2021-1-8 23:48:11

.NET: How to set the Lineweight of a Line



问题:
How do I create a line and append it to the current space, but also setting its LineWeight?

解答:



// creates a line and sets the lineweight for it, by Fenton Webb, DevTech, Autodesk
public void CreateLine()
{
    // create a new line
    Line line = new Line(new Point3d(0, 0, 0), new Point3d(100, 100, 0));

    // set the lineweight for it
    line.LineWeight = LineWeight.LineWeight211;

    // add the object to the current space
    Database dwg = HostApplicationServices.WorkingDatabase;


    // make sure lineweights are turn on
    dwg.LineWeightDisplay = true;


    // get the transaction manager
    Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = dwg.TransactionManager;
    // start a new transaction
    using (Transaction myT = tm.StartTransaction())
    {
      try
      {
            // get the current space and open it for write
            BlockTableRecord btr = (BlockTableRecord)tm.GetObject(dwg.CurrentSpaceId, OpenMode.ForWrite, false);


            // add it to the blocktable record
            btr.AppendEntity(line);


            // now to the tranaction manager
            tm.AddNewlyCreatedDBObject(line, true);


            // all ok, lets commit it
            myT.Commit();
      }
      catch
      {
            // if we failed, then abort
            myT.Abort();
      };
    }
}


wzjck01 发表于 2021-6-25 09:07:02

学习,学习。
页: [1]
查看完整版本: .NET: How to set the Lineweight of a Line