编辑ZWCAD实体--移动对象

来源:互联网 发布:aj2 wing it 编辑:程序博客网 时间:2024/05/16 17:52
Imports ZwSoft.ZwCAD.Runtime
Imports ZwSoft.ZwCAD.ApplicationServices
Imports ZwSoft.ZwCAD.DatabaseServices
Imports ZwSoft.ZwCAD.EditorInput
Imports ZwSoft.ZwCAD.Geometry


Public Class ZwcadApps

    <CommandMethod("MoveObject")> _
    Public Sub MoveObject()
        Dim ZcDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ZcDB As Database = ZcDoc.Database
        Dim ZcEd As Editor = ZcDoc.Editor


        Using ZcTran As Transaction = ZcDB.TransactionManager.StartTransaction()


            Dim peo As New PromptEntityOptions(vbLf & "Select object:")
            Dim per As PromptEntityResult = ZcEd.GetEntity(peo)
            If per.Status <> PromptStatus.OK Then
                Return
            End If
            Dim Ent As Entity = ZcTran.GetObject(per.ObjectId, OpenMode.ForWrite)


            Dim pro1 As New PromptPointOptions(vbLf & "Input source point:")
            Dim proR1 As PromptPointResult = ZcEd.GetPoint(pro1)
            If proR1.Status <> PromptStatus.OK Then
                Return
            End If
            Dim sourcePt As Point3d = proR1.Value


            Dim pro2 As New PromptPointOptions(vbLf & "Input target point:")
            Dim proR2 As PromptPointResult = ZcEd.GetPoint(pro2)
            If proR2.Status <> PromptStatus.OK Then
                Return
            End If
            Dim targetPt As Point3d = proR2.Value


            Dim vec As Vector3d = targetPt - sourcePt
            Dim Mt As Matrix3d = Matrix3d.Displacement(vec)
            Ent.TransformBy(Mt)


            ZcTran.Commit()
        End Using
    End Sub
End Class