Aligning camera to section view

sketchup

#1

Is there a ruby command to align camera to a section plane Like command “Align view”?
Or I need to find the plane, than the normal vector, than the up vector, than align the camera?


#2

You can select the section cut itself and align view.

Oops, sorry, didn’t realise this was a developer question. Just ignore me.


#3

It’s a little bit trickier than it could have been.

You can get a plane from a Section Plane’s get_plane method. However the returned plane is defined by 4 coordinates and you need to manually get the plane normal out of them. Once you’ve got a normal vector you can set the camera target to the camera eye offset by that vector.


#4

A section-plane [sp] has a plane [plane = sp.get_plane] and from that you can get its normal = plane[0..2].
So you can set a new camera using the n = normal.reverse as its direction of view…
Project an arbitrary point onto the ‘plane’ - this is now the ‘target’, offset it by ‘n’, to get the ‘eye’.
Use those to make and set the new camera then, zoom-extents to ensure you see everything…


#5

The code could be something like this, given that a section plane is the only selected Entity in the model:

# Convert plane defined by 4 coordinate Array into one defined by Poin3d and Vector3d Array.
# Source: http://sketchucation.com/forums/viewtopic.php?f=180&t=25462
def format_plane(plane)
  return plane if plane.length == 2
  a, b, c, d = plane
  v = Geom::Vector3d.new(a,b,c)
  p = ORIGIN.offset(v.reverse, d)
  
  [p, v]
end

model = Sketchup.active_model
section_plane = model.selection.first
plane = section_plane.get_plane
plane = format_plane(plane)

cam = model.active_view.camera
cam.set(cam.eye, cam.eye.offset(plane[1]), Z_AXIS)

#6

Thank you, now I’ve all the answers I needed.

  1. There is no direct soluction
  2. How to find the normal vector

Distinti saluti

Kind regards

Saludos

Mit freundlichen Grüßen

Sincères salutations

Ing. Paolo Danielli

O&P s.r.l.

Via dei Bocchi 352/D

55010 Segromigno in Piano – Lucca

Tel. +39 0583 926598

Fax. +39 0583 921800

mecdep@oepweb.com

The information included in this e-mail and any attachments are
confidential and may also be privileged.

The diffusion, distribution e/o copying of the document transmitted from
any different subject from the recipient is forbidden, to the senses of the
art. 616 c.ps. and to the senses of the D.Lgs. n.196/2003.

If you are not the correct recipient, you are kindly requested to notify
the sender immediately at mecdep@oepweb.com or +39 0583 926598, to cancel
it and not to disclose the contents to any other person.

2017-07-24 13:40 GMT+02:00 Julia Christina Eneroth <
sketchup@discoursemail.com>:


#7

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.