日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

autoCAD 创建对象 使用面域 创建图案填充

發(fā)布時(shí)間:2023/12/20 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 autoCAD 创建对象 使用面域 创建图案填充 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

創(chuàng)建對(duì)象

在 AutoCAD 中經(jīng)常有多種不同的方法可以創(chuàng)建相同的圖形對(duì)象。雖然 .NET API 沒(méi)有提供同樣的創(chuàng)建對(duì)象的組合,但是它除為每一個(gè)對(duì)象類型都提供一個(gè)基本的對(duì)象構(gòu)造函數(shù)外,也提供了對(duì)象構(gòu)造函數(shù)的許多重載版本。

例如,在 AutoCAD 中創(chuàng)建圓有四種不同方法:

  • (1) 通過(guò)指定圓心和半徑、
  • (2) 通過(guò)定義直徑的兩點(diǎn)、
  • (3) 通過(guò)定義圓周的三點(diǎn)或
  • (4) 通過(guò)兩個(gè)切點(diǎn)和一個(gè)半徑。
  • 但是,在 .NET API 中只提供了兩種創(chuàng)建圓的方法。一個(gè)方法不接受任何參數(shù),而第二個(gè)需要一個(gè)中心點(diǎn),圓的法線方向和半徑。

注意使用 New 關(guān)鍵字創(chuàng)建對(duì)象,然后使用 Add 或 AppendEntity 追加到父對(duì)象中,使用哪個(gè)方法要根據(jù)使用的是容器(符號(hào)表或字典) 還是塊表記錄對(duì)象。

為新對(duì)象指定默認(rèn)屬性值

當(dāng)創(chuàng)建一個(gè)新圖形對(duì)象后,應(yīng)該調(diào)用新對(duì)象的 SetDatabaseDefaults 方法。 SetDatabaseDefaults 方法根據(jù)在當(dāng)前文檔的數(shù)據(jù)庫(kù)中定義的當(dāng)前圖元的值設(shè)置下列各項(xiàng)圖元的屬性值。

  • Color
  • Layer
  • Linetype
  • Linetype scale
  • Lineweight
  • Plot style name
  • Visibility

確定父對(duì)象
創(chuàng)建直線
創(chuàng)建曲線對(duì)象
創(chuàng)建 Point 對(duì)象
創(chuàng)建實(shí)體填充區(qū)域
使用面域
創(chuàng)建圖案填充

確定父對(duì)象

圖形對(duì)象被添加到塊表記錄(BlockTableRecord)對(duì)象中,像模型或圖紙空間。用戶通過(guò)塊表對(duì)象引用代表模型和圖紙空間的塊。如果想在當(dāng)前空間代替在指定空間中工作,可以從當(dāng)前數(shù)據(jù)庫(kù)的 CurrentSpaceId 屬性獲得當(dāng)前空間的 ObjectId。

模型或圖紙空間的塊表記錄的 ObjectID 可以使用 DatabaseServices 命名空間下的 SymbolUtilityServices 類的屬性或 GetBlockModelSpaceId 和 GetBlockPaperSpaceId 方法從塊表對(duì)象中獲得。

訪問(wèn)模型空間、圖紙空間或當(dāng)前空間

下列示例演示如何訪問(wèn)與模型空間、圖紙空間或當(dāng)前空間相關(guān)聯(lián)的塊表記錄。一旦塊表記錄被引用,一個(gè)新的直線將被添加到塊表記錄中。

Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.EditorInput<CommandMethod("AccessSpace")> _ Public Sub AccessSpace()'' 獲得當(dāng)前文檔和數(shù)據(jù)庫(kù) Get the current document and databaseDim acDoc As Document = Application.DocumentManager.MdiActiveDocumentDim acCurDb As Database = acDoc.Database''啟動(dòng)一個(gè)事務(wù) Start a transactionUsing acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()'' 以只讀方式打開(kāi)塊表 Open the Block table for readDim acBlkTbl As BlockTableacBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)'' 以只讀方式打開(kāi)塊表記錄 Open the Block table record for readDim acBlkTblRec As BlockTableRecord'' 請(qǐng)求打開(kāi)哪一個(gè)表記錄 Request which table record to openDim pKeyOpts As PromptKeywordOptions = New PromptKeywordOptions("")pKeyOpts.Message = vbLf & "Enter which space to create the line in "pKeyOpts.Keywords.Add("Model")pKeyOpts.Keywords.Add("Paper")pKeyOpts.Keywords.Add("Current")pKeyOpts.AllowNone = FalsepKeyOpts.AppendKeywordsToMessage = TrueDim pKeyRes As PromptResult = acDoc.Editor.GetKeywords(pKeyOpts)If pKeyRes.StringResult = "Model" Then'' 從塊表獲得模型空間的 ObjectID Get the ObjectID for Model space from the Block tableacBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _OpenMode.ForWrite)ElseIf pKeyRes.StringResult = "Paper" Then'' 從塊表記錄獲得圖紙空間的ObjectID Get the ObjectID for Paper space from the Block tableacBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.PaperSpace), _OpenMode.ForWrite)Else'' 從數(shù)據(jù)庫(kù)中獲得當(dāng)前空間的ObjectID Get the ObjectID for the current space from the databaseacBlkTblRec = acTrans.GetObject(acCurDb.CurrentSpaceId, _OpenMode.ForWrite)End If'' 創(chuàng)建一條起點(diǎn)為2,5 終點(diǎn)為 10,7 的直線 Create a line that starts at 2,5 and ends at 10,7Dim acLine As Line = New Line(New Point3d(2, 5, 0), _New Point3d(10, 7, 0))acLine.SetDatabaseDefaults()'' 添加新對(duì)象到塊表記錄和事務(wù)中 Add the new object to the block table record and the transactionacBlkTblRec.AppendEntity(acLine)acTrans.AddNewlyCreatedDBObject(acLine, True)'' 保存新的直線到數(shù)據(jù)庫(kù)中 Save the new line to the databaseacTrans.Commit()End Using End Sub

