Error: No implicit conversion of Float into Array


#1

Here is the code:
ent = Sketchup.active_model.entities

#Hexagon head
hex_curve = ent.add_ngon [0, 0, 0], [0, 0, 1], 4, 6
hex_face = ent.add_face hex_curve
hex_face.pushpull -3

#Screw and bolt group created
screw_curve = ent.add_circle [0, 0, -8], [0, 0, 1], 1.5
screw_face = ent.add_face screw_curve
screw_face.pushpull 8
bolt_group = ent.add_group ent.to_a
bolt_group.name = “Hex Bolt”

#Create nut
nut_curve = ent.add_ngon [10, 0, 0], [0, 0, 1], 3, 4
nut_face = ent.add_face nut_curve
nut_face.reverse!
nut_face.pushpull 1.5
cut_curve = ent.add_circle [10, 0, 0], [0, 0, 1], 1.5
cut_curve[0].faces[0].pushpull -1.5
nut_group = ent.add_group cut_curve[0].faces[1].all_connected
nut_group.name = "Square Nut"
nut_group.transform! [-10, 0, -7]

full_group = ent.add_group bolt_group, nut_group
full_group.name = "Nut-Bolt Group"
t2 = Geom::Transformation.translation [10, 10, 10]
t1 = Geom::Transformation.rotation [0, 0, 0], [1, 1, 1] -45.degrees
full_group.transform! t1 * t2

The result is no implicit conversation of float into array. Error, why?


#2

You can edit your post to use formatting, select the code and mark it as code to make it better readable:

``` ruby
# your ruby code
```

Also it is better to provide the complete and exact error message. When you run the code in the Ruby Console, you get:

Error: #<TypeError: (eval):693:in `-': can't convert Float into Array>

When skimming through the code, look for a place where a minus operator (method) is used and expects an array as argument, but receives a float instead. The “minus” method only then expects to get an array, when it is used on an array: Array#-

In your code that is the case in the 3rd last line where you attempt to subtract 45.degrees from [1, 1, 1] (Computers are so silly, but for humans it’s obvious that it was just a missing comma).

If you had copy-pasted the code into a file, enclosed it in a method and a module and run it, you would even get an exact line number.


#3

[quote=“schiavo_caroline, post:1, topic:1758”]
Geom::Transformation.rotation [0, 0, 0], [1, 1, 1] -45.degrees
[/quote] contains issues.
It takes a point, so [0,0,0] == ORIGIN … OK
Then a vector, but [1,1,1] is a weird length vector - try [0,0,1] or Z_AXIS
AND the third argument ‘angle’ must be separated by a ‘,’ - otherwise it assumes you are trying to subtract 45.degrees from an array == error !
The error message tells you the problem !
So try some thing like:
Geom::Transformation.rotation([0, 0, 0], [0, 0, 1], -45.degrees)


#4

Actually

Geom::Vector3d.new([1,1,1]).length

-> 1.7321"