SetCameraLocation and SetCameraTarget in grasshopper

I did an experiment to control the camera position and target position in GH, but after I click the button, the viewport only seems to run until the Y value of the target point changes. I still need to click enter in any input box in the view property bar to complete the change of all viewports (the values of the camera and target point in the view property bar are changed under program control)

I don’t know what’s wrong

import Rhino
import scriptcontext as sc

doc=Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport

if set==True:
    new_camera_location = Rhino.Geometry.Point3d(1000, 1000, 1000)
    new_target_location = Rhino.Geometry.Point3d(0, 0, 0)
    
    set_active_view=doc.SetCameraLocation(new_camera_location,False)
    set_active_target=doc.SetCameraTarget(new_target_location,False)
    Rhino.DocObjects.DetailViewObject.CommitViewportChanges()
#    sc.doc.Views.Redraw()

:sweat_smile::sweat_smile::sweat_smile::sweat_smile:

Hi,

this works for me:

"""Grasshopper Script"""

import Rhino

import scriptcontext as sc

vp = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport

if setV==True:

    new_camera_location = Rhino.Geometry.Point3d(1000, 1000, 1000)

    new_target_location = Rhino.Geometry.Point3d(0, 0, 0)

    vp.SetCameraLocations(new_target_location, new_camera_location)

Change the script component input parameter to something other than “set”, since this is a reserved word (I used “setV”)