創(chuàng)建直線

直線是 AutoCAD 中最基本的對(duì)象。用戶可以創(chuàng)建各種直線—單一直線、帶圓弧和不帶圓弧的多線段。通常,可以通過(guò)指定坐標(biāo)點(diǎn)來(lái)繪制直線。直線被創(chuàng)建后,它會(huì)從圖形數(shù)據(jù)庫(kù)繼承當(dāng)前設(shè)置,像圖層、線型和顏色。

若要?jiǎng)?chuàng)建直線,可以創(chuàng)建下列任一個(gè)對(duì)象的新實(shí)例:

  • Line
  • 創(chuàng)建一個(gè)直線。
  • Polyline
  • 創(chuàng)建二維輕量多段線
  • MLine
  • 創(chuàng)建多線
  • Polyline2D
  • 創(chuàng)建二維多段線
  • Polyline3D
  • 創(chuàng)建三維多段線

創(chuàng)建直線對(duì)象

本例添加一條起點(diǎn)為(5,5,0),終點(diǎn)為(12,3,0)的直線到模型空間。

Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry<CommandMethod("AddLine")> _ Public Sub AddLine()'' 獲得當(dāng)前文檔和數(shù)據(jù)庫(kù) Get the current document and databaseDim acDoc As Document = Application.DocumentManager.MdiActiveDocumentDim acCurDb As Database = acDoc.Database''啟動(dòng)一個(gè)事務(wù) Start a transactionUsing acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()'' 以只讀方式打開(kāi)塊表 Open the Block table for readDim acBlkTbl As BlockTableacBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)'' 以寫方式打開(kāi)模型空間塊表記錄 Open the Block table record Model space for writeDim acBlkTblRec As BlockTableRecordacBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _OpenMode.ForWrite)'' 創(chuàng)建一條起點(diǎn)為(5,5,0),終點(diǎn)為(12,3,0)的直線 Create a line that starts at 5,5 and ends at 12,3Dim acLine As Line = New Line(New Point3d(5, 5, 0), _New Point3d(12, 3, 0))acLine.SetDatabaseDefaults()'' 添加新對(duì)象到塊表記錄和事務(wù)中 Add the new object to the block table record and the transactionacBlkTblRec.AppendEntity(acLine)acTrans.AddNewlyCreatedDBObject(acLine, True)'' 保存新對(duì)象到數(shù)據(jù)庫(kù)中 Save the new object to the databaseacTrans.Commit()End Using End Sub

創(chuàng)建多段線對(duì)象

本例添加使用二維坐標(biāo)(2,4)、(4,2) 和 (6,4)創(chuàng)建的一條有兩個(gè)直線段的輕量多段線到模型空間中。

Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry<CommandMethod("AddLightweightPolyline")> _ Public Sub AddLightweightPolyline()'' 獲得當(dāng)前文檔和數(shù)據(jù)庫(kù) Get the current document and databaseDim acDoc As Document = Application.DocumentManager.MdiActiveDocumentDim acCurDb As Database = acDoc.Database''啟動(dòng)一個(gè)事務(wù) Start a transactionUsing acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()'' 以只讀方式打開(kāi)塊表 Open the Block table for readDim acBlkTbl As BlockTableacBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)'' 以寫方式打開(kāi)模型空間塊表記錄 Open the Block table record Model space for writeDim acBlkTblRec As BlockTableRecordacBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _OpenMode.ForWrite)'' 創(chuàng)建一條有兩段的多段線 Create a polyline with two segments (3 points)Dim acPoly As Polyline = New Polyline()acPoly.SetDatabaseDefaults()acPoly.AddVertexAt(0, New Point2d(2, 4), 0, 0, 0)acPoly.AddVertexAt(1, New Point2d(4, 2), 0, 0, 0)acPoly.AddVertexAt(2, New Point2d(6, 4), 0, 0, 0)'' 添加新對(duì)象到塊表記錄和事務(wù)中 Add the new object to the block table record and the transactionacBlkTblRec.AppendEntity(acPoly)acTrans.AddNewlyCreatedDBObject(acPoly, True)'' 保存新對(duì)象到數(shù)據(jù)庫(kù)中 Save the new object to the databaseacTrans.Commit()End Using End Sub

