I’ve this code, but i need to apply a zoom extents in my object to fit it in the scene:
# Função para criar uma cena com a vista para trás (Back view)
def criar_cena_tras
model = Sketchup.active_model
# Define as configurações da nova cena
scene = model.pages.add("Back View")
scene.camera.set([0, 10, 0], [0, 0, 0], [0, 0, 1]) # Configura a câmera com a vista para trás
scene.camera.perspective = false
puts "Cena 'Back View' criada!"
fit_selected_object_in_view_with_zoom_extents(scene)
end
# Função para ajustar a visualização para ajustar o objeto selecionado na cena
def fit_selected_object_in_view_with_zoom_extents(scene)
model = Sketchup.active_model
selection = model.selection
return if selection.empty?
# Atualiza a visualização para ajustar o objeto selecionado na cena
model.active_view.refresh
model.active_view.zoom_extents
puts "Objeto selecionado ajustado na cena!"
end
criar_cena_tras
Pass the selection (or other objects) to the zoom
method, not the zoom_extents
method.
# Função para ajustar a visualização para ajustar o objeto selecionado na cena
def fit_selected_object_in_view_with_zoom_extents(scene)
model = Sketchup.active_model
selection = model.selection
return if selection.empty?
# Atualiza a visualização para ajustar o objeto selecionado na cena
model.active_view.refresh
model.active_view.zoom(selection) # <<<<-------<<<<<<<<<<<
puts "Objeto selecionado ajustado na cena!"
end
1 Like
Still not wotking. look, my object ins’t adjusted in the scene.
In the right view, it’s like “cutting” the view caus ins’t extented.
Right View:
Front View:
I tried again, and it’s worked as well.
Thank you bro.
1 Like
I had to change the other method as well …
def criar_cena_tras
model = Sketchup.active_model
# Define as configurações da nova cena
scene = model.pages.add("Back View")
scene.camera.set([0, 10, 0], [0, 0, 0], [0, 0, 1]) # Configura a câmera com a vista para trás
scene.camera.perspective = false
model.pages.selected_page= scene
model.active_view.refresh
puts "Cena 'Back View' criada!"
fit_selected_object_in_view_with_zoom_extents(scene)
end
1 Like
i’ll to try and verify.
So… can you help me with another part of my code?
I’m trying to create an scene with a section plane activated, but it’s creating the scene, setting the view, creating the section plane, but the SP doens’t be active in the scene
.
# Função para criar uma cena com perspectiva desligada e vista traseira
def criar_cena_vista_traseira
model = Sketchup.active_model
# Define as configurações da nova cena
scene = model.pages.add("Cena Vista Traseira")
scene.camera.perspective = false
section_plane = model.entities.find { |entity| entity.is_a?(Sketchup::SectionPlane) && entity.name == "C.03" }
if section_plane
section_plane.activate
puts "Corte 03 ativado!"
else
puts "Section plane C.03 não encontrado."
end
view = model.active_view
view.camera.set([0, 0, 0], [-1, 0, 0], [0, 0, 1])
view.zoom_extents
puts "Cena Vista Traseira criada!"
end
You should start a new topic for other issues, as this topic is solved.
P.S. - You need to update the scene page so it saves the section plane active state.
1 Like