- 积分
- 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 entities_com { private AcadApplication acadApp; private AcadDocument acadDoc;
public entities_com() { acadApp=(AcadApplication)Application.AcadApplication; acadDoc=acadApp.ActiveDocument; }
//添加新线型 public void loadLintType(string ltname) { bool hasThisLineType=false; foreach (AcadLineType entry in acadDoc.Linetypes) if(entry.Name==ltname) { hasThisLineType=true; } if(!hasThisLineType) { acadDoc.Linetypes.Load(ltname,"acad.lin"); CommandLinePrompts.Message(string.Format("加载线型 {0}",ltname)); } }
//插入块 public bool insertBlock(Point3d basePt,string blkname) { double[] pt=new double[3]; AcadBlockReference blockRefObj; pt[0]=basePt[0]; pt[1]=basePt[1]; pt[2]=basePt[2]; blockRefObj=acadDoc.ModelSpace.InsertBlock(pt,blkname,1.0,1.0,1.0,0,"");
if(blockRefObj!=null) { blockRefObj.Explode(); return true; } else { CommandLinePrompts.Message(string.Format("未找到 {0} 块!",blkname)); return false; } }
public bool setTextStyle(string tstname) { AcadTextStyle newText=acadDoc.TextStyles.Add(tstname); newText.BigFontFile="hztxt.shx"; newText.fontFile="simplex.shx"; newText.Height=5.0; newText.Width =0.7; return true; }
}
}
调用
[CommandMethod("mycmd2")] public static void mycmd2() { entities_com ets=new entities_com(); ets.setTextStyle("hz1"); } [CommandMethod("mycmd3")] public static void mycmd3() { entities_com ets=new entities_com(); ets.loadLintType("DASHDOT"); Point3d basePt=new Point3d(0,0,0); ets.insertBlock(basePt,"headA.dwg"); } |
|