Sorry, I’ve worked out how to post the full code.
module TIG
def self.arcface(ents=nil, cent=ORIGIN, axis=X_AXIS, norm=Z_AXIS, rad1=1.0, rad2=2.0, stara=0.0, enda=180.degrees)
ents=Sketchup.active_model.active_entities unless ents
grop=ents.add_group()
ents=grop.entities
arc1=ents.add_arc(cent, axis, norm, rad1, stara, enda)
arc2=ents.add_arc(cent, axis, norm, rad2, stara, enda)
vx10=arc1[0].start
vx20=arc2[0].start
edg1=ents.add_line(vx10, vx20)
vx12=arc1[-1].end
vx22=arc2[-1].end
edg2=ents.add_line(vx12, vx22)
edg2.find_faces
face=ents.grep(Sketchup::Face)
grop.explode
return face
end
end
########################################################################
#
# This script will create the layout for my absolute rotary encoder
# This will be used in the construction of my telescope.
# Written by Shane Frost
# 13 Nov 2014
#
# TODO
# Add gray code
# Add options
# Add mounting tabs
#
########################################################################
# Begin by declaring the variables
ring = 1
rings = 10
$r1 = 250
segments = 2.0
facets = 40
x = 0
y = 0
mountOffset = 15
#######################################################
# Add Inner circle
centre_point = Geom::Point3d.new(x,y,0)
normal_vector = Geom::Vector3d.new(x,y,1)
radius = ($r1 - mountOffset) / 25.4
entities = Sketchup.active_model.entities
edgearray = entities.add_circle centre_point, normal_vector, radius, 360
first_edge = edgearray[0]
arccurve = first_edge.curve
# Loop through the rings.
while ring < rings + 1 do
#Increment the radius by 10mm and reset the segment back to the first
$r2 = $r1 + 10
segment = 0
AngleVal = 360.0 / segments
#Loop through the segments of the ring
while segment < segments do
# Create an segment arc, normal to the Z axis
centre = Geom::Point3d.new
normal = Geom::Vector3d.new 0,0,1
xaxis = Geom::Vector3d.new 1,0,0
start_a = Math::PI * 2 / segments * segment
end_a = Math::PI * 2 / segments * (segment +1)
model = Sketchup.active_model
entities = model.entities
edgearray = entities.add_arc centre, xaxis, normal, $r1/25.4, start_a, end_a, facets
edge = edgearray[0]
arccurve = edge.curve
end_angle = arccurve.end_angle
#################################################
edgearray = entities.add_arc centre, xaxis, normal, $r2/25.4, start_a, end_a, facets
edge = edgearray[0]
arccurve = edge.curve
##################################################
# Now create the closing lines at the start of arc
point1 = Geom::Point3d.new(Math.cos(((360.0 / segments) *( segment )) * (Math::PI / 180)) * $r2 / 25.4, Math.sin(((360.0 / segments) *( segment)) * (Math::PI / 180)) * $r2 / 25.4,0) # Outer arc
point2 = Geom::Point3d.new(Math.cos(((360.0 / segments) *( segment )) * (Math::PI / 180)) * $r1 / 25.4, Math.sin(((360.0 / segments) *( segment)) * (Math::PI / 180)) * $r1 / 25.4,0) # Inner arc
line = entities.add_line point1,point2
##################################################
# Now create the closing lines at the end of arc
point1 = Geom::Point3d.new(Math.cos(((360.0 / segments) *( segment + 1)) * (Math::PI / 180)) * $r2 / 25.4, Math.sin(((360.0 / segments) *( segment + 1)) * (Math::PI / 180)) * $r2 / 25.4,0) # Outer arc
point2 = Geom::Point3d.new(Math.cos(((360.0 / segments) *( segment + 1)) * (Math::PI / 180)) * $r1 / 25.4, Math.sin(((360.0 / segments) *( segment + 1)) * (Math::PI / 180)) * $r1 / 25.4,0) # Inner arc
line = entities.add_line point1,point2
##################################################
# Find the faces
# Thanks to TIG from Sketchup Forums!
TIG.arcface(ents=nil, cent=ORIGIN, axis=X_AXIS, norm=Z_AXIS, rad1=$r1/25.4, rad2=$r2/25.4, stara=start_a, enda=end_a)
segment += 2 #Increment the segment
end
# Now increment the required variables before moving to the next ring.
ring += 1
$r1 += 10
segments += segments
facets -= 2
end
#######################################################
# Finish off by closing the outside of the disc.
centre_point = Geom::Point3d.new(x,y,0)
normal_vector = Geom::Vector3d.new(x,y,1)
radius = $r2 / 25.4
entities = Sketchup.active_model.entities
edgearray = entities.add_circle centre_point, normal_vector, radius, 360
first_edge = edgearray[0]
arccurve = first_edge.curve