乐筑天下

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

csharparx ....

[复制链接]

4

主题

7

帖子

3

银币

初来乍到

Rank: 1

铜币
23
发表于 2004-5-8 21:27: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 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);
                       
                }
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

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

© 2020-2025 乐筑天下

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