I am writing a extension to create groove/ridges in sketchup with user selected line.
I do not know how to let ruby understand which perpendicular direction I want in 3D space.
With AI attempt so far.
SketchUp Ruby script to create a groove from a selected line with user-defined options
model = Sketchup.active_model
entities = model.active_entities
Retrieve or initialize the last entered values
last_thickness_key = "last_gap_thickness"
last_height_key = "last_gap_height"
if model.get_attribute("user_data", last_thickness_key)
last_thickness = model.get_attribute("user_data", last_thickness_key)
else
last_thickness = 100.0.mm
end
if model.get_attribute("user_data", last_height_key)
last_height = model.get_attribute("user_data", last_height_key)
else
last_height = -100.0.mm
end
Step 1: Get the selected edge (line)
selected_lines = model.selection.grep(Sketchup::Edge)
if selected_lines.size != 1
UI.messagebox("Please select exactly one line.")
return
end
line = selected_lines.first
Step 2: Get the start and end points of the selected line
start_point = line.start.position
end_point = line.end.position
Step 3: Calculate the direction vector of the selected line
direction_vector = end_point - start_point
normalized_direction = direction_vector.normalize
Step 4: Determine the perpendicular vector
perpendicular_vector = Geom::Vector3d.new(-normalized_direction.y, normalized_direction.x, 0).normalize
Step 5: Get user inputs for groove creation
prompts = ["Groove Position (Center, Left, Right):", "Gap Thickness (in mm):", "Gap Height/Depth (in mm):", "Create Top Face?", "Create Base Face?", "Create Left Face?", "Create Right Face?", "Create Front Face?", "Create Back Face?"]
defaults = ["Center", last_thickness.to_mm, last_height.to_mm, true, true, true, true, true, true]
input = UI.inputbox(prompts, defaults, "Enter Groove Options")
groove_position = input[0].downcase
gap_thickness = input[1].to_f.mm
gap_height = input[2].to_f.mm
create_top_face = input[3]
create_base_face = input[4]
create_left_face