Description

Permet de sélectionner un rectangle et de créer une polyligne qui suit un motif en zigzag représentant un isolant. Le motif en zigzag est inscrit dans le rectangle et sa taille d’onde est égale à la taille du côté du motif en zigzag. Le script fonctionne avec les rectangles horizontaux et verticaux.

Le script ne fonctionne pas sur les rectangles tournés qui ne sont pas strictement horizontaux ou verticaux.

Le script suivant fonctionne sur :

  • Rhino pour Windows ;
  • Rhino pour macOS.

Script par MLAV.LAND, sous licence GNU GPL 3.

Code

import rhinoscriptsyntax as rs
 
# Create an empty list to store the points
points = []
 
# Ask the user to select a rectangle
rectangle = rs.GetObject("Select a rectangle")
if rectangle is None: exit()
 
# Get the bounding box of the rectangle
bbox = rs.BoundingBox(rectangle)
 
# Get the width and height of the bounding box
width = rs.Distance(bbox[0], bbox[1])
height = rs.Distance(bbox[0], bbox[3])
 
# Get the smaller side of the rectangle
zigzag_side = (min(width, height) / 0.866025403) / 2
 
# Check if the rectangle is horizontal or vertical
if width > height:
    # Rectangle is horizontal
    for i in range(int((width+zigzag_side)/zigzag_side + 1)):
        x = bbox[0][0] + i * zigzag_side
        y = bbox[0][1] + (i % 2) * height
        points.append((x, y, 0))
else:
    # Rectangle is vertical
    for i in range(int((height+zigzag_side)/zigzag_side + 1)):
        x = bbox[0][0] + (i % 2) * width
        y = bbox[0][1] + i * zigzag_side
        points.append((x, y, 0))
 
# Draw a line that passes through all the points
rs.AddPolyline(points)