I am trying to set the ucs in a floating viewport, but it is not working. I dont know what I am missing.
I checked the developers guide, but the example there is for tiled viewports and it didnt work when using it on floating viewports, especially the method of the editor UpdateTiledViewportsFromDatabase(), I am wondering if there is a similar method to be used when dealing with floating viewports.
'' Set the UCS current acVportTblRec.SetUcs(acUCSTblRec.ObjectId) acDoc.Editor.UpdateTiledViewportsFromDatabase()
The code below shows how do I create a new UCS and try to set it to a viewport, but unfortunately it is not working, I am sure the problem is in the viewport because the UCSs are being created and i check them in autocad and they exist, but they are not attached to the viewport.
'Open the existing viewport Dim exvpobjid As ObjectId = templyt.GetViewports(1) Dim exVport As Autodesk.AutoCAD.DatabaseServices.Viewport = TryCast(acTrans.GetObject(exvpobjid, OpenMode.ForRead), Autodesk.AutoCAD.DatabaseServices.Viewport) 'Open the viewport to be copied Dim vpobjid As ObjectId = newLayout.GetViewports(1) Dim Vport As Autodesk.AutoCAD.DatabaseServices.Viewport = TryCast(acTrans.GetObject(vpobjid, OpenMode.ForWrite), Autodesk.AutoCAD.DatabaseServices.Viewport) Vport.CopyFrom(exVport) 'Open the UCS table for read Dim acUCSTbl As UcsTable = acTrans.GetObject(acCurdb.UcsTableId, OpenMode.ForRead) 'Check to see if the New UCS table record exists Dim acUCSTblRec As UcsTableRecord If acUCSTbl.Has("Layout" & lytcounter & "-UCS") = False Then acUCSTblRec = New UcsTableRecord() acUCSTblRec.Name = "Layout" & lytcounter & "-UCS" 'Open the UCSTable for write acUCSTbl.UpgradeOpen() acUCSTbl.Add(acUCSTblRec) acTrans.AddNewlyCreatedDBObject(acUCSTblRec, True) Else acUCSTblRec = acTrans.GetObject(acUCSTbl("Layout" & lytcounter & "-UCS"), OpenMode.ForWrite) End If Dim acPol As Autodesk.AutoCAD.DatabaseServices.Polyline = TryCast(acTrans.GetObject(prop.objid, OpenMode.ForRead), Autodesk.AutoCAD.DatabaseServices.Polyline) Dim origin As Point3d = New Point3d(acPol.GetPoint2dAt(0).X, acPol.GetPoint2dAt(0).Y, 0) acUCSTblRec.Origin = origin Dim xaxis As Vector3d = New Vector3d(acPol.GetPoint2dAt(1).X - acPol.GetPoint2dAt(0).X, acPol.GetPoint2dAt(1).Y - acPol.GetPoint2dAt(0).Y, 0) acUCSTblRec.XAxis = xaxis Dim yaxis As Vector3d = New Vector3d(acPol.GetPoint2dAt(3).X - acPol.GetPoint2dAt(0).X, acPol.GetPoint2dAt(3).Y - acPol.GetPoint2dAt(0).Y, 0) acUCSTblRec.YAxis = yaxis Dim height As Double Dim width As Double height = Math.Sqrt(Math.Pow((acPol.GetPoint2dAt(0).X - acPol.GetPoint2dAt(1).X), 2) + Math.Pow((acPol.GetPoint2dAt(0).Y - acPol.GetPoint2dAt(1).Y), 2)) width = Math.Sqrt(Math.Pow((acPol.GetPoint2dAt(0).X - acPol.GetPoint2dAt(3).X), 2) + Math.Pow((acPol.GetPoint2dAt(0).Y - acPol.GetPoint2dAt(3).Y), 2)) If height > width Then Dim tmp As Double = height height = width width = tmp End If Vport.On = True Vport.SetUcs(acUCSTblRec.ObjectId) Vport.UpdateDisplay()
Any ideas?