[SOLVED]set standard view
-
I know it is possible to use Sketchup.send_action("viewIso:") to set the active_view to one of the standard views.
The problem is, when this is used in a loop like this all images return equal:standardviews=['SV_Top','SV_Bottom','SV_Front','SV_Back','SV_Left','SV_Right','SV_Iso'] standardviews.each{|view| if view=='SV_Top' Sketchup.send_action("viewTop;") elsif view=='SV_Bottom' Sketchup.send_action("viewBottom;") elsif view=='SV_Front' Sketchup.send_action("viewFront;") elsif view=='SV_Back' Sketchup.send_action("viewBack;") elsif view=='SV_Left' Sketchup.send_action("viewLeft;") elsif view=='SV_Right' Sketchup.send_action("viewRight;") elsif view=='SV_Iso' Sketchup.send_action("viewIso;") end x = Sketchup.active_model.active_view path="c;\\"+Sketchup.active_model.title imagename = path+view.to_s+".jpg" Sketchup.set_status_text("Writing #{imagename}") x.write_image(imagename,200,200,true) }
Now when i add a messagebox at the end of the loop it seems to goes well.
This is probably gonna be something stupid, i really have an off day on coding SU ruby. -
Are you doing that within a start_operation block that disables the UI?
-
Not 100% sure, but...
What is the Scene transition time set to? Either set it to 0, or wait for the Scene animation to finish before writing the image.
-
ThomThom:
no, but i'll give it a shotJim:
scene transitions are off -
@pout said:
ThomThom:
no, but i'll give it a shotNo - I was thinking that might be why it didn't work.
Maybe you can use
view.refresh
? -
Ah, there are no scenes, so no scene tranistions.
Oh, and even simpler:
standardviews = %w(viewTop; viewBottom; viewFront; viewBack; viewRight; viewLeft viewIso;) standardviews.each do |view| Sketchup.send_action(view) # write image end
-
Thx Jim for the code update
ThomThom,
I've tried just to see if there was any diff. and there is none.
I also already tried to do active_view.refresh after each view switch but that doesn't help either.
In the API this is the explanation on send_action:
The send_action method sends a message to the message queue to perform some action asynchronously.I don't know if this could have something to do with it
Btw did you try the code?
Extra info, if you switch pages 'scenes) in the same loop all goes well.
-
Hm...
Tried setting the camera object itself instead of issuing the SU commands? -
I was thinking about that.
But I need the standard views attributes for that so i can use them in a camera definition.
I have not yet found a way to adress these standard views. (or i'm looking over it completely) -
@pout said:
But I need the standard views attributes for that so i can use them in a camera definition.
Attributes? Camera definitions? -
You mean how to set the camera vectors?
I'd think just setting the camera to match X_AXIS, YAXIS and Z_AXIS should be enough... ?
-
yes to 'copy' the standard cameras it would be great to be able to copy the eye, target and up of the standard cameras into new cameras so i can use those.
fact is i can't itterate over those standard cameras as shown above and i need the specific values of eye and target otherwise i need to calculate the center of the bounding box of all elements of the model to specify the eye and target.At the other hand, maybe i'm lacking any sense today (you wouldn't be the first to say that today )
-
And once you set the camera eye to target vector to suit an AXIS vector you need to use
Sketchup.send_action("viewZoomExtents:")
to see everything ??? -
The native standard view buttons doesn't zoom extent - but if that is what you want - then eye and target does not matter.
direction = Z_AXIS.reverse Sketchup.active_model.active_view.camera.set( ORIGIN, direction, direction.axes.y) Sketchup.active_model.active_view.zoom_extents
-
Overview of the code for each standard view (informative)
Top
direction = Z_AXIS.reverse Sketchup.active_model.active_view.camera.set( ORIGIN, direction, direction.axes.y) Sketchup.active_model.active_view.zoom_extents
Bottom
direction = Z_AXIS Sketchup.active_model.active_view.camera.set( ORIGIN, direction, direction.axes.y) Sketchup.active_model.active_view.zoom_extents
Front
direction = Y_AXIS Sketchup.active_model.active_view.camera.set( ORIGIN, direction, direction.axes.y) Sketchup.active_model.active_view.zoom_extents
Back
direction = Y_AXIS.reverse Sketchup.active_model.active_view.camera.set( ORIGIN, direction, direction.axes.y) Sketchup.active_model.active_view.zoom_extents
Left
direction=X_AXIS Sketchup.active_model.active_view.camera.set( ORIGIN, direction, direction.axes.y) Sketchup.active_model.active_view.zoom_extents
Right
direction=X_AXIS.reverse Sketchup.active_model.active_view.camera.set( ORIGIN, direction, direction.axes.y) Sketchup.active_model.active_view.zoom_extents
Iso
direction=Geom;;Vector3d.new -0.666667, 0.666667, -0.333333 Sketchup.active_model.active_view.camera.set( ORIGIN, direction, direction.axes.y) Sketchup.active_model.active_view.zoom_extents
This emulates the standard cameras, combined with zoom extents.
Credits to ThomThom!
Advertisement