How to read detail information from ruby code editor?

I am writing a program to simulate shadowing . But I can’t read more information from the debug procedures. As follows,

mod = Sketchup.active_model
info=mod.shadow_info
info[“Displayshadows”]=true
info[“DisplayOnGroundPlane”]=true
later=Time.now+ 60607
info[“ShadowTime”]=later
info[“Latitude”]=31
info[“Longitude”]=120
direction_towards_sun = info[“SunDirection”]
ray = [ Geom::Point3d.new(0, 0, 0), direction_towards_sun ]
ignore_hidden_geometry = false
result1 = mod.raytest( ray, ignore_hidden_geometry )

when I finish the runing procedures, how can I know the data of variable “result1”?

Many thanks.

What do you mean by detail?

the return data of the raytest function , I have no way to read it.

unless your ray passes through an item, result1 == nil

there is also a typo in your code which breaks it…

use Ruby Console to see all errors and results…

john

After fixing the typo [clue Displayshadows],
add p result1 afterwards to see what it returned
It can be nil for no ‘hit’, or an array [point, [hits-array]]

PS: Please format lengthy code using the code tags…

Two things about Ruby programming:

  1. A variable is stored in memory (in Ruby’s “ObjectSpace”) as long as the variable is alive / referenced by something.
  2. To get a value from a function/method, you need to return it with return (in Ruby usually the last expression is automatically returned).

That means for 1.) you type in and evaluate only the variable name to get a textual version of the variable’s value (as the default Window → Ruby Console does). According to the documentation (Array(Geom::Point3d, Array<Sketchup::Drawingelement>)?), you would expect that raytest either returns nil (check for it, if the ray hits nothing) or two objects, an intersection point and an array of the drawing elements that have been hit. You can nicely visualize the objects that your variables reference by using for example Ruby Console+, it may have helped to understand where the points and drawing elements are located in the model.

For 2.) there is the special case that you are evaluating a code snippet that is not wrapped in a function/method (and thus return is invalid), but the last value should be returned and printed by the Ruby Code Editor. Some consoles of some languages (like Python) do not print nil, but you should in any case see something for other values.