Move group to left corner of screen
-
Hallo, I need your help on above issue.
I want to perform a view.write_image of a selected Group with coloured faces and use this Image as texture for a Terrain.
The only way I found to apply the Image to the Terrain in a proper way, is by
aligning the group to the left/upper side of the screen before writing the Image.Otherwise the Image contains uncolored portions to the left and the top of the Image.
I tried to move the Group to the upper left Corner using the following code:
model = Sketchup.active_model @view = model.active_view keys = { ;filename => @chosen_file, ;width => @view.vpwidth, ;height => @view.vpheight, ;antialias => false, ;compression => 0.9, ;transparent => true } ip0=@view.inputpoint(0,0) ip1=@view.inputpoint(@view.vpwidth,0) p0=ip0.position p1=ip1.position sel= model.selection bbox = sel[0].bounds sel[0].move! [p0.x+bbox.width/2,p0.y-bbox.height/2,0] view.write_image keys view.invalidate
Unfortunately this does not work reliable.
Any better ideas? Maybe there is even a more simple solution.
Very much appreciate your help!
-
@view.zoom sel[0]
-
Thanks Dan for the quick reply.
I tried it before, but what I get is the below Image. I need an Image without the green borders at the left and at the top..
-
Select the object.
Change to a non-perspective Camera.
Change to a Plan view.
Then Zoom extents of the Selection.
There are Sketchup.send_action methods for these:Sketchup.send_action(10519) ### PC only, otherwise mess on with model.active_view.camera settings... Sketchup.send_action("viewTop:") Sketchup.send_action("viewZoomToSelection:")
-
Be aware that if the aspect ratio of the image does not match that of the view, it can not be zoomed to fill the entire view window!
-
Thanks for your help,
- I draw a simple rectangle
Then I tried:
Sketchup.send_action(10519) #Change to a non-perspective Camera. Sketchup.send_action("viewTop;") #Change to a Plan view. Sketchup.send_action("viewZoomToSelection;") #Zoom extents of the Selection.
Unfortunately I still have the annoying green borders as shown in the below Image. Can anybody try it and come back with his/her Image.
I have no clue what is wrong.
Help is very much appreciated
- I draw a simple rectangle
-
@sonjachr said:
Thanks for your help,
- I draw a simple rectangle
Then I tried:
Sketchup.send_action(10519) #Change to a non-perspective Camera. > Sketchup.send_action("viewTop;") #Change to a Plan view. > Sketchup.send_action("viewZoomToSelection;") #Zoom extents of the Selection. > >
Unfortunately I still have the annoying green borders as shown in the below Image. Can anybody try it and come back with his/her Image.
I have no clue what is wrong.
Help is very much appreciated
First of all, the face dimensions would have to perfectly match the screen dimensions and even then the "border" would still exists after zoom extents or selection.
I would suggest capturing the screen and paste into a image editing program and crop it.
- I draw a simple rectangle
-
I can ' t ask the user to triim the image by himself, before my code is going to put it as a texture onto a terrain.
Any further ideas?
It seems to be the last open issue in my routine, so I am very eager to get this solved.
Thanks for your help
-
@sonjachr said:
I can ' t ask the user to triim the image by himself, before my code is going to put it as a texture onto a terrain.
Any further ideas?
It seems to be the last open issue in my routine, so I am very eager to get this solved.
Thanks for your help
I thought I had this figured out before but the code I posted quite working as soon as I posted it. Very strange. I obviously made a change and didn't know it. yada yada yada
This code seems to work even better than the previous anyway. Although it has a top view command it, it takes two executions if model is not already in top view. Can't imagine why it just does. So pick top view then execute.
mod = Sketchup.active_model ent = mod.active_entities sel = mod.selection vue = mod.active_view Sketchup.send_action 10501#"viewTop;" vue.zoom sel fac = sel[0] ulc = fac.bounds.corner(2); puts "ulc=#{ulc}" dst = vue.pixels_to_model 1,ulc; cor = vue.screen_coords(ulc); puts "cor=#{cor}" vec = Geom;;Vector3d.new(-cor.x*dst,cor.y*dst,0) tr = Geom;;Transformation.new(vec) ent.transform_entities(tr,fac)
-
@sonjachr said:
Hallo, I need your help on above issue.
I want to perform a view.write_image of a selected Group with coloured faces and use this Image as texture for a Terrain.
The only way I found to apply the Image to the Terrain in a proper way, is by
aligning the group to the left/upper side of the screen before writing the Image.Otherwise the Image contains uncolored portions to the left and the top of the Image.
I tried to move the Group to the upper left Corner using the following code:
model = Sketchup.active_model > @view = model.active_view > > keys = { > ;filename => @chosen_file, > ;width => @view.vpwidth, > ;height => @view.vpheight, > ;antialias => false, > ;compression => 0.9, > ;transparent => true > } > > ip0=@view.inputpoint(0,0) > ip1=@view.inputpoint(@view.vpwidth,0) > p0=ip0.position > p1=ip1.position > sel= model.selection > bbox = sel[0].bounds > sel[0].move! [p0.x+bbox.width/2,p0.y-bbox.height/2,0] > view.write_image keys > view.invalidate >
Unfortunately this does not work reliable.
Any better ideas? Maybe there is even a more simple solution.
Very much appreciate your help!
Played around with your code and got it to work, sort of. Like mine, including top view and zoom selection commands caused it not to work.
.move! is only for groups and/or components and is not undoable so should be avoided.
Here is my version of your code.
#Sketchup.send_action 10501 #top view #Sketchup.send_action 21469 #zoom sel model = Sketchup.active_model @view = model.active_view sel= model.selection 0.upto(1){ ip0=@view.inputpoint(0,0); p0=ip0.position; p1 = sel[0].bounds.corner(2); sel[0].transform! Geom;;Transformation.new(p0-p1) }#do it twice keys = { ;filename => @chosen_file, ;width => @view.vpwidth, ;height => @view.vpheight, ;antialias => false, ;compression => 0.9, ;transparent => true } #view.write_image keys @view.invalidate
-
Wow! This is awesome! It works!
Thanks a lot.
I almost gave up!
Good to know, that there are real experts in this forum who are willing to help.Thanks again.
Advertisement