Rickson
(Rickson)
December 21, 2019, 3:15pm
1
i’ve tried coercing, making a different list, all sorts of things yet still get this error.
Message: iteration over non-sequence of type Guid
import rhinoscriptsyntax as rs
surface = rs.GetObject("Select Surface",8)
curve = rs.GetObject("Select curve", 4)
#offset = rs.GetReal("Offset Amount")
#offsetX = rs.GetInteger("How many")
offset = 2
offsetX = 3
count = 1
for eachint in range(offsetX):
offing = rs.OffsetCurveOnSurface(curve,surface,(offset * count))
count += 1
curveid = rs.coerceguid(offing)
rs.ExtendCurve(curveid, 0, 2, surface)
print(curveid)
Rickson
(Rickson)
December 21, 2019, 4:18pm
2
ok, i got this to work, but do not understand what the difference is. (this is purely a learning exercise)
import rhinoscriptsyntax as rs
filter = rs.filter.curve | rs.filter.surface | rs.filter.polysurface
objects = rs.GetObjects("Select boundary objects", filter)
if objects:
curves = rs.GetObjects("Select curve to extend", rs.filter.curve)
for curve in curves:
rs.ExtendCurve( curve, 0, 2, objects )
Rickson
(Rickson)
December 21, 2019, 9:55pm
3
in the above script to extend curves the input into rs.ExtendCurve is the guild
in my loop of offset curves its the same, yet throws the error.
Hi,
Is the problem in sending a single surface
rather than a list of objects
? What if you provide [surface]
instead?
Rickson
(Rickson)
December 21, 2019, 10:10pm
5
That did it, So the error wasn’t about the curve the entire time? uff.
Any idea of why? Is has to get a list? The help is plural but doesn’t indicate square brackets.
Well the error message says it was expecting a sequence so putting it inside a list (square brackets) was the easiest way…
If you look at the RhinoCommon code for ExtendCurve() you can see that it has not been written to accept single (bare) objects, only a list - which could contain only one object, but it has to be a list.
boundary_object_ids
is the variable containing boundary objects passed into the method
rhobjs = [rhutil.coercerhinoobject(id) for id in boundary_object_ids]
As this is a list comprehension, if boundary_object_ids
is not a list, it will automatically fail. It would need to be written differently to accept either a single object or a list of objects. Something like
if isinstance(boundary_object_ids,list):
rhobjs = [rhutil.coercerhinoobject(id) for id in boundary_object_ids]
else:
rhobj=rhutil.coercerhinoobject(boundary_object_ids)
if rhobj: rhobjs=[rhobj]
Rickson
(Rickson)
December 22, 2019, 4:23pm
8
Thanks for the additional explanation. I learned a lot through day or so struggle with this problem.
A good example being that this works without the [ ]'s if rs.GetObjects is used vs rs.GetObject(), one returns a list, the other a value.
import rhinoscriptsyntax as rs
import scriptcontext as sc
def offsetCurveOnSurfaceMulti():
#Set value from sticky
offsetX = sc.sticky["offsetX"] if sc.sticky.has_key("offsetX") else 1
offset = sc.sticky["offset"] if sc.sticky.has_key("offset") else 1
#get objects
surface = rs.GetObjects("Select Surface",8)
curve = rs.GetObject("Select curve", 4)
#Get new values
val = rs.GetInteger("Offset Amount", offset)
if val:
offset = val
valX = rs.GetInteger("How many", offsetX)
if valX:
offsetX = valX
# sets sticky to dict
sc.sticky["offset"] = offset
sc.sticky["offsetX"] = offsetX
#loop
count = 1
for eachint in range(offsetX):
offing = rs.OffsetCurveOnSurface(curve,surface,(offset * count))
count += 1
rs.ExtendCurve(offing, 0, 2, surface)
offsetCurveOnSurfaceMulti()