Jump to content

Setting the amount of Zoom using script


---
 Share

Go to solution Solved by [Mi...],

Recommended Posts

Hi,

I was wondering if there was a command which allows to control how much I zoom into an object (for example, 150% zoom, 200% zoom, etc.)?

I've already tried gom.script.view.adapt_zoom but it does not suit my purpose.

Thank you!

Link to comment
Share on other sites

Hi James, 

Essentially it is to put the proper pictures in a report automatically, but sometimes the object being viewed is zoomed in too much or too little. I was wondering what commands exist to modify the 3D view.

Link to comment
Share on other sites

  • Solution

Winston,

I have a script that might help you here. Back on the old GOM forums a few years ago, I came across the gom.script.view.set_view_cartesian command which can set and scale a camera view based on... unit vectors i think? It's been particularly handy over the years so I wrote the quick utility below to help replicate camera views. If you set Mode to 'get', it will retrieve the current camera view position/scale information and print it to the script editor window in the right format so that you can copy/paste it right into another script and replicate the same view and zoom level. And you can test it by changing the Mode variable to 'set' to change the camera view to whatever is entered into the gom.script.view.set_view_cartesian command built-in to that flowpath of the script. Hope this helps!

# -*- coding: utf-8 -*-

import gom

#print(gom.script.view.set_view_cartesian.__doc__)
#print(gom.script.view.set_view_direction_and_up_direction.__doc__)

Mode = 'get'


if Mode == 'get':
	position_list = [gom.app.get( 'views.active.position.' + i ) for i in ( 'x', 'y', 'z' )]
	up_list = [gom.app.get( 'views.active.up_direction.' + i ) for i in ( 'x', 'y', 'z' )]
	view_list = [gom.app.get( 'views.active.view_direction.' + i ) for i in ( 'x', 'y', 'z' )]
	print('	gom.script.view.set_view_cartesian ( ')
	print('		camera_position = gom.Vec3d ( ' + str(position_list[0]) + ', ' + str(position_list[1]) + ', ' + str(position_list[2]) + ' ), ')
	print('		scale = ' + str(gom.app.get ( 'views.active.scale' )) + ', ')
	print('		up_direction = gom.Vec3d ( ' + str(up_list[0]) + ', ' + str(up_list[1]) + ', ' + str(up_list[2]) + ' ), ')
	print('		use_animation = True, ')
	print('		view_direction = gom.Vec3d ( ' + str(view_list[0]) + ', ' + str(view_list[1]) + ', ' + str(view_list[2]) + ' ))')
	print('')
	
	
	print( 'position: ', [gom.app.get( 'views.active.position.' + i ) for i in ( 'x', 'y', 'z' )])
	print('scale: ', gom.app.get ( 'views.active.scale' ))
	print('up direction: ', [gom.app.get( 'views.active.up_direction.' + i ) for i in ( 'x', 'y', 'z' )])
	print('view direction: ', [gom.app.get( 'views.active.view_direction.' + i ) for i in ( 'x', 'y', 'z' )])
elif Mode == 'set':
	gom.script.view.set_view_cartesian ( 
		camera_position = gom.Vec3d ( 4065.32177734375, 1039.28271484375, 306.1480407714844 ), 
		scale = 77.30164337158203, 
		up_direction = gom.Vec3d ( 0.1830126941204071, 0.9659258127212524, 0.1830126941204071 ), 
		use_animation = True, 
		view_direction = gom.Vec3d ( -0.6830127239227295, 0.258819043636322, -0.6830127239227295 ))

Regards,

Michael Henson

Link to comment
Share on other sites

 Share

×
×
  • Create New...