Quantcast
Channel: Autodesk AutoCAD forums
Viewing all articles
Browse latest Browse all 14319

Getting viewport UCS

$
0
0
I hope if you can help me with this problem, I am still stuck at it. My objective is to find whether a layout viewport has a rotated ICS or not.
I have attached a visual studio 2012 project along a testdrawing, please check my code and tell me why it is not working.
In fact the code works but not always, for example if you run the code and select the viewport in the layout of the attached drawing, it will falsely give you (1,0,0) which is the vector or the world ucs x-axis, but this is not true. Now activate the model space in the viewport in autocad manually, then run the code again, it would work and give you the right coordinates of the ucs x-axis.
I don't understand how and why it works this way, so could you help me a little please.
I think the real problem is in the part of the code that makes the viewport active, I cannot believe that there is no code in vb.net to activate a viewport, and using the com code may be the problem.
 
Great thanks for you, I hope this problem gets resolved.
 
Public Class Test<CommandMethod("GetUCS", CommandFlags.NoTileMode)> _
    Public Sub GetUCS()
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurdb As Database = acDoc.Database
        Dim ed As Editor = acDoc.Editor()

        Dim peo As New PromptEntityOptions("Select a viewport : ")
        peo.SetRejectMessage("Select a viewport.")
        peo.AddAllowedClass(GetType(Autodesk.AutoCAD.DatabaseServices.Viewport), True)
        Dim per As PromptEntityResult = ed.GetEntity(peo)
        Dim vpId As ObjectId = per.ObjectId

        Dim acadDoc As AcadDocument = Autodesk.AutoCAD.ApplicationServices.DocumentExtension.GetAcadDocument(acDoc)
        ed.SwitchToModelSpace()

        Using tr As Transaction = acCurdb.TransactionManager.StartTransaction()
            Dim vp As Autodesk.AutoCAD.DatabaseServices.Viewport = TryCast(tr.GetObject(vpId, OpenMode.ForRead), Autodesk.AutoCAD.DatabaseServices.Viewport)

            'Setting the chosen viewport active
            acadDoc.ActivePViewport = vp.AcadObject

            'I just want to read the x-axis vector to know whether the viewport has been rotated or not
            Dim curXdir As Vector3d = acCurdb.Ucsxdir
            ed.WriteMessage(vbLf & curXdir.ToString)

            tr.Commit()
        End Using
        ed.SwitchToPaperSpace()
    End Sub
End Class

 


Viewing all articles
Browse latest Browse all 14319

Trending Articles