The code below will draw a viewport in paper space and zoom to an area in model space. It will then create a circle in model space and then change that circle to to papers pace while still keeping the circle in the same location.
Note: for this to work, the MSpace has to be set as true. Once the CHSPACE command is used, it atomically changes the MSPACE to false.
Set ACLayout = acadDoc.Layouts.Add(pgnum) acadDoc.ActiveLayout = ACLayout Dim viewportCenter(0 To 2) As Double viewportCenter(0) = 0.762: viewportCenter(1) = 0.8 Set pviewportObj = acadDoc.PaperSpace.AddPViewport(viewportCenter, 17, 7) pviewportObj.Layer = "viewport" pviewportObj.Display True acadDoc.MSpace = True zoompoint1(0) = -1: zoompoint1(1) = -20 zoompoint2(0) = 1: zoompoint2(1) = Range("tank_dia") / 2 + 20 acadDoc.Application.ZoomWindow zoompoint2, zoompoint1 Dim vphandle As String Set objEntcir = acadDoc.ModelSpace.AddCircle(crossGirdposition, zoomdistance * 2) objEntcir.Layer = "dashed" objEntcir.LinetypeScale = 0.2 vphandle = "(handent " & Chr(34) & objEntcir.Handle & Chr(34) & ")" acadDoc.SendCommand "CHSPACE" & vbCr & vphandle & vbCr & vbCr & vbCr
the next code example will use the TranslateCoordinates method to translate an array of x y coordinates from model space to paper space. In this case, it will move the x y point of the start line from model to paper space. It works similar to CHSPACE except instead of moving whole objects it will move only coordinates.
Set ACLayout = acadDoc.Layouts.Add(pgnum) acadDoc.ActiveLayout = ACLayout Dim endline(0 To 2) As Double Dim insertionPointPS As Variant startline(0) = crossGirdposition(0) + 0.707 * zoomdistance * 2: startline(1) = crossGirdposition(1) + 0.707 * zoomdistance * 2 insertionPointPS = acadDoc.Utility.TranslateCoordinates(startline, acDisplayDCS, acPaperSpaceDCS, False) endline(0) = 7: endline(1) = 1.0889 Set objline = acadDoc.PaperSpace.AddLine(insertionPointPS, endline) objline.Layer = "dashed" objline.LinetypeScale = 0.2