The issue is as desribed in title. I’ve got a first part of script (by Mitch Heynick - SimplifyCrv does not work) for simplifying near-circles coming from braille font of TextObject into real circles in order to make half spheres of real braille tactile font (2nd part of the script).
The problem is that after selecting near-circles for simplification and running the simplifying function, I want then to select next objects for simplification. The prompt runs to ‘Select Braille dots’ but I am not able to select any feature in the program.
I wonder if an issue is that I should somehow stop executing the first part of script so that I can freely proceed to 2nd part? What should I do? Hopefully the description is not too chaotic. Thanks in advance!
Kuba
"""Replaces closed planar curves that are near-circles with real circle objects
- including those that do not simplify with Rhino's normal simplify tool.
Stopgap tool for addressing a bug in Rhino V5 SimplifyCrv, hopefully to be made
redundant in future versions. Near-circles that have curve deviation of less than
file tolerance of an exact circle will be simplified to circles.
Script by Mitch Heynick 18.10.16
Revised 01.12.17 - added tolerance choice, changed compare method -
CrvDeviation is unreliable, this version relies on sampling curves
Setting 0 as tolerance will convert *any* planar closed curve to a circle
using average of bounding box x,y lengths/2 as radius."""
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
###############################################################################
#1st part of the script
def CurvePointDeviation(crvA,crvB,tol=sc.doc.ModelAbsoluteTolerance,samples=24):
#samples crvA and checks points against crvB. Returns True if all pts in tol.
a_params=crvA.DivideByCount(samples,True)
a_pts=[crvA.PointAt(param) for param in a_params]
b_params=[]
for pt in a_pts:
rc,pt=crvB.ClosestPoint(pt)
if not rc: return False
b_params.append(pt)
b_pts=[crvB.PointAt(param) for param in b_params]
for i in range(samples):
if a_pts[i].DistanceTo(b_pts[i])>tol: return False
return True
#planar closed curves
def cp_crv_filt(rhino_object, geometry, component_index):
return rs.IsCurvePlanar(geometry) and rs.IsCurveClosed(geometry)
def BBCtrRad(objID,plane,tol):
in_tol=False
bb=rs.BoundingBox(objID,plane)
if bb:
x=bb[0].DistanceTo(bb[1])
y=bb[1].DistanceTo(bb[2])
if Rhino.RhinoMath.EpsilonEquals(x,y,tol): in_tol=True
return (bb[0]+bb[2])/2,(x+y)/4, in_tol
def SimplifyRecalcitrantCircles():
msg="Select near-circles to simplify"
objIDs=rs.GetObjects(msg,4,preselect=True,custom_filter=cp_crv_filt)
if not objIDs: return
a_tol=sc.doc.ModelAbsoluteTolerance
if "SimRecalCirc_Tol" in sc.sticky: user_tol=sc.sticky["SimRecalCirc_Tol"]
else: user_tol=a_tol
tol=rs.GetReal("Simplify tolerance? Enter 0 to ignore tolerance",user_tol,0)
if tol is None: return
not_circles=[]
rs.EnableRedraw(False)
for objID in objIDs:
if rs.IsCircle(objID):
rs.SimplifyCurve(objID)
else:
not_circles.append(objID)
if len(not_circles)>0:
replaced=0
for objID in not_circles:
plane=rs.CurvePlane(objID)
circ_data=BBCtrRad(objID,plane,tol)
if not circ_data: continue
ctr,rad,in_tol=circ_data
plane.Origin=ctr
new_circle=Rhino.Geometry.Circle(plane,rad)
nc=new_circle.ToNurbsCurve()
rhobj=sc.doc.Objects.Find(objID)
obj=rhobj.Geometry
if tol != 0:
if not in_tol: continue
#refine curve check
#Curve deviation can fail here !!!
# c_dev=Rhino.Geometry.Curve.GetDistancesBetweenCurves(obj,nc,tol)
# if c_dev[0]:
# if c_dev[1]>tol: continue
#args: (crvA,crvB,tol,samples)
if not CurvePointDeviation(obj,nc,tol,32): continue
sc.doc.Objects.Replace(objID,new_circle)
replaced+=1
msg="{} curves simplified to circles.".format(replaced)
left=len(not_circles)-replaced
if left != 0:
msg+=" {} curves unable to be simplified.".format(left)
print msg
sc.sticky["SimRecalCirc_Tol"] = tol
SimplifyRecalcitrantCircles()
print('Success')
###############################################################################
#2nd part of the script
brailleDots = rs.GetObjects(message = "Select Braille dots", filter = 4 , select = True, group = True) #select curves in a form of circles
centerPoints = [] #create an empty variable in a form of list
for curve in brailleDots:
centerPoints.append(rs.CircleCenterPoint(curve)) #for each selected circle, a hypothetical center point is generated (without geometry)
print(centerPoints)
radius = 0.8
sfery = []
for center in centerPoints:
sfery.append(rs.AddSphere(center, radius)) #for each point - 3D geometry - a sphere of defines radius is created
curve = rs.GetObjects("pick curves to create a trimming surface", 4) #Select a curve (closed, planar) that will form a trimming surface for created spheres
surface = rs.AddPlanarSrf(curve) #A trimming surface is being created
rs.FlipSurface(surface, 1) #surface U direction is flipped so that the correct half of sphere is trimmed
for sphere in sfery:
rs.TrimBrep(sphere, surface) #Spheres are trimme so that half domes are created
rs.DeleteObject(surface) #Trimming surface is deleted
print ("Full success")
The look at console when I am not able to pick circles for further step