First of all: I am NOT a programmer, so there is ZERO error handling on this quick-and dirty script. I had tried TIG's solution, but did not work on my DWG because some of the arcs would "clip" others as they were rebuilt by the script.
So I wrote this small routine to:
loop through imported AutoCAD entities.
select curves and group them (individually)
create a more refined clone of the curve (the number of segments is controlled by two parameters. See script)
Delete the original curve.
Anyone is welcome to turn this snippet into something better and more reusable.
Best,
Marcos.
theModel = Sketchup.active_model
#selEntities = theModel.selection
theModel.selection.clear
allEntities = theModel.entities
Collect user values:
prompts = ["Minimum number of segments:", "Minimum Segment Length:"]
defaults = [36, 10]
input = UI.inputbox(prompts, defaults, "Enter Desired Settings")
#set minimum length for each arc segment (in model units)
userSegs = input[0]
minLen = input[1]
#UI.messagebox(userSegs.to_s)
#UI.messagebox(minLen.to_s)
allEntities.each do |i|
if (i.typename == "Edge")
aCurve = i.curve
if (aCurve)
Sel = theModel.selection unless defined?(Sel)
Sel.add (aCurve.edges)
newGroup = allEntities.add_group (theModel.selection)
Sel.clear
else
#not a Curve
end
end
end
theModel = Sketchup.active_model
theModel.selection.clear
allEntities = theModel.entities
Loop through all entities
allEntities.each do |i|
#open Groups, search for Curves
if (i.typename == "Group")
#Loop through array of Entities inside each Group
subset = i.entities
subset.each do |s|
curve = s.curve
# if it is a curve, collect a few properties
if (curve)
# get coord. transformation, since entities are in a group
#use "transform" below to translate to global coordinates
tr=i.transformation
cCenter = curve.center.transform! (tr)
cSangle = curve.start_angle
cEangle = curve.end_angle
cRadius = curve.radius
cNormal = curve.normal.transform! (tr)
cXaxis = curve.xaxis.transform! (tr)
cYaxis = curve.yaxis.transform! (tr)
cLength = curve.length
#UI.messagebox(" Curve Length is " + cLength.to_s)
#divides arcs in minLen(model unit) increments
divSegs = (cLength / minLen).to_i
#UI.messagebox("Divided Result is " + divSegs.to_s)
#for very small arcs, sets a minimum number of segments
if (divSegs <= userSegs)
numSegs = userSegs
# UI.messagebox("Using: " + numSegs.to_s)
else
#subdivides larger arcs using target length
numSegs = divSegs.to_i
# UI.messagebox("using Divided total" + numSegs.to_s)
end
myarc = allEntities.add_arc cCenter,cXaxis,cNormal,cRadius,cSangle,cEangle,numSegs
#Erases original
i.erase!
end # if curve
end # entities inside group loop
end # if it is a group
end #loop through all entities