I need to add the Curve Piping Render Property to a series of curves (in Python). I have searched the RhinoCommon API docs, examples, and here on the forum without any success. Perhaps the render attribute version it’s not called “piping” under the hood. (Just to clarify, I am not looking for rhinoscriptsyntax.AddPipe())
Can any developers or users with experience in this area point me in the right direction?
I am looking for the call to add render time Curve Piping. It’s an attribute/property that is added to the curve object. In the rhino GUI, it’s exposed under the “Properties” panel, “Curve Piping” tab.
I’m not sure if it’s even possible to control these properties from Python but you can create meshes and use display conduit to display your curves as pipe:
from scriptcontext import doc
import System
import Rhino
class DrawMeshConduit(Rhino.Display.DisplayConduit):
def __init__(self, mesh):
self.mesh = mesh
self.color = System.Drawing.Color.White
self.material = Rhino.Display.DisplayMaterial()
self.material.Diffuse = self.color
if mesh != None and mesh.IsValid:
self.bbox = mesh.GetBoundingBox(True)
def CalculateBoundingBox(self, calculateBoundingBoxEventArgs):
calculateBoundingBoxEventArgs.BoundingBox.Union(self.bbox)
def PreDrawObjects(self, drawEventArgs):
gvp = drawEventArgs.Display.Viewport
if gvp.DisplayMode.EnglishName.ToLower() == "wireframe":
return
else:
drawEventArgs.Display.DrawMeshShaded(self.mesh, self.material)
circle = Rhino.Geometry.Circle(20)
m = Rhino.Geometry.Mesh.CreateFromCurvePipe(circle.ToNurbsCurve(), 0.5, 20, 50, Rhino.Geometry.MeshPipeCapStyle.None, False)
conduit = DrawMeshConduit(m)
conduit.Enabled = True
doc.Views.Redraw()
I’ve just found out that we can check whether CurvePiping is activated or not for a curve object by checking RhinoObject.Description. And also fount out how we can get the pipingmesh and add it to document. The CurvePiping option seems to store as UserData so Obviously, we can add another curve object with the same attributes and if we purge the UserData from a curve object, the CurvePiping option would be deactivated:
import Rhino
import rhinoscriptsyntax as rs
from scriptcontext import doc
id = rs.GetCurveObject("Select a curve with curve-piping")[0]
obj = doc.ActiveDoc.Objects.FindId(id)
#description
log = Rhino.FileIO.TextLog()
obj.Description(log)
print log
#add piping mesh to document
renders = obj.GetRenderPrimitiveList(Rhino.DocObjects.ViewportInfo(doc.ActiveDoc.Views.ActiveView.ActiveViewport), None)
if renders is not None:
doc.Objects.AddMesh(renders.Mesh(0))
#add a circle with same attributes
circle = Rhino.Geometry.Circle(20)
doc.Objects.AddCircle(circle, obj.Attributes)
#remove curve-piping
obj.Attributes.UserData.Purge()
obj.CommitChanges()
I found out this could be easily done with macros BUT it is not possible to exit block edit mode with macro?! is there anyway i can edit blocks and run applycurvepiping command automatically? from macro, pythton or c# i dont mind. i need to know if its possible. @pascal
This is the best we can get. Beware there is a bug in captype propery you need to set _SPACE Flat otherwise it does not work so there is unneccessary space in that property.
I’m trying to add more options to you script and most of them are working, with the exception of the CapType. It seems that by default curves are assigned to have a ‘dome’ cap and this isn’t be overwritten by this script. @ivan.galik noted this above.