①: 隱藏實(shí)體
在CAD的開(kāi)發(fā)中,有時(shí)候我們需要根據(jù)用戶(hù)的需求隱藏和顯示一些實(shí)體,對(duì)于實(shí)體本身的屬性Visible當(dāng)然可以實(shí)現(xiàn)隱藏、顯示實(shí)體,不過(guò),除此之外,我們還可以將一個(gè)層上的實(shí)體同時(shí)隱藏起來(lái),這就要使用LayerTableRecord中的IsOff屬性,并且隱藏的實(shí)體ObjectId可以出現(xiàn)在SelectAll()的集合中.當(dāng)然,他們之間還是有區(qū)別的,當(dāng)你用Ctrl+A,選中當(dāng)前活動(dòng)文檔的全部實(shí)體是,你就會(huì)發(fā)現(xiàn)原來(lái)他們之間區(qū)別。
簡(jiǎn)單的測(cè)試程序:


2 [CommandMethod("TestLayer")]
3 public void TestLayerVis()
4 {
5 //選擇一點(diǎn)創(chuàng)建實(shí)體
6 PromptPointOptions opt = new PromptPointOptions("選擇起始點(diǎn):");
7 PromptPointResult res = ed.GetPoint(opt);
8 if (PromptStatus.OK == res.Status)
9 {
10 Point3d sPt = res.Value;
11 using (Transaction trans = db.TransactionManager.StartTransaction())
12 {
13 BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
14 BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
15 //直線(xiàn),其所在層為默認(rèn)的層
16 Line line = new Line();
17 line.StartPoint = sPt;
18 line.EndPoint = new Point3d(sPt.X + 100, sPt.Y + 50, 0);
19 //圓,指定層
20 Circle c = new Circle(sPt, new Vector3d(0, 0, 1), 30);
21 c.LayerId = CreateLayer("TestLayer");
22 line.Visible = false; //不顯示實(shí)體
23 btr.AppendEntity(line);
24 btr.AppendEntity(c);
25 trans.AddNewlyCreatedDBObject(line, true);
26 trans.AddNewlyCreatedDBObject(c, true);
27
28 LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead);
29 LayerTableRecord ltr = (LayerTableRecord)trans.GetObject(CreateLayer("TestLayer"), OpenMode.ForWrite);
30 ltr.IsOff = true; //關(guān)閉圖層,隱藏圖層上的實(shí)體
31
32 trans.Commit();
33 }
34 }
35 }
36
37 //創(chuàng)建一個(gè)圖層
38 private ObjectId CreateLayer(string layerName)
39 {
40 ObjectId objId = ObjectId.Null;
41 using (Transaction trans = db.TransactionManager.StartTransaction())
42 {
43 LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite);
44 if (lt.Has(layerName))
45 {
46 objId = lt[layerName];
47 }
48 else
49 {
50 LayerTableRecord ltr = new LayerTableRecord();
51 ltr.Name = layerName;
52 objId = lt.Add(ltr);
53 trans.AddNewlyCreatedDBObject(ltr, true);
54 trans.Commit();
55 }
56 }
57
58 return objId;
59 }
60 #endregion
②:修改線(xiàn)寬
有的時(shí)候我們?yōu)榱舜蛴〕鰜?lái)的圖片更加的清楚,可能會(huì)設(shè)計(jì)到修改實(shí)體的線(xiàn)寬,對(duì)于多段線(xiàn),我們很容易想到使用ConstantWidth,這樣就可以修改其線(xiàn)寬了,其實(shí),對(duì)于圓或是直線(xiàn)也一樣,不過(guò)我們?cè)谛薷乃麄兊木€(xiàn)寬之前要保證系統(tǒng)變量的lwdisplay的值為1(開(kāi)),這時(shí)我們?cè)僭O(shè)置LineWeight,就可以改變他們的線(xiàn)寬了。
簡(jiǎn)單的測(cè)試程序:


