乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 13|回复: 0

csharp_com

[复制链接]

4

主题

7

帖子

3

银币

初来乍到

Rank: 1

铜币
23
发表于 2004-5-8 21:35:00 | 显示全部楼层 |阅读模式
using System;
using Autodesk..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");
                }
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 02:34 , Processed in 0.659612 second(s), 54 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表