Creating a Paperspace Layout and Viewport Issues

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've done a check on similar topics here and found som possible suggestions to my problem, but either they aren't working or I'm not approaching it correctly, so I'm hoping someone can point me in the right direction or point out my error.
What I'm trying to accomplish:
- Have the user select a number of objects that contain attribute data that they wish to create information slips from (a paper space layout for each)
- Create a new "temp" paperspace layout based on a layout the user selects from another drawing
- Switch to the new layout and using a rectanlge jig have the user draw a viewport location.
- Create a viewport at the location specified by the user
- Clone the "temp" layout for each object the user originally selected, and zoom the viewport to the location of the object that sheet is displaying information for.
- Delete the "temp" layout
So far all of this works except, when I click on one of the layouts created and perform a zoom extents to see the sheet, the viewport is empty. I then have to switch to another layout tab, switch back and do another zoom extents before the viewport shows anything.
So that's the portion I'm trying to figure out. I've seen some information about initializing the layout before hand, but so far in playing with that have been unsuccessful in fixing the issue. The code I'm using for the steps important to layout and viewport creation are as follows:
Step 2: Creating a "temp" layout based on a layout from another drawing.
Using acTrans As Transaction = acDoc.TransactionManager.StartTransaction() Dim acObjIDs As New ObjectIdCollection Dim acIDMaps As New IdMapping acObjIDs.Add(acLayoutID) Dim acDestLayouts As DBDictionary = acTrans.GetObject(acDB.LayoutDictionaryId, OpenMode.ForWrite) acTemplateDB.WblockCloneObjects(acObjIDs, acDestLayouts.ObjectId, acIDMaps, DuplicateRecordCloning.Ignore, False) Dim ip As IdPair = acIDMaps.Lookup(acLayoutID) acNewLayoutID = ip.Value acTrans.Commit() acEd.Regen() 'Show new temp layout tab End Using
Step 4: Create the viewport on the "temp" layout
'Create the viewport Using acTrans As Transaction = acDoc.TransactionManager.StartTransaction() Dim acCurSpace As BlockTableRecord = acTrans.GetObject(acDB.CurrentSpaceId, OpenMode.ForWrite) Dim acVP As Viewport = New Viewport() Dim acVPCenterX As Double Dim acVPCenterY As Double Dim acVPWidth As Double Dim acVPHeight As Double 'acVP.SetDatabaseDefaults() acCurSpace.AppendEntity(acVP) acTrans.AddNewlyCreatedDBObject(acVP, True) If acVPBounds.GetPoint2dAt(0).X > acVPBounds.GetPoint2dAt(2).X Then acVPCenterX = acVPBounds.GetPoint2dAt(0).X - ((acVPBounds.GetPoint2dAt(0).X - acVPBounds.GetPoint2dAt(2).X) / 2) acVPWidth = (acVPBounds.GetPoint2dAt(0).X - acVPBounds.GetPoint2dAt(2).X) Else acVPCenterX = acVPBounds.GetPoint2dAt(2).X - ((acVPBounds.GetPoint2dAt(2).X - acVPBounds.GetPoint2dAt(0).X) / 2) acVPWidth = (acVPBounds.GetPoint2dAt(2).X - acVPBounds.GetPoint2dAt(0).X) End If If acVPBounds.GetPoint2dAt(0).Y > acVPBounds.GetPoint2dAt(2).Y Then acVPCenterY = acVPBounds.GetPoint2dAt(0).Y - ((acVPBounds.GetPoint2dAt(0).Y - acVPBounds.GetPoint2dAt(2).Y) / 2) acVPHeight = (acVPBounds.GetPoint2dAt(0).Y - acVPBounds.GetPoint2dAt(2).Y) Else acVPCenterY = acVPBounds.GetPoint2dAt(2).Y - ((acVPBounds.GetPoint2dAt(2).Y - acVPBounds.GetPoint2dAt(0).Y) / 2) acVPHeight = (acVPBounds.GetPoint2dAt(2).Y - acVPBounds.GetPoint2dAt(0).Y) End If acVP.CenterPoint = New Point3d(acVPCenterX, acVPCenterY, 0) acVP.Width = acVPWidth acVP.Height = acVPHeight acVP.Layer = strVPLayer 'Set scale as 1:1000 acVP.CustomScale = 1 'Center Viewport on block acVP.ViewDirection = Vector3d.ZAxis acVP.ViewTarget = New Point3d(0, 0, 0) acVP.ViewCenter = Point2d.Origin acVP.Visible = True acVP.On = True acVP.UpdateDisplay() acTrans.Commit() End Using
Step 5: Clone the "temp" layout
Dim lm As LayoutManager = LayoutManager.Current Dim acLayout As Layout = acTrans.GetObject(acNewLayoutID, OpenMode.ForRead) Dim strNewLayoutName As String = "Lot " & acLotInfo.LotNumber.ToString While lm.GetLayoutId(strNewLayoutName) <> Nothing strNewLayoutName = "Lot " & acLotInfo.LotNumber.ToString & "(Copy " & GenerateRandomString(2) & ")" End While lm.CloneLayout(acLayout.LayoutName, strNewLayoutName, lm.LayoutCount) Dim acClonedLayout As Layout = acTrans.GetObject(lm.GetLayoutId("Lot " & acLotInfo.LotNumber.ToString), OpenMode.ForWrite) 'acClonedLayout.Initialize() Dim acClonedLayoutBTR As BlockTableRecord = acTrans.GetObject(acClonedLayout.BlockTableRecordId, OpenMode.ForRead)
Step 5: Set the VP on the cloned layout to view the object
Dim acVP As Viewport = CType(acEnt, Viewport) acVP.UpgradeOpen() 'Set scale as 1:1000 acVP.CustomScale = 1 'Center Viewport on block acVP.ViewDirection = Vector3d.ZAxis acVP.ViewTarget = acLotInfo.InsertionPointforBlock acVP.ViewCenter = Point2d.Origin 'Set viewport rotation to 360 - block rotation angle acVP.TwistAngle = (2 * PI) - acLotInfo.BlockRotation acVP.UpdateDisplay() acVP.DowngradeOpen()
I've attached the full .vb file here if anyone would like to see the full code for this procedure. The Procedure name is "CreateBGSlips()". I appreciate any help or light anyone can shed on this!