Hi,
I am now on holiday, and i use this calm time to continue my exemples on ruby.
I have few point
- lines don’t show properly and It doesn’t build a proper component.
- Is there a simpler way to code it? Like use name lines to make it move according to parameters
- Is there so people who use Modus? would it be apropriate in this case?
- beside, Is there some point of view on the Copilot, the new plugin of Visual Studio Code? Is it useful for Sketchup API?
Could you help me? I maybe don’t have all the basics but this exemples and little project helps me to understand the tool and the environement… I am not an armchair ruby programmer
here is my lines of code.
# load "C:/ruby_scripts/JoueTole_v6.rb"
require 'sketchup.rb'
=begin
History
* 1.1.0:: 2021-01-09
*first version
ToDoList
*
=end
Sketchup.send_action "showRubyPanel:"
# Add a menu item to Launch our pluging
UI.menu("PlugIns").add_item("Joue gauche") {
Sketchup.active_model.start_operation "Joue gauche"
# Create a new layer
model = Sketchup.active_model
l_new = model.layers.add "Bardage"
model.active_layer = l_new
#List of entities of the roof
variables
joue_gauche
#Commit the operation
model.commit_operation
}
def variables
prompts = nil
prompts = [
'Epaisseur bardage:',
'Profondeur total ebrasement:',
'largeur prise:',
#'Hauteur ebrasement'
]
parametres = [
20.mm,
50.mm,
30.mm,
#1000.mm
]
parametres = UI.inputbox( prompts, parametres, "Caractéristiques")
#Create some variables
@epaiss_bard = parametres[0] #Epaisseur du bardage
@prof_ebrasement = parametres[1] #Profondeur ebrasement
@larg_prise = parametres[2] #largeur de prise derrière le bardage
@hauteur_ebrase = parametres[3] #hauteur tableau
end
def joue_gauche
#Create the component definition
model = Sketchup.active_model
joue_gauche_def = model.definitions.add("joue_gauche")
joue_gauche_ent = joue_gauche_def.entities
@rayon_inter = 1.5.mm
@rayon_exter = 3.mm
@epaiss_tole = 1.5.mm
x0 = 0
x1 = @larg_prise
x2 = @larg_prise + @rayon_inter
x3 = x2 + @epaiss_tole
x4 = x3 + @rayon_inter
x5 = x4 + @rayon_inter
x6 = x5 + @epaiss_tole
y1 = 0 - @epaiss_bard - @rayon_inter
y2 = 0 - @rayon_inter
y3 = 0
y4 = @epaiss_tole
y5 = @epaiss_tole + @prof_ebrasement - @epaiss_bard
z = 0
pt1 = [x0, y3, z]
# Create a 1/4 circle, radius of 5, normal to the Z axis
center = Geom::Point3d.new x1, y2, 0
normal = Geom::Vector3d.new 0, 0, 1
xaxis = Geom::Vector3d.new 1, 0, 0
start_a = Math::PI/2
end_a = 0
model = Sketchup.active_model
entities = model.entities
edgearray1 = entities.add_arc center, xaxis, normal, @rayon_inter, start_a, end_a
edge = edgearray1[0]
arccurve = edge.curve
start_angle1 = arccurve.start_angle
pt2 = edgearray1[0].start
pt3 = edgearray1[-1].end
# Create a 1/4 circle, radius of 5, normal to the Z axis
center = Geom::Point3d.new x4, y1, 0
normal = Geom::Vector3d.new 0, 0, -1
xaxis = Geom::Vector3d.new 1, 0, 0
start_a = 0
end_a = Math::PI
model = Sketchup.active_model
entities = model.entities
edgearray2 = entities.add_arc center, xaxis, normal, @rayon_exter, start_a, end_a
edge = edgearray2[0]
arccurve = edge.curve
start_angle2 = arccurve.start_angle
pt4 = edgearray2[-1].end
pt5 = edgearray2[0].start #good
pt6 = [x6, y5, z]
pt7 = [x5, y5, z]
# Create a 1/4 circle, radius of 5, normal to the Z axis
center = Geom::Point3d.new x4, y1, 0
normal = Geom::Vector3d.new 0, 0, -1
xaxis = Geom::Vector3d.new 1, 0, 0
start_a = 0
end_a = Math::PI
model = Sketchup.active_model
entities = model.entities
edgearray3 = entities.add_arc center, xaxis, normal, @rayon_inter, start_a, end_a
edge = edgearray3[0]
arccurve = edge.curve
start_angle3 = arccurve.start_angle
pt8 = edgearray3[0].start #good
pt9 = edgearray3[-1].end
# Create a 1/4 circle, radius of 5, normal to the Z axis
center = Geom::Point3d.new x1, y2, 0
normal = Geom::Vector3d.new 0, 0, 1
xaxis = Geom::Vector3d.new 1, 0, 0
start_a = 0
end_a = Math::PI/2
model = Sketchup.active_model
entities = model.entities
edgearray4 = entities.add_arc center, xaxis, normal, @rayon_exter, start_a, end_a
edge = edgearray4[0]
arccurve = edge.curve
start_angle4 = arccurve.start_angle
pt10 = edgearray4[0].start
pt11 = edgearray4[-1].end
pt12 = [x0, y4, z]
# Call methods on the Entities collection top drax stuff
face1 = joue_gauche_ent.add_face pt1, pt2, edgearray1, pt3, pt4, edgearray2, pt6, pt7, edgearray3, edgearray4, pt12
#atempt to weld the point and the curves
edges = face1.selection.grep(Sketchup::Edge)
curves = model.active_entities.weld(edges)
# entities objects is an edge.
entity1 = joue_gauche_ent[1]
# Getting zero.
number = entity1.find_faces
x = y = z = 0
ents = model.active_entities
joue_gauche1 = ents.add_instance(joue_gauche_def, [x, y, z])
joue_gauche1.explode
end
Thank you in advance,
Best regards,