創(chuàng)建曲線對(duì)象

用戶可以使用 AutoCAD 創(chuàng)建各種曲線對(duì)象,包括樣條曲線、螺旋線、圓、圓弧和橢圓。所有的曲線都在當(dāng)前 UCS 的 XY 平面上創(chuàng)建。

若要?jiǎng)?chuàng)建曲線,可以創(chuàng)建下面任一個(gè)對(duì)象的新實(shí)例:

  • Arc
  • 使用給定的中心點(diǎn),半徑,起始和終止角度創(chuàng)建圓弧。
  • Circle
  • 使用給定的中心點(diǎn)和半徑創(chuàng)建圓。
  • Ellipse
  • 使用給定的中心點(diǎn),長(zhǎng)軸點(diǎn),和半徑比創(chuàng)建橢圓。
  • Spline
  • 創(chuàng)建一個(gè)二次或三次的曲線曲面的非均勻有理B樣條(非均勻 B 樣條曲線)曲線。
  • Helix
  • 創(chuàng)建一個(gè)二維或三維的螺旋線對(duì)象。

創(chuàng)建圓對(duì)象
創(chuàng)建圓弧對(duì)象
創(chuàng)建樣條曲線對(duì)象

創(chuàng)建圓對(duì)象

本例在模型空間中創(chuàng)建一個(gè)中心點(diǎn)在 (2,3,0) ,半徑為4.25 的圓。

Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry<CommandMethod("AddCircle")> _ Public Sub AddCircle()'' 獲得當(dāng)前文檔和數(shù)據(jù)庫(kù) Get the current document and databaseDim acDoc As Document = Application.DocumentManager.MdiActiveDocumentDim acCurDb As Database = acDoc.Database''啟動(dòng)一個(gè)事務(wù) Start a transactionUsing acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()'' 以只讀方式打開(kāi)塊表 Open the Block table for readDim acBlkTbl As BlockTableacBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)'' 以寫方式打開(kāi)模型空間塊表記錄 Open the Block table record Model space for writeDim acBlkTblRec As BlockTableRecordacBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _OpenMode.ForWrite)'' 創(chuàng)建一個(gè)中心點(diǎn)在 (2,3,0) ,半徑為4.25 的圓 Create a circle that is at 2,3 with a radius of 4.25Dim acCirc As Circle = New Circle()acCirc.SetDatabaseDefaults()acCirc.Center = New Point3d(2, 3, 0)acCirc.Radius = 4.25'' 添加新對(duì)象到塊表記錄和事務(wù)中 Add the new object to the block table record and the transactionacBlkTblRec.AppendEntity(acCirc)acTrans.AddNewlyCreatedDBObject(acCirc, True)'' 保存新對(duì)象到數(shù)據(jù)庫(kù)中 Save the new object to the databaseacTrans.Commit()End Using End Sub

創(chuàng)建圓弧對(duì)象

本例在模型空間中創(chuàng)建一個(gè)中心點(diǎn)在 (6.25,9.125,0),半徑為6,起始角度為1.117(64度),終點(diǎn)角度為3.5605(204度)的圓弧。

Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry<CommandMethod("AddArc")> _ Public Sub AddArc()'' 獲得當(dāng)前文檔和數(shù)據(jù)庫(kù) Get the current document and databaseDim acDoc As Document = Application.DocumentManager.MdiActiveDocumentDim acCurDb As Database = acDoc.Database''啟動(dòng)一個(gè)事務(wù) Start a transactionUsing acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()'' 以只讀方式打開(kāi)塊表 Open the Block table for readDim acBlkTbl As BlockTableacBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)'' 以寫方式打開(kāi)模型空間塊表記錄 Open the Block table record Model space for writeDim acBlkTblRec As BlockTableRecordacBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _OpenMode.ForWrite)'' 創(chuàng)建一個(gè)中心點(diǎn)在 (6.25,9.125,0),半徑為6,起始角度為1.117(64度),終點(diǎn)角度為3.5605(204度)的圓弧。 Create an arc that is at 6.25,9.125 with a radius of 6, and'' starts at 64 degrees and ends at 204 degreesDim acArc As Arc = New Arc(New Point3d(6.25, 9.125, 0), _6, 1.117, 3.5605)acArc.SetDatabaseDefaults()'' 添加新對(duì)象到塊表記錄和事務(wù)中 Add the new object to the block table record and the transactionacBlkTblRec.AppendEntity(acArc)acTrans.AddNewlyCreatedDBObject(acArc, True)'' 保存新對(duì)象到數(shù)據(jù)庫(kù)中 Save the new object to the databaseacTrans.Commit()End Using End Sub

創(chuàng)建樣條曲線對(duì)象

