KeyShot Forum

Technical discussions => Extending KeyShot => Scripting => Topic started by: rembem on August 17, 2018, 02:37:18 AM

Title: Center and fit part/object
Post by: rembem on August 17, 2018, 02:37:18 AM
I'm starting to use scripts. I can use the standard one in KeyShot with creating all the camera angle, but I also want to centre and fit the product per camera. Can someone help !!!?
(I will import a product in KeyShot and then create all the angles/cameras)

This is the script from KeyShot:

views = {lux.VIEW_FRONT: "Front",
   lux.VIEW_BACK: "Back",
         lux.VIEW_LEFT: "Left",
         lux.VIEW_RIGHT: "Right",
         lux.VIEW_TOP: "Top",
         lux.VIEW_BOTTOM: "Bottom",
         lux.VIEW_ISOMETRIC: "Isometric"}

for view in views:
    name = "_" + views[view]
    has = False
    if name in lux.getCameras():
        has = True
        lux.setCamera(name)
    else:
        lux.newCamera(name)
    lux.setStandardView(view)
    lux.saveCamera()
    print("{} camera: {}".format("Updated" if has else "Created", name))

... all I need is that it also will center and fit the objects.
Title: Re: Center and fit part/object
Post by: Morten Kristensen on August 23, 2018, 07:32:21 AM
Hi Remko,

To center-and-fit a node, you can get the root node via lux.getSceneTree() (https://keyshot.com/scripting/doc/7.3/lux.html#-getSceneTree) then you find the node you want to center-and-fit via find() (https://keyshot.com/scripting/doc/7.3/lux.html#SceneNode-find) on the root, which returns a list of nodes.