Error set Camera when Top View

Error:
#<ArgumentError: Up vector cannot be parallel to view direction>
How to handle this Error?.

def rotate_view()
	@stop_rotasi = false
	model = Sketchup.active_model
	ents = model.entities
	sel = model.selection
	arr = sel.to_a.select { |e| e.respond_to?(:transformation) }
	sel.clear

	total_bb = Geom::BoundingBox.new
	arr.each{|e|
		total_bb.add(e.bounds)
	}
	target_center = total_bb.center
	
	my_timer = UI.start_timer(0.02,true){	
		if !@stop_rotasi
			angle = 1.degrees
			transformation = Geom::Transformation.rotation(target_center, [0,0,1], angle)
			camerapoint = Sketchup.active_model.active_view.camera.eye
			camerapoint.transform! transformation
			up = [0,0,1]
			Sketchup.active_model.active_view.camera.set(camerapoint,target_center,up)
		else
			UI.stop_timer my_timer
			#sel.add(arr)
			arr.each{|e| sel.add(e) if e.valid?}
		end
	}
end
rotate_view()

I’m reading on my phone so can’t try code, but the error message suggests that the target point is in the z direction from the camera point, which makes the view vector be the z axis, the same as your hardwired up vector. If that situation wasn’t expected, you’ll have to figure out why it happened. And if that orientation of the view direction is expected, you need to choose a different up vector.

1 Like

did you mean like this ?

direction = Sketchup.active_model.active_view.camera.direction
if direction.z != -1
	up = [0,0,1]
else
	up = [0,1,1]
end

More or less, though I’d use parallel? instead of comparing the value because the vectors actually use floats which can contain small errors that prevent an exact match. Parallel? tests to within a tolerance.