2 [CommandMethod("TestLW")]
3 public void TestLW()
4 {
5 PromptPointOptions opt = new PromptPointOptions("選擇起點(diǎn):");
6 PromptPointResult res = ed.GetPoint(opt);
7 if (PromptStatus.OK == res.Status)
8 {
9 Point3d sPt = res.Value;
10 ObjectId plId = ObjectId.Null;
11 ObjectId circleId = ObjectId.Null;
12 using (Transaction trans = db.TransactionManager.StartTransaction())
13 {
14 BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
15 BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
16
17 //創(chuàng)建一個(gè)多段線(xiàn)
18 Polyline pl = new Polyline();
19 pl.AddVertexAt(0, sPt.Convert2d(new Plane()), 0, 0, 0);
20 pl.AddVertexAt(1, new Point3d(sPt.X + 100, sPt.Y + 50, 0).Convert2d(new Plane()), 0, 0, 0);
21 pl.AddVertexAt(2, new Point3d(sPt.X + 150, sPt.Y - 150, 0).Convert2d(new Plane()), 0, 0, 0);
22
23 //創(chuàng)建一個(gè)圓
24 Circle c = new Circle(sPt, new Vector3d(0, 0, 1), 40);
25
26 plId = btr.AppendEntity(pl);
27 circleId = btr.AppendEntity(c);
28 trans.AddNewlyCreatedDBObject(pl, true);
29 trans.AddNewlyCreatedDBObject(c, true);
30 //修改線(xiàn)寬
31 pl.ConstantWidth = 0.15;
32 c.LineWeight = LineWeight.LineWeight035;//絕對(duì)線(xiàn)寬
33
34 trans.Commit();
35 }
36 }
37 }
38 #endregion
③:多段線(xiàn)凸起
這個(gè)功能一般用在兩條多段線(xiàn)相交時(shí),區(qū)分多段線(xiàn)的走向而特意使相交的多段線(xiàn)在交點(diǎn)出凸起一個(gè)"小弧",在這個(gè)應(yīng)用中,我們會(huì)發(fā)現(xiàn)PolyLine中的AddVertexAt的奇妙之處(插入點(diǎn)的序號(hào)可以小于PLine的節(jié)點(diǎn)數(shù)目,PLine的原有節(jié)點(diǎn)的序號(hào)會(huì)因?yàn)橛行虏迦朦c(diǎn)而自增)。
簡(jiǎn)單的測(cè)試程序:


2 public void TestPolyLine()
3 {
4 PromptPointOptions opt = new PromptPointOptions("選擇起點(diǎn):");
5 PromptPointResult res = ed.GetPoint(opt);
6 if (PromptStatus.OK == res.Status)
7 {
8 Point3d sPt = res.Value;
9 ObjectId plId = ObjectId.Null;
10 ObjectId circleId = ObjectId.Null;
11 Polyline pl = new Polyline();
12 using (Transaction trans = db.TransactionManager.StartTransaction())
13 {
14 BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
15 BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
16
17 //創(chuàng)建一個(gè)多段線(xiàn)
18 pl.AddVertexAt(0, sPt.Convert2d(new Plane()), 0, 0, 0);
19 pl.AddVertexAt(1, new Point3d(sPt.X + 200, sPt.Y + 150, 0).Convert2d(new Plane()), 0, 0, 0);
20 pl.AddVertexAt(2, new Point3d(sPt.X + 400, sPt.Y + 80, 0).Convert2d(new Plane()), 0, 0, 0);
21
22 btr.AppendEntity(pl);
23 trans.AddNewlyCreatedDBObject(pl, true);
24 ////加一個(gè)小弧
25 Point3d pt1 = pl.GetPointAtDist(80);
26 Point3d pt2 = pl.GetPointAtDist(100);
27 pl.AddVertexAt(1, pt1.Convert2d(new Plane()), 0, 0, 0);
28 pl.AddVertexAt(2, pt2.Convert2d(new Plane()), 0, 0, 0);
29 pl.SetBulgeAt(1, 0.78);
30
31 trans.Commit();
32 }
33
34 }
35 }
相關(guān)文章
- 2021-07-20AutoCAD 繪制三維實(shí)體裝配圖 [胡起學(xué),胡進(jìn),胡怡 編著] 2
- 2020-12-19AutoCAD 、SolidWorks實(shí)體仿真建模與應(yīng)用解析 [芮勇勤
- 2012-04-05CAD繪制三維實(shí)體圖形教程及例題下載
- 2011-08-03AutoCAD 2007三維實(shí)體建模手冊(cè)
- 2011-08-03AutoCAD 2009典型案例設(shè)計(jì)(電子教案)PPT
- 2010-12-30斜齒輪三維實(shí)體造型方法的比較研究
- 2010-11-19批量修改NC程式名的程序
- 2009-12-18CAD三維實(shí)體渲染效果圖
- 2009-12-12NEW貴賓的"ZZZ"在cad2008中的應(yīng)用