csharp_com
using System;<BR>using Autodesk.AutoCAD.DatabaseServices;<BR>using Autodesk.AutoCAD.Runtime;<BR>using Autodesk.AutoCAD.Geometry;<BR>using Autodesk.AutoCAD.ApplicationServices;<BR>using System.Reflection;<BR>using System.IO;<BR>using System.Collections;<BR>using System.Runtime.InteropServices;<BR>using Autodesk.AutoCAD.Interop;<BR>using Autodesk.AutoCAD.Interop.Common;<BR>using System.Diagnostics;<BR>using Autodesk.AutoCAD.PlottingServices;<BR>using Autodesk.AutoCAD.Colors;<BR>using DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager;namespace setenv<BR>{
public class entities_com<BR> {<BR> private AcadApplication acadApp;<BR> private AcadDocument acadDoc;
public entities_com()<BR> {<BR> acadApp=(AcadApplication)Application.AcadApplication;<BR> acadDoc=acadApp.ActiveDocument;<BR> }
//添加新线型 <BR> public void loadLintType(string ltname)<BR> {<BR> bool hasThisLineType=false;<BR> foreach (AcadLineType entry in acadDoc.Linetypes)<BR> if(entry.Name==ltname) <BR> {<BR> hasThisLineType=true;<BR> }<BR> if(!hasThisLineType)<BR> {<BR> acadDoc.Linetypes.Load(ltname,"acad.lin");<BR> CommandLinePrompts.Message(string.Format("加载线型 {0}",ltname));<BR> }<BR> }
//插入块<BR> public bool insertBlock(Point3d basePt,string blkname)<BR> {<BR> double[] pt=new double;<BR> AcadBlockReference blockRefObj;<BR> pt=basePt;<BR> pt=basePt;<BR> pt=basePt;<BR> blockRefObj=acadDoc.ModelSpace.InsertBlock(pt,blkname,1.0,1.0,1.0,0,"");
if(blockRefObj!=null)<BR> {<BR> blockRefObj.Explode(); <BR> return true;<BR> }<BR> else<BR> {<BR> CommandLinePrompts.Message(string.Format("未找到 {0} 块!",blkname));<BR> return false;<BR> }<BR> }
public bool setTextStyle(string tstname)<BR> {<BR> AcadTextStyle newText=acadDoc.TextStyles.Add(tstname);<BR> newText.BigFontFile="hztxt.shx";<BR> newText.fontFile="simplex.shx";<BR> newText.Height=5.0;<BR> newText.Width =0.7;<BR> return true;<BR> }
}
}
调用
<BR> public static void mycmd2()<BR> {<BR> entities_com ets=new entities_com();<BR> ets.setTextStyle("hz1");<BR> }<BR> <BR> public static void mycmd3()<BR> {<BR> entities_com ets=new entities_com();<BR> ets.loadLintType("DASHDOT");<BR> Point3d basePt=new Point3d(0,0,0);<BR> ets.insertBlock(basePt,"headA.dwg");<BR> }
页:
[1]