本例在模型空間中創(chuàng)建一個(gè)使用三個(gè)點(diǎn) (0, 0, 0), (5, 5, 0), 和 (10, 0, 0)創(chuàng)建的圓。樣條曲線的起始和終止切向?yàn)?0.5, 0.5, 0.0)。

Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry<CommandMethod("AddSpline")> _ Public Sub AddSpline()'' 獲得當(dāng)前文檔和數(shù)據(jù)庫(kù) Get the current document and databaseDim acDoc As Document = Application.DocumentManager.MdiActiveDocumentDim acCurDb As Database = acDoc.Database''啟動(dòng)一個(gè)事務(wù) Start a transactionUsing acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()'' 以只讀方式打開(kāi)塊表 Open the Block table for readDim acBlkTbl As BlockTableacBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)'' 以寫方式打開(kāi)模型空間塊表記錄 Open the Block table record Model space for writeDim acBlkTblRec As BlockTableRecordacBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _OpenMode.ForWrite)'' 定義樣條曲線的固定點(diǎn) Define the fit points for the splineDim ptColl As Point3dCollection = New Point3dCollection()ptColl.Add(New Point3d(0, 0, 0))ptColl.Add(New Point3d(5, 5, 0))ptColl.Add(New Point3d(10, 0, 0))''從點(diǎn)(0.5,0.5,0)獲得三維矢量 Get a 3D vector from the point (0.5,0.5,0)Dim vecTan As Vector3d = New Point3d(0.5, 0.5, 0).GetAsVector'' Create a spline through (0, 0, 0), (5, 5, 0), and (10, 0, 0) with a'' start and end tangency of (0.5, 0.5, 0.0)Dim acSpline As Spline = New Spline(ptColl, vecTan, vecTan, 4, 0.0)acSpline.SetDatabaseDefaults()'' 添加新對(duì)象到塊表記錄和事務(wù)中 Add the new object to the block table record and the transactionacBlkTblRec.AppendEntity(acSpline)acTrans.AddNewlyCreatedDBObject(acSpline, True)'' 保存新對(duì)象到數(shù)據(jù)庫(kù)中 Save the new object to the databaseacTrans.Commit()End Using End Sub

創(chuàng)建 Point 對(duì)象

Point 對(duì)象非常有用,例如,可將 Point 對(duì)象用作捕捉的節(jié)點(diǎn)或者偏移對(duì)象的參考點(diǎn)??梢韵鄬?duì)于屏幕或采用絕對(duì)單位來(lái)設(shè)置點(diǎn)的樣式和大小。

數(shù)據(jù)庫(kù)對(duì)象的 Pdmode 和 Pdsize 屬性控制 Point 對(duì)象的外觀。PDMODE 值 0、2、3 和 4 指定要通過(guò)點(diǎn)繪制的圖形。值為 1 時(shí)表示不顯示任何圖形。

?

在上述值上加上 32、64 或 96 表示除了繪制通過(guò)點(diǎn)的圖形以外,還在點(diǎn)的周圍繪制形狀:

?PDSIZE 控制點(diǎn)圖形的尺寸,PDMODE 值為 0 和 1 時(shí)除外。如果設(shè)置為 0,則點(diǎn)圖形的高度是圖形區(qū)高度的 5%。正的 PDSIZE 值指定點(diǎn)圖形的絕對(duì)尺寸。負(fù)值將解釋為視口大小的百分比。重生成圖形時(shí)將重新計(jì)算所有點(diǎn)的大小。

更改 PDMODE 和 PDSIZE 后,現(xiàn)有點(diǎn)的外觀將在下次重新生成圖形時(shí)改變。

創(chuàng)建 Point 對(duì)象并更改其外觀

Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry<CommandMethod("AddPointAndSetPointStyle")> _ Public Sub AddPointAndSetPointStyle()'' 獲得當(dāng)前文檔和數(shù)據(jù)庫(kù) Get the current document and databaseDim acDoc As Document = Application.DocumentManager.MdiActiveDocumentDim acCurDb As Database = acDoc.Database''啟動(dòng)一個(gè)事務(wù) Start a transactionUsing acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()'' 以只讀方式打開(kāi)塊表 Open the Block table for readDim acBlkTbl As BlockTableacBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)'' 以寫方式打開(kāi)模型空間塊表記錄 Open the Block table record Model space for writeDim acBlkTblRec As BlockTableRecordacBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _OpenMode.ForWrite)'' 在模型空間中創(chuàng)建一個(gè)坐標(biāo)為(4,3,0)的點(diǎn) Create a point at (4, 3, 0) in Model spaceDim acPoint As DBPoint = New DBPoint(New Point3d(4, 3, 0))acPoint.SetDatabaseDefaults()'' 添加新對(duì)象到塊表記錄和事務(wù)中 Add the new object to the block table record and the transactionacBlkTblRec.AppendEntity(acPoint)acTrans.AddNewlyCreatedDBObject(acPoint, True)'' 在圖形中設(shè)置所有點(diǎn)對(duì)象的樣式 Set the style for all point objects in the drawingacCurDb.Pdmode = 34acCurDb.Pdsize = 1'' 保存新對(duì)象到數(shù)據(jù)庫(kù)中 Save the new object to the databaseacTrans.Commit()End Using End Sub

