Hi all. Can someone tell me how to use 3D dot boards as an argument for a method or function? The following code doesn’t work. It displays “undefined method ‘Point3d’ for main:Object”
Thank you jimhami42, thank you DanRathbun.
My problem is a little more complicated. It is part of a gear calculation project. The dot boards that I have to deal with come out of a method that finds me the points of all instances and thus provides me with large 3D dot tables. Unless I find another technique to get non-3D points, I have to find a way to switch these 3D scoreboards into arguments, otherwise the code is likely to quickly become very heavy!
The method that sends me back from 3D dot tables is:
def plrecoveredge( instance )
ents = instance.definition.entities
edges = ents.grep(Sketchup::Edge)
vertices = edges.flat_map(&:vertices).uniq
points = vertices.map(&:position)
# Now the points are local to the instance's transformation.
# They need to be converted to “global” coordinates
xform = instance.transformation
ptsedges = points.map {|pt| pt.transform(xform) }
ptsedges
end #plrecoveredge
Oh that is a conversion, not a transformation.
It is simple … add a call to Geom::Point3d#to_a in the #map block …
def plrecoveredge( instance )
ents = instance.definition.entities
edges = ents.grep(Sketchup::Edge)
vertices = edges.flat_map(&:vertices).uniq
points = vertices.map(&:position)
# Now the points are local to the instance's transformation.
# They need to be converted to “global” coordinates
xform = instance.transformation
# Convert to simple [x,y,z] array in global coordinates
points.map {|pt| pt.transform(xform).to_a }
end #plrecoveredge
Note, by convention, Ruby uses method names that have words separated with underscores …