Author Topic: Plotting Window v Plotting Entity Extents  (Read 1879 times)

0 Members and 1 Guest are viewing this topic.

flowerrobot

  • Guest
Plotting Window v Plotting Entity Extents
« on: July 17, 2013, 09:43:19 PM »
Hi,

I run two pieces of code, of which returns two different values when UCS is not set to world.
I am obtaining a window via a user prompt, Which translates correctly to the UCS,.
When getting the Geometric Extents of a block I get the correct window, when UCS = World, However when it is not, it does not give me the correct result.

There is some thing simple that I am missing, Any help would be greatly appreciated.

UCS translate
Code: [Select]
Public Function Translate(ByVal Point As Point3d) As Point3d
        ' Transform from UCS to DCS

        Dim rbFrom As New ResultBuffer(New TypedValue(5003, 1)), rbTo As New ResultBuffer(New TypedValue(5003, 3))

        Dim firres As Double() = New Double() {0, 0, 0}

        ' Transform the first point...
        acedTrans(Point.ToArray(), rbFrom.UnmanagedObject, rbTo.UnmanagedObject, 0, firres)

        Dim result As New Point3d(firres)

        Return result
    End Function

Get Window
Code: [Select]
Public Function ActiveSpaceGetWindow() As Extents2d
        Dim AcDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim AcDB As Database = AcDoc.Database
        Dim AcEd As Editor = AcDoc.Editor

        Dim Result1 As PromptPointResult = Nothing
        Dim Result2 As PromptPointResult = Nothing
        Try
            Dim PointOP1 As New PromptPointOptions(vbLf & "Select first corner : ")
            PointOP1.AllowNone = False

            Result1 = AcEd.GetPoint(PointOP1)
            If Result1.Status <> PromptStatus.OK Or Result1.Value = Nothing Then
                Return Nothing
            End If

            Dim Pt1 As Point3d = Result1.Value
            Dim CornOP1 As New PromptCornerOptions(vbLf & "Select second corner : ", Result1.Value)
            Result2 = AcEd.GetCorner(CornOP1)
            If Result2.Status <> PromptStatus.OK Or Result2.Value = Nothing Then
                Return Nothing
            End If

            '' Transform from UCS to DCS         

            Dim Point1 As Point3d = Translate(Result1.Value)
            Dim Point2 As Point3d = Translate(Result2.Value)
            Return New Extents2d(Point1.X, Point1.Y, Point2.X, Point2.Y)
        Catch ex As System.Exception
            If Result1 IsNot Nothing AndAlso Result2 IsNot Nothing Then
                Return New Extents2d(Result1.Value.X, Result1.Value.Y, Result2.Value.X, Result2.Value.Y)
            Else
                Return Nothing
            End If
        End Try
        Return Nothing

Get Block extents
Code: [Select]
dim Blk as blockreference
Dim Extents As Extents3d = Blk.GeometricExtents


                        Dim PointOne As Point3d = Translate(Extents.MinPoint)
                        Dim PointTwo As Point3d = Translate(Extents.MaxPoint)
                        Dim d2Extents As Extents2d = New Extents2d(PointOne.X, PointOne.Y, PointTwo.X, PointTwo.Y) 'Convert to 2d
« Last Edit: July 17, 2013, 10:09:06 PM by flowerrobot »

flowerrobot

  • Guest
Re: Plotting Window v Plotting Entity Extents
« Reply #1 on: July 21, 2013, 11:40:26 PM »
Getting a point from user need a conversion o UCS - DCS
Getting a point from Object needs a conversion of WCS - DCS

Code: [Select]
   Public Function Translate(ByVal Point As Point3d, ByVal FromCor As CoOrds, ByVal ToCor As CoOrds) As Point3d
        ' Transform from UCS to DCS

        Dim rbFrom As New ResultBuffer(New TypedValue(5003, FromCor)), rbTo As New ResultBuffer(New TypedValue(5003, ToCor))

        Dim firres As Double() = New Double() {0, 0, 0}

        ' Transform the first point...
        acedTrans(Point.ToArray(), rbFrom.UnmanagedObject, rbTo.UnmanagedObject, 0, firres)

        Dim result As New Point3d(firres)

        Return result
    End Function
    Public Enum CoOrds
        WCS = 0
        UCS = 1
        DCS = 2
        PaperSpaceDCS = 3
    End Enum