AutoCAD二次开发实验二Word文件下载.docx
- 文档编号:20878186
- 上传时间:2023-01-26
- 格式:DOCX
- 页数:14
- 大小:271.52KB
AutoCAD二次开发实验二Word文件下载.docx
《AutoCAD二次开发实验二Word文件下载.docx》由会员分享,可在线阅读,更多相关《AutoCAD二次开发实验二Word文件下载.docx(14页珍藏版)》请在冰豆网上搜索。
BlockTableRecordbtr=(BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
//把图形对象的记录加入到块表中
pModifyEntID=btr.AppendEntity(lineEnt);
//将直线添加到事务处理中
trans.AddNewlyCreatedDBObject(lineEnt,true);
trans.Commit();
}
运行效果如下图所示
修改直线
ModifyLine"
publicvoidModifyLine()
//打开要修改的图形对象,定义一个实体对象
EntitypEnt=(Entity)trans.GetObject(pModifyEntID,OpenMode.ForWrite);
//修改颜色
pEnt.ColorIndex=5;
pEnt.Close();
2,创建圆对象
CreatCir"
publicvoidCircle()
//声明圆对象
Circlec=newCircle();
c.Center=newPoint3d(0,0,0);
c.Radius=100;
//启动事务
//创建块表
BlockTablec_block=(BlockTable)trans.GetObject(db.BlockTableId,OpenMode.ForRead);
//读取,0
BlockTableRecordc_block_record=(BlockTableRecord)trans.GetObject(c_block[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
//写入,1
c_block_record.AppendEntity(c);
//块表记录追加实体,把图形对象的记录加入到块表记录
trans.AddNewlyCreatedDBObject(c,true);
//将圆添加到事务处理中
//提交事务
3,创建圆弧对象
//创建圆弧
[CommandMethod("
CreatArc"
publicvoidCreatArc()
//创建圆弧,指定圆心,半径,起始角,终止角
ArcpArc=newArc(newPoint3d(100,100,0),3000,0,30);
BlockTablepBlkTbl=(BlockTable)trans.GetObject(db.BlockTableId,OpenMode.ForRead);
BlockTableRecordpBlkTblRec=(BlockTableRecord)trans.GetObject(pBlkTbl[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
//将图形对象的记录加到块表记录中
pBlkTblRec.AppendEntity(pArc);
//将圆弧添加到事务处理中
trans.AddNewlyCreatedDBObject(pArc,true);
4,创建多段线:
//创建多段线
CreatPloyline"
publicvoidcreatePloyline1()
Polylinepl=newPolyline(5);
Point2dp1=newPoint2d(50,10);
Point2dp2=newPoint2d(100,30);
Point2dp3=newPoint2d(150,60);
Point2dp4=newPoint2d(200,90);
Point2dp5=newPoint2d(250,120);
Point2dCollectionpc=newPoint2dCollection();
pc.Add(p1);
pc.Add(p2);
pc.Add(p3);
pc.Add(p4);
pc.Add(p5);
for(inti=0;
i<
5;
i++)
pl.AddVertexAt(i,pc[i],0.5,5,5);
btr.AppendEntity(pl);
trans.AddNewlyCreatedDBObject(pl,true);
5,创建椭圆
//创建椭圆
CEllipse"
publicvoidEllipse()
EllipsepEllipse=newEllipse(newPoint3d(150,150,0),newVector3d(0,0,50),newVector3d(50,50,0),0.8,0,0);
btr.AppendEntity(pEllipse);
trans.AddNewlyCreatedDBObject(pEllipse,true);
6,创建样条曲线
//创建样条曲线
CreatSpline"
publicvoidCreateSpline()
Point3dp1=newPoint3d(50,30,0);
Point3dp2=newPoint3d(100,60,0);
Point3dp3=newPoint3d(150,520,0);
Point3dp4=newPoint3d(200,240,0);
Point3dp5=newPoint3d(250,300,0);
Point3dCollectionpc=newPoint3dCollection();
Splinespline=newSpline(pc,2,5);
btr.AppendEntity(spline);
trans.AddNewlyCreatedDBObject(spline,true);
7,创建面域
//创建面域°
Polygon"
publicvoidCreatePolygon()
using(TransactionTrans=db.TransactionManager.StartTransaction())
Point3dcenter=newPoint3d(50,50,0);
Circleentity=newCircle(center,Vector3d.ZAxis,150);
DBObjectCollectioncurveSegments=newDBObjectCollection();
DBObjectCollectionregions=newDBObjectCollection();
curveSegments.Add(entity);
regions=Region.CreateFromCurves(curveSegments);
RegionnewRegion=(Region)regions[0];
newRegion.SetDatabaseDefaults();
BlockTablebt=(BlockTable)Trans.GetObject(db.BlockTableId,OpenMode.ForRead);
BlockTableRecordbtr=(BlockTableRecord)Trans.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
btr.AppendEntity(newRegion);
Trans.AddNewlyCreatedDBObject(newRegion,true);
Trans.Commit();
8,创建文字
//创建文字
CreatText"
publicvoidAddText()
DBTexttext=newDBText();
text.Position=newPoint3d(5,5,0);
text.ColorIndex=3;
text.TextString="
AutoCAD二次开发!
"
;
MTexttext1=newMText();
text1.Contents="
text1.Color=Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci,2);
btr.AppendEntity(text);
btr.AppendEntity(text1);
trans.AddNewlyCreatedDBObject(text,true);
trans.AddNewlyCreatedDBObject(text1,true);
9,创建填充
代码如下
//创建填充
CreatHatch"
publicvoidAddHatch()
Circlecircle=newCircle();
circle.Center=newPoint3d(150,150,0);
circle.Radius=200;
btr.AppendEntity(circle);
trans.AddNewlyCreatedDBObject(circle,true);
ObjectIdCollectioncollection=newObjectIdCollection();
collection.Add(circle.ObjectId);
Hatchhatch=newHatch();
hatch.Elevation=0;
hatch.HatchStyle=HatchStyle.Normal;
hatch.ColorIndex=5;
hatch.SetHatchPattern(HatchPatternType.PreDefined,"
SOLID"
);
hatch.AppendLoop(HatchLoopTypes.Default,collection);
hatch.EvaluateHatch(true);
btr.AppendEntity(hatch);
trans.AddNewlyCreatedDBObject(hatch,true);
10,创建三维实体
Create3DSolid"
publicvoidCreate3DSolid()
{Databasedb=HostApplicationServices.WorkingDatabase;
{Point3dp1=newPoint3d(50,50,0);
Point3dp2=newPoint3d(110,100,0);
Point3dp3=newPoint3d(150,160,0);
Point3dp4=newPoint3d(210,190,0);
Point3dp5=newPoint3d(270,230,0);
Polyline3dPolyline3d=newPolyline3d(0,pc,true);
DBObjectCollectiondbobc=newDBObjectCollection();
dbobc.Add(Polyline3d);
regions=Region.CreateFromCurves(dbobc);
Regionregion=(Region)regions[0];
Solid3dsd=newSolid3d();
sd.Revolve(region,newPoint3d(0,0,0),Vector3d.XAxis,360);
PModifyEntID=btr.AppendEntity(sd);
trans.AddNewlyCreatedDBObject(sd,true);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- AutoCAD 二次开发 实验