马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
问题:
How do I create a line and append it to the current space, but also setting its LineWeight?
解答:
- [Autodesk.AutoCAD.Runtime.CommandMethod("CreateLine")]
- // 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();
- };
- }
- }
|