'快速创建块(将选择的对象创建成一个块,在原来的位置插入盖参照块)
Public Class Class6
<CommandMethod("NiMingBlock")> _
Public Sub NiMingBlock()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Dim acEditor As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim Record As BlockTableRecord = New BlockTableRecord
Dim Name As String
Name = Replace("TC_" & System.DateTime.Now.ToString, " ", "")
Name = Replace(Name, "-", "")
Name = Replace(Name, ":", "")
Record.Name = Name
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim BlockTable As BlockTable = acTrans.GetObject(acCurDb.BlockTableId, _
OpenMode.ForWrite)
Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection()
If acSSPrompt.Status = PromptStatus.OK Then '选择成功
Dim acSSet As SelectionSet = acSSPrompt.Value
Dim acEnt As Entity = acTrans.GetObject(acSSet.Item(0).ObjectId, _
OpenMode.ForRead)
'得到第一个对象的一个角点
Dim P3D As Point3d = acEnt.GeomExtents.MinPoint
Record.Origin = P3D
'创建一个块
For Each acSSObj As SelectedObject In acSSet
Dim Ent As Entity = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite)
Dim NewEnt As Entity = Ent.Clone
Ent.Erase()
Record.AppendEntity(NewEnt)
Next
BlockTable.Add(Record)
acTrans.AddNewlyCreatedDBObject(Record, True)
'插入参照块
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(BlockTable(BlockTableRecord.ModelSpace), _
OpenMode.ForWrite)
Dim BlockRef As BlockReference = New BlockReference(P3D, Record.ObjectId)
acBlkTblRec.AppendEntity(BlockRef)
acTrans.AddNewlyCreatedDBObject(BlockRef, True)
End If
acTrans.Commit()
End Using
End Sub
End Class
Public Class Class6
<CommandMethod("NiMingBlock")> _
Public Sub NiMingBlock()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Dim acEditor As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim Record As BlockTableRecord = New BlockTableRecord
Dim Name As String
Name = Replace("TC_" & System.DateTime.Now.ToString, " ", "")
Name = Replace(Name, "-", "")
Name = Replace(Name, ":", "")
Record.Name = Name
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim BlockTable As BlockTable = acTrans.GetObject(acCurDb.BlockTableId, _
OpenMode.ForWrite)
Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection()
If acSSPrompt.Status = PromptStatus.OK Then '选择成功
Dim acSSet As SelectionSet = acSSPrompt.Value
Dim acEnt As Entity = acTrans.GetObject(acSSet.Item(0).ObjectId, _
OpenMode.ForRead)
'得到第一个对象的一个角点
Dim P3D As Point3d = acEnt.GeomExtents.MinPoint
Record.Origin = P3D
'创建一个块
For Each acSSObj As SelectedObject In acSSet
Dim Ent As Entity = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite)
Dim NewEnt As Entity = Ent.Clone
Ent.Erase()
Record.AppendEntity(NewEnt)
Next
BlockTable.Add(Record)
acTrans.AddNewlyCreatedDBObject(Record, True)
'插入参照块
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(BlockTable(BlockTableRecord.ModelSpace), _
OpenMode.ForWrite)
Dim BlockRef As BlockReference = New BlockReference(P3D, Record.ObjectId)
acBlkTblRec.AppendEntity(BlockRef)
acTrans.AddNewlyCreatedDBObject(BlockRef, True)
End If
acTrans.Commit()
End Using
End Sub
End Class
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |