How do i model this snake curve

i have not aidea how to do this curvs as long asis posible, using loop.
if some one help I apreciate in advance, sorry my english. :stuck_out_tongue_winking_eye:

	model = Sketchup.active_model
		entities = model.entities

		pt1 = [0.mm, 0.mm,0.mm]
		pt2 = [18.mm, 0.mm,0.mm]
		
		pt3 = [18.mm, 15.mm, 0.mm]
		pt4 = [36.mm, 15.mm,0.mm]
		
		pt5 = [36.mm, 0.mm,0.mm]
		pt6 = [54.mm, 0.mm,0.mm]
		
		pt7 = [54.mm, 15.mm,0.mm]
		pt8 = [72.mm, 15.mm,0.mm]
		
		pt9 = [72.mm, 0.mm, 0.mm]
		pt10 = [90.mm, 0.mm,0.mm]


		pt11 = [90.mm, 15.mm, 0.mm]
		pt12 = [108.mm, 15.mm,0.mm]
		
		pt13 = [108.mm, 0.mm,0.mm]
		pt14 = [126.mm, 0.mm,0.mm]
		
		pt15 = [126.mm, 15.mm,0.mm]
		pt16 = [144.mm, 15.mm,0.mm]

		pt17 = [144.mm, 0.mm,0.mm]
		pt18 = [162.mm, 0.mm,0.mm]
		
		pt19 = [162.mm, 18.mm,0.mm]
		pt20 = [0.mm, 18.mm, 0.mm]
		# set more points
        contador = Sketchup.active_model.definitions.count;
		componente = Sketchup.active_model.definitions.add("Componente#" + contador.to_s) ;
		cara = componente.entities.add_face pt1, pt2, pt3, pt4,pt5,pt6,pt7,pt8,pt9,pt10,pt11,pt12,pt13,pt14,pt15,pt16,pt17,pt18,pt19,pt20
		cara.pushpull thickness	

Here is an example method. (A continuación se muestra un método de ejemplo.)

# Create a grooved plate. (Crear una placa ranurada.)
def placa_ranurada(
  num = 1,   # number of grooves (número de ranuras)
  t = 40.mm, # plate length (longitud de la placa)
  w = 18.mm, # groove width (ancho de la ranura)
  d = 15.mm  # groove depth (profundidad de la ranura)
)
  model = Sketchup.active_model
  x = w
  # Array of points (Matriz de puntos):
  pts = [
    [0, 0, 0], [x, 0, 0]
  ]
  # Add groove points for each groove in plate:
  # (Agrega puntos de ranura para cada ranura en la placa):
  num.times do
    pts << [x, d, 0]
    x += w
    pts << [x, d, 0]
    pts << [x, 0, 0]
    x += w
    pts << [x, 0, 0]
  end
  # Add the closing points (Agregar los puntos de cierre):
  pts << [x, w, 0]
  pts << [0, w, 0]
  #
  dlist = model.definitions
  componente = dlist.add("Componente##{dlist.count.to_s}")
  cara = componente.entities.add_face(pts)
  if cara.valid?
    cara.pushpull(-t)
    componente
  else
    # Error creating face!
    UI.messagebox("¡Error al crear la cara!")
    nil
  end
end
3 Likes

Thanks for the help DanRathbun. It looks good a simplified version of my long code. :+1:

1 Like

I made some small changes to it and it works great…! thank you very much again…! :ok_hand:

# Create a grooved plate. (Crear una placa ranurada.)
def placa_ranurada(
 num = 5,   # number of grooves (número de ranuras)
  t = 40.mm, # plate length (longitud de la placa)
  w = 18.mm, # groove width (ancho de la ranura)
  d = 15.mm  # groove depth (profundidad de la ranura)
)
  model = Sketchup.active_model
	entities = model.entities
  x = w
  # Array of points (Matriz de puntos):
  pts = [
    [0, 0, 0], [x, 0, 0]
  ]
  # Add groove points for each groove in plate:
  # (Agrega puntos de ranura para cada ranura en la placa):
  num.times do
    pts << [x, d, 0]
    x += w
    pts << [x, d, 0]
    pts << [x, 0, 0]
    x += w
    pts << [x, 0, 0]
  end
  # Add the closing points (Agregar los puntos de cierre):
  pts << [x, w, 0]
  pts << [0, w, 0]
	
  #dlist = model.definitions
  #componente = dlist.add("Componente##{dlist.count.to_s}")
  cara = entities.add_face(pts)
  if cara.valid?
    cara.pushpull(-t)
    #componente
  else
    # Error creating face!
    UI.messagebox("¡Error al crear la cara!")
    nil
  end

end
1 Like

No problem. It is for learning.

However, adding the geometry to the main model entities collection could merge with other primitive geometry at the top-level.

An alternative is to add a group and add the face to the group.entities (which actually adds then to the group.definition.entities.)

1 Like

:+1: :stuck_out_tongue_winking_eye: