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 > endIt'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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement