获取被剪裁块的剪裁编辑



http://spiderinnet1.typepad.com/blog/2012/10/autocad-net-retri ... oundary-for-insertblockreference.html

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices.Filters
Imports Autodesk.AutoCAD.Geometry

Public Class XClipRetriever
    <CommandMethod("RXC", CommandFlags.Modal Or CommandFlags.UsePickSet)> _
    Public Shared Sub RetrieveXClipBoundary_Method()
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Try
            If ed.SelectImplied().Status <> PromptStatus.OK Then
                Throw New System.Exception("Nothing has been pre-selected!")
            End If

            Dim BlockReferenceRXClass As RXClass = RXClass.GetClass(GetType(BlockReference))
            Using tr As Transaction = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()
                For Each id As ObjectId In ed.SelectImplied().Value.GetObjectIds()
                    If id.ObjectClass = BlockReferenceRXClass Then
                        Dim blkRef As BlockReference = CType(tr.GetObject(id, OpenMode.ForRead), BlockReference)
                        If blkRef.ExtensionDictionary <> ObjectId.Null Then
                            Dim extdict As DBDictionary = CType(tr.GetObject(blkRef.ExtensionDictionary, OpenMode.ForRead), DBDictionary)
                            If extdict.Contains("ACAD_FILTER") Then
                                Dim dict As DBDictionary = CType(tr.GetObject(extdict.GetAt("ACAD_FILTER"), OpenMode.ForRead), DBDictionary)
                                If dict.Contains("SPATIAL") Then
                                    Dim filter As SpatialFilter = CType(tr.GetObject(dict.GetAt("SPATIAL"), OpenMode.ForRead), SpatialFilter)
                                    DrawPolygon(blkRef.Database, filter.Definition.Normal, filter.ClipSpaceToWorldCoordinateSystemTransform, filter.Definition.GetPoints())
                                End If
                            End If
                        End If
                    End If
                Next

                tr.Commit()
            End Using
        Catch ex As System.Exception
            ed.WriteMessage(Environment.NewLine + ex.Message)
        End Try
    End Sub

    Public Shared Function DrawPolygon(ByVal db As Database, ByVal normal As Vector3d, ByVal mat As Matrix3d, ByVal vertices As Point2dCollection) As ObjectId
        Dim ret As ObjectId = ObjectId.Null

        Dim tr As Transaction = db.TransactionManager.TopTransaction
        Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
        Using pl As New Polyline()
            pl.SetDatabaseDefaults()
            pl.ColorIndex = 3
            pl.Closed = True
            Dim i As Integer = 0
            While i < vertices.Count
                pl.AddVertexAt(0, vertices(i), 0, 0, 0)
                System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
            End While
            pl.TransformBy(mat)
            btr.AppendEntity(pl)
            tr.AddNewlyCreatedDBObject(pl, True)
            ret = pl.ObjectId
        End Using

        Return ret
    End Function
End Class



Excel打印时候设置打印区域



欢迎关注微信公众账号ByCAD