創(chuàng)建實(shí)體填充區(qū)域

用戶可以創(chuàng)建用某種顏色填充的三角形和四邊形的區(qū)域。要更快地得到結(jié)果,請(qǐng)?jiān)陉P(guān)閉 FILLMODE 系統(tǒng)變量時(shí)創(chuàng)建這些區(qū)域,然后再打開(kāi) FILLMODE 以填充完成的區(qū)域。

創(chuàng)建四邊形實(shí)體填充區(qū)域時(shí),第三點(diǎn)和第四點(diǎn)的次序?qū)Q定其形狀。

前兩點(diǎn)定義了多邊形的一條邊。第三點(diǎn)定義在第二點(diǎn)的對(duì)角處。如果第四點(diǎn)設(shè)置為等于第三點(diǎn),則會(huì)創(chuàng)建一個(gè)填充三角形。

創(chuàng)建一個(gè)實(shí)體填充對(duì)象?

下面示例使用坐標(biāo) (0,0,0)、(5,0,0)、(5,8,0) 和 (0,8,0) 在模型空間中創(chuàng)建四邊形實(shí)體(蝴蝶結(jié))。它也使用坐標(biāo)(10, 0, 0), (15, 0, 0), (10, 8, 0)和 (15, 8, 0)創(chuàng)建一個(gè)矩形形狀的四邊形實(shí)體。

Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry<CommandMethod("Add2DSolid")> _ Public Sub Add2DSolid()'' 獲得當(dāng)前文檔和數(shù)據(jù)庫(kù) Get the current document and databaseDim acDoc As Document = Application.DocumentManager.MdiActiveDocumentDim acCurDb As Database = acDoc.Database''啟動(dòng)一個(gè)事務(wù) Start a transactionUsing acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()'' 以只讀方式打開(kāi)塊表 Open the Block table for readDim acBlkTbl As BlockTableacBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)'' 以寫方式打開(kāi)模型空間塊表記錄 Open the Block table record Model space for writeDim acBlkTblRec As BlockTableRecordacBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _OpenMode.ForWrite)'' Create a quadrilateral (bow-tie) solid in Model spaceDim ac2DSolidBow As Solid = New Solid(New Point3d(0, 0, 0), _New Point3d(5, 0, 0), _New Point3d(5, 8, 0), _New Point3d(0, 8, 0))ac2DSolidBow.SetDatabaseDefaults()'' 添加新對(duì)象到塊表記錄和事務(wù)中 Add the new object to the block table record and the transactionacBlkTblRec.AppendEntity(ac2DSolidBow)acTrans.AddNewlyCreatedDBObject(ac2DSolidBow, True)'' Create a quadrilateral (square) solid in Model spaceDim ac2DSolidSqr As Solid = New Solid(New Point3d(10, 0, 0), _New Point3d(15, 0, 0), _New Point3d(10, 8, 0), _New Point3d(15, 8, 0))ac2DSolidSqr.SetDatabaseDefaults()'' 添加新對(duì)象到塊表記錄和事務(wù)中 Add the new object to the block table record and the transactionacBlkTblRec.AppendEntity(ac2DSolidSqr)acTrans.AddNewlyCreatedDBObject(ac2DSolidSqr, True)'' 保存新對(duì)象到數(shù)據(jù)庫(kù)中 Save the new object to the databaseacTrans.Commit()End Using End Sub

?

?使用面域

面域是用戶從稱為環(huán)的閉合形狀創(chuàng)建的二維閉合區(qū)域。環(huán)是由直線和不自交的曲線組成的封閉邊界。環(huán)可以是直線、輕量?jī)?yōu)化多段線、2維和3維多段線,圓、圓弧、橢圓、橢圓弧、樣條曲線、三維面、寬線和實(shí)體的組合。

組成環(huán)的對(duì)象必須是閉合的,或者是通過(guò)與其他對(duì)象共享端點(diǎn)而形成閉合的區(qū)域。所有這些對(duì)象還必須共面(在同一個(gè)平面上)。組成面域的環(huán)必須定義為對(duì)象的數(shù)組。

創(chuàng)建面域

面域是被添加到塊表記錄對(duì)象中的,它是通過(guò)創(chuàng)建一個(gè)面域的實(shí)例然后把它追加到塊表記錄的。在將面域添加到塊表記錄中前,需要根據(jù)對(duì)象創(chuàng)建一個(gè)封閉環(huán)。CreateFromCurves 函數(shù)通過(guò)輸入的對(duì)象數(shù)組組成的每一個(gè)封閉環(huán)創(chuàng)建面域。CreateFromCurves 方法返回和需要一個(gè) DBObjectCollection 對(duì)象。

