Hi
It is possible to create components with ruby code, but i believe its much easier to use the ruby code to load a defined component and position it,
I will continue with the pipe line DC, I created earlier and develop that.
If you look at the cylinder code in the linetool example,
%(#000080)[vec = pt2 - pt1
length = vec.length
if( length == 0.0 )
UI.beep
puts "Cannot create a zero length cylinder"
return
end]
I used that as the starting point, initially changing the cylinder for a simple line.
I now need to load a component and scale, then rotate it to the line created.
%(#0000BF)[path = Sketchup.find_support_file('rod.skp', 'Plugins/su_examples/')
definitions = Sketchup.active_model.definitions
definition = definitions.load(path)]
to get a scaling factor I saved the pipe line DC with a length of 1 meter and used that to scale to the length of the line. I loaded that DC to the su_examples folder
http://ruby-doc.org/core-2.2.0/Math.html
gives the syntax for the maths
being a roof carpenter, I used my knowledge of the relationship between a rafter and a hip (bevel cuts, lengths) to create a transformation sequence for the rotation
searches in this forum helped to work out the method
then I deactivated the line as it was no longer required as a reference
added
dc_observers.get_latest_class.redraw_with_undo(componentinstance)
to redraw the scaled component (tig)
I have attached the amended rod.skp and linetool.rb, which can overwrite the existing in the C:\Users"computer name"\AppData\Roaming\SketchUp\SketchUp 2016\SketchUp\Plugins\su_examples
links
the base component
linetool.rb