- 积分
- 403
- 明经币
- 个
- 注册时间
- 2003-4-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
using System; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.ApplicationServices; using System.Reflection; using System.IO; using System.Collections; using System.Runtime.InteropServices; using Autodesk.AutoCAD.Interop; using Autodesk.AutoCAD.Interop.Common; using System.Diagnostics; using Autodesk.AutoCAD.PlottingServices; using Autodesk.AutoCAD.Colors; using DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager;
namespace setenv { public class entites { private Database db;
public entites() { db= Application.DocumentManager.MdiActiveDocument.Database; } //创建多义线 public bool createPolyline(Point3dCollection ptArr,string lyrname) { DBTransMan tm= db.TransactionManager; Transaction myT = tm.StartTransaction();
BlockTable bt=(BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false); BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite,false); try { DoubleCollection blgs=new DoubleCollection(); for(int i=1;i<=ptArr.Count;i++) blgs.Add(0.0); Polyline2d pline=new Polyline2d(Poly2dType.SimplePoly,ptArr,0.0,false,0.0,0.0,blgs); pline.Layer=lyrname; btr.AppendEntity(pline); tm.AddNewlyCreatedDBObject(pline, true); myT.Commit(); } finally { bt.Close(); btr.Close(); myT.Dispose(); } return true; } //创建新层 public bool createNewLayer(string lyrname,string ltname,short lyrcolor) { ObjectId objId=db.LayerTableId ; LayerTable lyrTb=(LayerTable)objId.Open(OpenMode.ForWrite); try { if (!lyrTb.Has(lyrname)) { LayerTableRecord lyrTbr=new LayerTableRecord(); lyrTbr.Name=lyrname; lyrTbr.IsFrozen=false; lyrTbr.IsOff=false; lyrTbr.ViewportVisibilityDefault =true; lyrTbr.IsLocked=false; Color color1=new Color() ; color1.ColorIndex =lyrcolor; lyrTbr.Color=color1; lyrTbr.LinetypeObjectId =getLineTypeId(ltname); lyrTb.Add(lyrTbr); lyrTbr.Close(); } } finally { lyrTb.Close(); } return true; } //获取ltname 线型ID private ObjectId getLineTypeId(string ltname) { ObjectId objId=db.LinetypeTableId ; ObjectId id1=new ObjectId(); LinetypeTable ltTb=(LinetypeTable)objId.Open(OpenMode.ForRead); if(!ltTb.Has(ltname)) id1= ltTb["CONTINUOUS"]; else id1= ltTb[ltname]; ltTb.Close(); return id1; }
// protected void Dispose( ) { // }
}
}
调用
[CommandMethod("mycmd1")] public static void mycmd1() { Point3dCollection ptArr=new Point3dCollection(); Point3d pt1=new Point3d(0,0,0); Point3d pt2=new Point3d(1,1,0); Point3d pt3=new Point3d(2,2,0); ptArr.Add(pt1); ptArr.Add(pt2); ptArr.Add(pt3); string lyrname="0"; entites ets=new entites(); ets.createPolyline(ptArr,lyrname); ets.createNewLayer("1","HIDDEN",2); } |
评分
-
参与人数 1 | 威望 +1 |
金钱 +3 |
贡献 +1 |
激情 +1 |
收起
理由
|
zfbj
| + 1 |
+ 3 |
+ 1 |
+ 1 |
【好评】好程序适合初学者的程序 |
查看全部评分
|