AutoCAD 將閉合的二維和平面三維多段線轉(zhuǎn)換為獨(dú)立的面域,然后轉(zhuǎn)換形成閉合平面環(huán)的多段線、直線和曲線。如果有兩條以上的曲線共用一個(gè)端點(diǎn),得到的面域可能是不確定的。所以,在使用 CreateFromCurves 方法時(shí),實(shí)際可能會(huì)創(chuàng)建多個(gè)面域。用戶需要追加每一個(gè)創(chuàng)建的面域到塊表記錄對(duì)象中去。

創(chuàng)建一個(gè)簡(jiǎn)單的面域

本例創(chuàng)建從一個(gè)簡(jiǎn)單的圓中創(chuàng)建一個(gè)面域。

Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry<CommandMethod("AddRegion")> _ Public Sub AddRegion()'' 獲得當(dāng)前文檔和數(shù)據(jù)庫(kù) Get the current document and databaseDim acDoc As Document = Application.DocumentManager.MdiActiveDocumentDim acCurDb As Database = acDoc.Database''啟動(dòng)一個(gè)事務(wù) Start a transactionUsing acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()'' 以只讀方式打開(kāi)塊表 Open the Block table for readDim acBlkTbl As BlockTableacBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)'' 以寫方式打開(kāi)模型空間塊表記錄 Open the Block table record Model space for writeDim acBlkTblRec As BlockTableRecordacBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _OpenMode.ForWrite)'' 在內(nèi)存中創(chuàng)建圓 Create an in memory circleUsing acCirc As Circle = New Circle()acCirc.SetDatabaseDefaults()acCirc.Center = New Point3d(2, 2, 0)acCirc.Radius = 5'' 添加圓到對(duì)象數(shù)組中 Adds the circle to an object arrayDim acDBObjColl As DBObjectCollection = New DBObjectCollection()acDBObjColl.Add(acCirc)'' 根據(jù)每一個(gè)閉合環(huán)計(jì)算面域 Calculate the regions based on each closed loopDim myRegionColl As DBObjectCollection = New DBObjectCollection()myRegionColl = Region.CreateFromCurves(acDBObjColl)Dim acRegion As Region = myRegionColl(0)'' 添加新對(duì)象到塊表記錄和事務(wù)中 Add the new object to the block table record and the transactionacBlkTblRec.AppendEntity(acRegion)acTrans.AddNewlyCreatedDBObject(acRegion, True)'' Dispose of the in memory object not appended to the databaseEnd Using'' 保存新對(duì)象到數(shù)據(jù)庫(kù)中 Save the new object to the databaseacTrans.Commit()End Using End Sub

創(chuàng)建組合面域

可以通過(guò)查找面域或三維實(shí)體的差集、并集或交集來(lái)創(chuàng)建組合面域。然后可以拉伸或旋轉(zhuǎn)組合面域以創(chuàng)建復(fù)雜的實(shí)體。要?jiǎng)?chuàng)建組合面域,請(qǐng)使用 BooleanOperation 方法。

減去面域

當(dāng)從某個(gè)面域減去另一個(gè)面域時(shí),需要從第一個(gè)面域調(diào)用 BooleanOperation 方法。這是要從中減去其他面域的的面域。例如,要計(jì)算地板需要鋪多少地毯,需要從地板空間的外部邊界調(diào)用 BooleanOperation 方法,并將不需要鋪地毯的區(qū)域如柱子和柜臺(tái)作為 Boolean 參數(shù)列表中的對(duì)象。

并集面域

要獲得并集面域,可以調(diào)用 BooleanOperation 方法并在操作中輸入常量 用戶可以按任意次序組合面域來(lái)形成并集面域。

查找兩個(gè)面域的交集

要查找兩個(gè)面域的交集,請(qǐng)使用常量 BooleanOperationType.BoolIntersect??梢园慈我獯涡蚪M合面域來(lái)計(jì)算這些面域的交集。

創(chuàng)建組合面域

