# Viewport Center in Modelspace (View Target)

**URL:** <https://forum.dynamobim.com/t/viewport-center-in-modelspace-view-target/100419>\
**Category:** Developers\
**Tags:** civil3d, autocad\
**Created:** [April 24, 2024, 7:16pm UTC](https://forum.dynamobim.com/t/viewport-center-in-modelspace-view-target/100419 "2024-04-24T19:16:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kpricePZXHH](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@kpricePZXHH](https://forum.dynamobim.com/u/kpricePZXHH)\
**Post date:** [April 24, 2024, 7:16pm UTC](https://forum.dynamobim.com/t/viewport-center-in-modelspace-view-target/100419/1 "2024-04-24T19:16:36Z")

</div>

I am trying to scale and move the modelspace target location on already created viewports in multiple layouts. I used the AutoCAD API viewport class properties. I don’t get any errors when using these to edit viewports, however the locked and scale function work but the viewports aren’t being moved. I have attached my python code.

```auto
# Load the Python Standard and DesignScript Libraries
import sys
import clr

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

viewports = IN[0]
scale = IN[1]
centerpoints = IN[2]
locked = IN[3]
if locked == None:
    bool = True
else:
    bool = locked
out = []
adoc = Application.DocumentManager.MdiActiveDocument
ed = adoc.Editor
if len(viewports) != len(centerpoints):
    out = "WARNING: Viewports and Centerpoints do not match length"
else:
    for i, viewport in enumerate(viewports):
        vp = viewport.InternalDBObject
        vp.UpgradeOpen()
        cntr = centerpoints[i]
        pt = Point3d(cntr.X,cntr.Y,0)
        """
        midpoint = vp.CenterPoint
        midPnt = Point2d(midpoint.X,midpoint.Y)
        ed.SwitchToModelSpace()
        view = ViewTableRecord()
        view.IsPaperspaceView = True
        view.CenterPoint = midPnt
        ed.SetCurrentView(view)
        ed.SwitchToPaperSpace()
        """
        vp.CustomScale = scale
        vp.ViewTarget = pt
        vp.Locked = bool
        vp.On = True
        out.append(vp)

# Assign your output to the OUT variable.
OUT = out

```

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [April 25, 2024, 6:35am UTC](https://forum.dynamobim.com/t/viewport-center-in-modelspace-view-target/100419/2 "2024-04-25T06:35:36Z")

</div>

You will need to lock the adoc and make the changes inside a transaction  
I don’t currently have access to my workstation with C3D, however if you start with the standard python code the information is there
