明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2763|回复: 0

csharparx ....

[复制链接]
发表于 2004-5-8 21:27 | 显示全部楼层 |阅读模式
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 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);

}

评分

参与人数 1威望 +1 金钱 +3 贡献 +1 激情 +1 收起 理由
zfbj + 1 + 3 + 1 + 1 【好评】好程序适合初学者的程序

查看全部评分

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

本版积分规则

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

GMT+8, 2024-4-25 23:08 , Processed in 0.355361 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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