本例從兩個(gè)圓創(chuàng)建兩個(gè)面域,然后用大的面域減去小的面域以創(chuàng)建一個(gè)輪形圖。

Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry<CommandMethod("CreateCompositeRegions")> _ Public Sub CreateCompositeRegions()'' 獲得當(dāng)前文檔和數(shù)據(jù)庫(kù) Get the current document and databaseDim acDoc As Document = Application.DocumentManager.MdiActiveDocumentDim acCurDb As Database = acDoc.Database''啟動(dòng)一個(gè)事務(wù) Start a transactionUsing acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()'' 以只讀方式打開(kāi)塊表 Open the Block table for readDim acBlkTbl As BlockTableacBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)'' 以寫方式打開(kāi)模型空間塊表記錄 Open the Block table record Model space for writeDim acBlkTblRec As BlockTableRecordacBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _OpenMode.ForWrite)'' 在內(nèi)存中創(chuàng)建兩個(gè)圓 Create two in memory circlesDim acCirc1 As Circle = New Circle()acCirc1.SetDatabaseDefaults()acCirc1.Center = New Point3d(4, 4, 0)acCirc1.Radius = 2Dim acCirc2 As Circle = New Circle()acCirc2.SetDatabaseDefaults()acCirc2.Center = New Point3d(4, 4, 0)acCirc2.Radius = 1'' 添加圓到對(duì)象數(shù)組中 Adds the circle to an object arrayDim acDBObjColl As DBObjectCollection = New DBObjectCollection()acDBObjColl.Add(acCirc1)acDBObjColl.Add(acCirc2)'' 根據(jù)每一個(gè)閉合環(huán)計(jì)算面域 Calculate the regions based on each closed loopDim myRegionColl As DBObjectCollection = New DBObjectCollection()myRegionColl = Region.CreateFromCurves(acDBObjColl)Dim acRegion1 As Region = myRegionColl(0)Dim acRegion2 As Region = myRegionColl(1)'' 從面域2減去面域1 Subtract region 1 from region 2If acRegion1.Area > acRegion2.Area Then'' 從大的一個(gè)中減去小的面域 Subtract the smaller region from the larger oneacRegion1.BooleanOperation(BooleanOperationType.BoolSubtract, acRegion2)acRegion2.Dispose()'' 添加遇終的面域到數(shù)據(jù)庫(kù)中 Add the final region to the databaseacBlkTblRec.AppendEntity(acRegion1)acTrans.AddNewlyCreatedDBObject(acRegion1, True)Else'' 從大的一個(gè)中減去小的面域 Subtract the smaller region from the larger oneacRegion2.BooleanOperation(BooleanOperationType.BoolSubtract, acRegion1)acRegion1.Dispose()'' 添加遇終的面域到數(shù)據(jù)庫(kù)中 Add the final region to the databaseacBlkTblRec.AppendEntity(acRegion2)acTrans.AddNewlyCreatedDBObject(acRegion2, True)End If'' 不追加對(duì)象到數(shù)據(jù)庫(kù)中直接從內(nèi)存中銷毀 Dispose of the in memory objects not appended to the databaseacCirc1.Dispose()acCirc2.Dispose()'' 保存新對(duì)象到數(shù)據(jù)庫(kù)中 Save the new object to the databaseacTrans.Commit()End Using End Sub

創(chuàng)建圖案填充

圖案填充是可以使用某種圖案來(lái)填充圖形的封閉邊界。

在創(chuàng)建圖案填充時(shí),不是在開(kāi)始的時(shí)候指定要填充的區(qū)域。首先必須創(chuàng)建 Hatch 對(duì)象。完成后,可以指定外部環(huán),這是圖案填充最外面的邊界。然后繼續(xù)指定圖案填充中可能存在的所有內(nèi)部環(huán)。

創(chuàng)建 Hatch 對(duì)象

創(chuàng)建 Hatch 對(duì)象時(shí),需要指定填充圖案類型、填充圖案名和關(guān)聯(lián)性。一旦創(chuàng)建 Hatch 對(duì)象,就無(wú)法再更改其關(guān)聯(lián)性。

要?jiǎng)?chuàng)建 Hatch 對(duì)象,請(qǐng)創(chuàng)建一個(gè)新的對(duì)象實(shí)例,然后使用 AppendEntity 方法將其添加到塊表記錄對(duì)象中去。

關(guān)聯(lián)圖案填充

用戶可以創(chuàng)建關(guān)聯(lián)的或非關(guān)聯(lián)的圖案填充。關(guān)聯(lián)的圖案填充鏈接到它們的邊界并且會(huì)在邊界改變時(shí)自動(dòng)更新,而非關(guān)聯(lián)的圖案填充則獨(dú)立于它們的邊界。

要使圖案填充具有關(guān)聯(lián)性,請(qǐng)將創(chuàng)建的圖案填充對(duì)象的關(guān)聯(lián)特性設(shè)置為TRUE。若要使圖案填充不關(guān)聯(lián),請(qǐng)將“關(guān)聯(lián)”特性設(shè)置為FALSE。

hatch 關(guān)聯(lián)性必須在添加填充環(huán)前設(shè)置。如果 Hatch 對(duì)象是非關(guān)聯(lián)性的,那么可以通過(guò)設(shè)置 Associative 屬性為 TRUE 讓其再次關(guān)聯(lián)然后添加填充環(huán)。

指定填充圖案的類型和名稱

AutoCAD 提供了實(shí)體填充的五十多種行業(yè)標(biāo)準(zhǔn)填充圖案。填充圖案可用于亮顯圖形的特定特征或區(qū)域。例如,圖案可以幫助區(qū)分三維對(duì)象的組成部分,或者表示組成對(duì)象的材質(zhì)。

可以使用 AutoCAD 附帶的圖案或外部圖案庫(kù)中的圖案。

要指定唯一的圖案,用戶必須在創(chuàng)建 Hatch 對(duì)象時(shí)輸入圖案的類型和名稱。圖案類型指定在何處查找圖案名稱。輸入圖案類型時(shí),可以使用以下常量:

HatchPatternType.PreDefined

