Call align view
-
Hello!
Is it possible to call the "Align View"-method of the context-menu from a ruby script? Or what kind of script do I need to get such a functionality?
-
It's not a standard 'send_action'.
To do it in code select the face [somehow - either preselected when code runs asmodel.selection[0]
, or determined within your code itself, or 'picked' within a tool].
Then get
vector=face.normal.reverse center=face.bounds.center
Make a new camera using face's values to set the camera, change the view to use that and zoom.
eye=center.clone target=center.offset(vector) up=Z_AXIS new_camera=Sketchup::Camera.new(eye, target, up) view=model.active_view view.camera=new_camera Sketchup.send_action("viewZoomExtents:")
If you only want to zoom a selection of things you can either zoom to the preselected set or temporarily select them within your code, and then use the send_action"viewZoomToSelection:"
-
thx
But I receive an error if the faces normal is parallel to Z_AXIS.
I have added the following lines and it seems to work, but is it the correct solution?if !vector.parallel?(Z_AXIS) then up = Z_AXIS else up = Y_AXIS end
-
@bluetale said:
thx
But I receive an error if the faces normal is parallel to Z_AXIS.
I have added the following lines and it seems to work, but is it the correct solution?if !vector.parallel?(Z_AXIS) then > up = Z_AXIS > else > up = Y_AXIS > end
It's a good trap!
PS you don't need the 'then' and perhaps more 'simply' putif vector.parallel?(Z_AXIS) up = Y_AXIS else up = Z_AXIS end
Advertisement