I tried to translate this code:
Flow Object in VB
into Python. But all I get is the ‘namespace#’ error:
“attribute ‘FlowObject’ of ‘namespace#’ object is read-only”.
I am fairly new to Rhino scripting and I didn’t know where to look for the flowobject method in the Rhino script methods.
So now my question: How can I script a Flow Object command in python? How is the “local = Yes” boolean set in this command?
Thanks a lot! Cheers,
FlowObject is not in Python/rhinoscriptsyntax V5, and does not appear to have been implemented yet for V6 either…
Following is an implementation in RhinoCommon that works in V5 or V6.
It is very simple with no error checking or curve end pick detection - flows from one curve to the other using their natural start points and stretch=yes.
import rhinoscriptsyntax as rs import scriptcontext as sc import Rhino def TestFlowMorph(): objID=rs.GetObject("Select object to flow") bcID=rs.GetObject("Pick base curve",4) tcID=rs.GetObject("Pick target curve",4) obj=sc.doc.Objects.Find(objID).Geometry bc=sc.doc.Objects.Find(bcID).Geometry tc=sc.doc.Objects.Find(tcID).Geometry flow=Rhino.Geometry.Morphs.FlowSpaceMorph(bc,tc,False) rc=flow.Morph(obj) if rc: sc.doc.Objects.AddBrep(obj) sc.doc.Views.Redraw() TestFlowMorph()
I will implement your Solution tomorrow!
I tried out your solution on a mesh… Of course your code expects a brep. Is there a posibility to flow with a mesh?
Found out how your code works with a mesh. I still need the Local=Yes option though. Is there a possible way to give this option to the function?
Yes, of course, you can just change the line
and it should work for all geometry objects. That being said…
This morning I have been playing around with “encapsulating” the whole thing into a Python method that will work like the (vb) Rhinoscript. It’s more complicated than I thought, there are a lot of cases to consider - and what looks like a bug I’ve run across. I’ll post the result a little later once I have figured out what’s going on there.
OK, I think I’ve got it here… the little “bug” was a bit hard to track down. It’s amazing how much time you can end up spending on this.
The definition below should behave essentially like the Rhinoscript Rhino.FlowObject() method. Just copy/paste the whole first def part (up to
return IDs) at the top of your script, then you can call it as a method like any other.
It has all the same arguments as Rhino.FlowObject(): the first three - the object(s) and two curves - are required, the others are optional (copy, etc.) and will revert to default values if you do not specify them. You can supply either a single object or list of objects to flow; it returns the same if successful. Should work with (any combination of) points, curves, surfaces, polysurfaces, extrusions, meshes.
If you find bugs (likely), let me know…
FlowObject.py (2.2 KB)
I tested your script. I am still amazed. It works and gives similar results as the Flow command in Rhino directly. One Thing I need anyways: The Local=Yes is not available for this Flow command altough I need it. Is this option somewhere?
I worked my way around now with rs.Command(“Flow”) by selecting the Curves over ID’s. I will upload an example file tomorrow so you know what I am talking about.
Thank you so much!
Unfortunately not, this control does not appear to be exposed in the RhinoCommon SDK for the moment… So I guess your workaround scripting rs.Command("Flow) is about the only way if you need that.
i need to use the definition above but i’m getting the same error :Message: attribute ‘FlowSpaceMorph’ of ‘namespace#’ object is read-only
i’m new to Rhino scripting so i can’t understand what is wrong , any help?
It works here in the Beta version, could it be you are testing on V5?