從 acad.pat 文件中定義的圖案名中進(jìn)行選擇。

HatchPatternType.UserDefined

用當(dāng)前線型定義直線圖案。

HatchPatternType.CustomDefined

從 PAT 而不是 acad.pat 文件中選擇圖案名。

輸入圖案名稱時(shí),名稱必須對(duì)由圖案類型指定的文件有效。

定義填充邊界

一旦 Hatch 對(duì)象被創(chuàng)建,就可以添加圖案填充邊界。邊界可以是直線、圓弧、圓、二維多段線、橢圓、樣條曲線和面域的任意組合。

添加的第一個(gè)邊界必須是外邊界,即用于定義圖案填充最外面的邊界。要添加外部邊界,請(qǐng)使用添加環(huán)的類型為 HatchLoopTypes.Outermost 常量的 AppendLoop 方法。

一旦外邊界被定義,就可以繼續(xù)添加另外的邊界。添加內(nèi)部邊界請(qǐng)使用帶 HatchLoopTypes.Default 常量的 AppendLoop 方法。

內(nèi)邊界定義圖案填充內(nèi)的孤島。Hatch 對(duì)象處理這些孤島的方式取決于 HatchStyle 屬性的設(shè)置。HatchStyle 屬性可以設(shè)置為以下?tīng)顟B(tài):

?

HatchStyle.Normal

指定標(biāo)準(zhǔn)的樣式,即普通。此選項(xiàng)從最外面的區(qū)域邊界向內(nèi)進(jìn)行圖案填充。如果 AutoCAD 遇到內(nèi)部邊界,將停止填充,直到遇到另一個(gè)內(nèi)部邊界。這是 HatchStyle 屬性的默認(rèn)設(shè)置。

HatchStyle.Outer

僅填充最外面的區(qū)域。此樣式也是從最外面的區(qū)域邊界向內(nèi)進(jìn)行圖案填充,但是遇到內(nèi)部邊界時(shí)會(huì)關(guān)閉圖案填充并且不再打開(kāi)。

HatchStyle.Ignore

忽略內(nèi)部結(jié)構(gòu)。此選項(xiàng)使圖案填充通過(guò)所有的內(nèi)部對(duì)象。

定義完圖案填充之后,必須先對(duì)其進(jìn)行計(jì)算,然后才能顯示。請(qǐng)使用 EvaluateHatch 方法完成此任務(wù)。

創(chuàng)建 Hatch 對(duì)象

本例在模型空間中創(chuàng)建關(guān)聯(lián)的圖案填充。創(chuàng)建圖案填充后,可以修改與圖案填充關(guān)聯(lián)的圓的大小。圖案填充將自動(dòng)改變以匹配圓的當(dāng)前大小。

Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry<CommandMethod("AddHatch")> _ Public Sub AddHatch()'' 獲得當(dāng)前文檔和數(shù)據(jù)庫(kù) Get the current document and databaseDim acDoc As Document = Application.DocumentManager.MdiActiveDocumentDim acCurDb As Database = acDoc.Database''啟動(dòng)一個(gè)事務(wù) Start a transactionUsing acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()'' 以只讀方式打開(kāi)塊表 Open the Block table for readDim acBlkTbl As BlockTableacBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)'' 以寫方式打開(kāi)模型空間塊表記錄 Open the Block table record Model space for writeDim acBlkTblRec As BlockTableRecordacBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _OpenMode.ForWrite)'' 創(chuàng)建一個(gè)圓對(duì)象作為圖案填充的封閉邊界 Create a circle object for the closed boundary to hatchDim acCirc As Circle = New Circle()acCirc.SetDatabaseDefaults()acCirc.Center = New Point3d(3, 3, 0)acCirc.Radius = 1'' 添加新的圓對(duì)象到塊表記錄和事務(wù)中 Add the new circle object to the block table record and the transactionacBlkTblRec.AppendEntity(acCirc)acTrans.AddNewlyCreatedDBObject(acCirc, True)'' 添加圓到一個(gè) ObjectID 數(shù)組中去 Adds the circle to an object id arrayDim acObjIdColl As ObjectIdCollection = New ObjectIdCollection()acObjIdColl.Add(acCirc.ObjectId)'' 創(chuàng)建圖案填充對(duì)象并添加到塊表記錄中 Create the hatch object and append it to the block table recordDim acHatch As Hatch = New Hatch()acBlkTblRec.AppendEntity(acHatch)acTrans.AddNewlyCreatedDBObject(acHatch, True)'' Set the properties of the hatch object'' Associative must be set after the hatch object is appended to the '' block table record and before AppendLoopacHatch.SetDatabaseDefaults()acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31")acHatch.Associative = TrueacHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl)acHatch.EvaluateHatch(True)'' 保存新對(duì)象到數(shù)據(jù)庫(kù)中 Save the new object to the databaseacTrans.Commit()End Using End Sub

總結(jié)

以上是生活随笔為你收集整理的autoCAD 创建对象 使用面域 创建图案填充的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。