<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Pan in a paper space view port after successful zoomcenter in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/pan-in-a-paper-space-view-port-after-successful-zoomcenter/m-p/12622057#M923</link>
    <description>Kind of like AutoCAD's built-in (but not in VBA) PanLeft, PanRight, PanUp and PanDown toolbar buttons for example?</description>
    <pubDate>Thu, 07 Mar 2024 00:10:36 GMT</pubDate>
    <dc:creator>pendean</dc:creator>
    <dc:date>2024-03-07T00:10:36Z</dc:date>
    <item>
      <title>Pan in a paper space view port after successful zoomcenter</title>
      <link>https://forums.autodesk.com/t5/vba-forum/pan-in-a-paper-space-view-port-after-successful-zoomcenter/m-p/12621563#M922</link>
      <description>&lt;P&gt;I want to be able to shift the center of my AcadPViewport. Note I am using Autodesk.AutoCAD.Interop.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I conditionally rotate my pviewport using twist angle property. And based on whether I rotated the pviewport right or left, I want to pan to create a better view.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The code is doing such, finding all viewports and zooming the viewport to a specific alignment. I rotate the alignments so negative stations point left in the pv and positive stations point right.&lt;BR /&gt;However, after the rotation I want to fit more of the alignment in the window.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Panning would be the simplest in my mind, as simple change the x will give wildly different results based on the position of the alignment on a global scale.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;For Each objPaperSpaceEntity As AcadEntity In thisDwg.PaperSpace
                If TypeOf objPaperSpaceEntity Is AcadPViewport Then
                    intViewPortCount = intViewPortCount + 1
                    If intViewPortCount &amp;gt; 0 Then
                        Dim mslngViewPortEntities As Integer = 0
                        Dim objPViewPort As AcadPViewport = objPaperSpaceEntity

                        'Determine Station value and set center point for zoom
                        'to first or last point based on station sign
                        If (horiAligns(14).FirstStation &amp;gt;= 0) Then
                            'means positive station rotate point right
                            rotationForVP = pi / 2
                            'Positive stations, mean we center at first point
                            point(0) = horiAligns(0).FirstPoint.x
                            point(1) = horiAligns(0).FirstPoint.Y
                            point(2) = horiAligns(0).FirstPoint.z
                        Else
                            'negative station rotate point left
                            rotationForVP = -pi / 2
                            'Negative station means we center at last point
                            point(0) = horiAligns(0).LastPoint.x
                            point(1) = horiAligns(0).LastPoint.Y
                            point(2) = horiAligns(0).LastPoint.z
                        End If

                        globalAngle = cmnAngles.Atan2(
                            horiAligns(0).LastPoint.Y - horiAligns(0).FirstPoint.Y,
                            horiAligns(0).LastPoint.x - horiAligns(0).FirstPoint.x)
                        globalAngle = 1.570796326794895 - globalAngle

                        objPViewPort.TwistAngle = globalAngle + rotationForVP

                        'Make the viewport active.
                        objPViewPort.Display(True)
                        thisDwg.MSpace = True
                        thisDwg.ActivePViewport = objPViewPort

                        Dim test(0 To 2) As Double
                        test(0) = 0
                        test(1) = 0
                        test(2) = 0

                        thisDwg.Application.ZoomCenter(point, 80)

                        'SOMEWHERE HERE I WANT TO PAN OR ADJSUT TARGET

                        thisDwg.MSpace = False
                        objPViewPort.Target = test

                    End If
                End If
            Next&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Let me know what you all think&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 20:57:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/pan-in-a-paper-space-view-port-after-successful-zoomcenter/m-p/12621563#M922</guid>
      <dc:creator>QNashJSRL8</dc:creator>
      <dc:date>2024-03-06T20:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: Pan in a paper space view port after successful zoomcenter</title>
      <link>https://forums.autodesk.com/t5/vba-forum/pan-in-a-paper-space-view-port-after-successful-zoomcenter/m-p/12622057#M923</link>
      <description>Kind of like AutoCAD's built-in (but not in VBA) PanLeft, PanRight, PanUp and PanDown toolbar buttons for example?</description>
      <pubDate>Thu, 07 Mar 2024 00:10:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/pan-in-a-paper-space-view-port-after-successful-zoomcenter/m-p/12622057#M923</guid>
      <dc:creator>pendean</dc:creator>
      <dc:date>2024-03-07T00:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: Pan in a paper space view port after successful zoomcenter</title>
      <link>https://forums.autodesk.com/t5/vba-forum/pan-in-a-paper-space-view-port-after-successful-zoomcenter/m-p/12624118#M924</link>
      <description>&lt;P&gt;Yeah I after looking around it seemed like is not possible with VBA to pan a viewport from the code end.&lt;BR /&gt;&lt;BR /&gt;I think I can do it with some math fidgeting. Since I have the center point that I zoom and the amount of radians I rotated my viewport. I should be able to find a point that is some X distance away from the center that is along my alignment. Then make the target of the viewport that new point.&lt;BR /&gt;&lt;BR /&gt;If I get it, I'll post the code here, even if is not exactly vba with AutoCAD. Just a math work around. But maybe it will be useful for someone trying to pan after using twist angle.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 14:59:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/pan-in-a-paper-space-view-port-after-successful-zoomcenter/m-p/12624118#M924</guid>
      <dc:creator>QNashJSRL8</dc:creator>
      <dc:date>2024-03-07T14:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Pan in a paper space view port after successful zoomcenter</title>
      <link>https://forums.autodesk.com/t5/vba-forum/pan-in-a-paper-space-view-port-after-successful-zoomcenter/m-p/12624492#M925</link>
      <description>&lt;P&gt;I tried to do something with arc tang and the quadratic but that didn't work but found a simple solution on stack&lt;/P&gt;&lt;P&gt;&lt;A href="https://math.stackexchange.com/questions/175896/finding-a-point-along-a-line-a-certain-distance-away-from-another-point#:~:text=We%20need%20to%20find%20a%20point%20%28xt%2C%20yt%29,%3C%201%2C%20the%20point%20is%20on%20the%20line." target="_blank" rel="noopener"&gt;Stack Overflow finding point on a line&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you will want to do is reset the target to the point you will zoom to, then zoom after setting the target.&lt;BR /&gt;This way when you adjust the target it will match the model space coordinates.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;'Loop through each of out layouts created by CopyLayout
        For i As Integer = 0 To 0
            thisDwg.ActiveLayout = thisDwg.Layouts.Item(i)

            '-----------------
            'https://groups.google.com/g/autodesk.autocad.customization.vba/c/WSba9d3BGR4
            '   For cycling through PViewports.
            '   Use interop to adjust the pviewport to display alignmen
            '   for intViewPortCount we have to ingnore the first one hence starting at -1
            '       for some reason the first AcadPViewport is not an actual Pviewport
            '-----------------
            Dim intViewPortCount As Integer = -1
            For Each objPaperSpaceEntity As AcadEntity In thisDwg.PaperSpace

                If TypeOf objPaperSpaceEntity Is AcadPViewport Then

                    intViewPortCount = intViewPortCount + 1

                    If intViewPortCount &amp;gt; 0 Then

                        Dim objPViewPort As AcadPViewport = objPaperSpaceEntity
                        Dim align As CivilHAlign
                        Dim positiveStation As Boolean
                        Dim zoomPoint(0 To 2) As Double
                        Dim firstPoint(0 To 2) As Double
                        Dim lastPoint(0 To 2) As Double
                        Dim adjustedtarget(0 To 2) As Double
                        Dim dX As Double
                        Dim dY As Double
                        Dim distance As Double
                        Dim globalAngle As Double
                        Dim rotationForVP As Double

                        align = horiAligns(14)
                        positiveStation = If(align.FirstStation &amp;gt;= 0, True, False)
                        firstPoint(0) = align.FirstPoint.x
                        firstPoint(1) = align.FirstPoint.Y
                        firstPoint(2) = align.FirstPoint.z
                        lastPoint(0) = align.LastPoint.x
                        lastPoint(1) = align.LastPoint.Y
                        lastPoint(2) = align.LastPoint.z

                        'Determine Station value and set center point for zoom
                        'to first or last point based on station sign
                        If (positiveStation) Then
                            'means positive station rotate point right
                            rotationForVP = 3 * PI / 2
                            'Positive stations, mean we center at first point
                            zoomPoint = firstPoint
                        Else
                            'negative station rotate point left
                            rotationForVP = -PI / 2
                            'Negative station means we center at last point
                            zoomPoint = lastPoint
                        End If

                        'Set target to zooomCenter
                        objPViewPort.Target = zoomPoint

                        dX = lastPoint(0) - firstPoint(0)
                        dY = lastPoint(1) - firstPoint(1)

                        globalAngle = cmnAngles.Atan2(dY, dX)
                        globalAngle = (PI / 2) - globalAngle
                        objPViewPort.TwistAngle = globalAngle + rotationForVP

                        'Make the viewport active. and zoom to alignment
                        objPViewPort.Display(True)
                        thisDwg.MSpace = True
                        thisDwg.ActivePViewport = objPViewPort
                        thisDwg.Application.ZoomCenter(zoomPoint, 80)
                        thisDwg.MSpace = False
'------------------------------------------------
'New code here
                        'Adjust target of viewport
                        distance = System.Math.Sqrt((dX ^ 2) + (dY ^ 2))

                        Dim ratioDistance As Double = 50 / distance

                        adjustedtarget(0) = ((1 - ratioDistance) * firstPoint(0)) + ((ratioDistance) * lastPoint(0))
                        adjustedtarget(1) = ((1 - ratioDistance) * firstPoint(1)) + ((ratioDistance) * lastPoint(1))

                        objPViewPort.Target = adjustedtarget
'---------------------------------------
                    End If
                End If
            Next
        Next&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 16:41:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/pan-in-a-paper-space-view-port-after-successful-zoomcenter/m-p/12624492#M925</guid>
      <dc:creator>QNashJSRL8</dc:creator>
      <dc:date>2024-03-07T16:41:48Z</dc:date>
    </item>
  </channel>
</rss>

