明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4576|回复: 0

csharp_com

[复制链接]
发表于 2004-5-8 21:35:00 | 显示全部楼层 |阅读模式
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");
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 04:27 , Processed in 0.159577 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表