I’d like to ask you for comment.
Here is a small script that I wrote in python which allows to run the “Section” Rhino Command and create hatches automatically with the newly created curves. The aim is to create hatches on the same layer as every original closed curve created with the Section command.
When running the Section command, I have to choose options to assign curves to original layer and to join curves corresponding to original polysurfaces.
What advice would you give me to improve and optimize that following script ?
Thanks for your comments
#!/usr/bin/python# -- coding: utf-8 --
import rhinoscriptsyntax as rs import scriptcontext as sc import Rhino as rh
def HatchCurves(curveList): hatchName = "Hachures1" hatchNames = rs.HatchPatternNames() if hatchName not in hatchNames: print "Create a " + hatchName + " hatch when using this script for the first time." return False
createdHatches =  for curve in curveList: if rs.IsCurveClosed(curve): curveLayer = rs.ObjectLayer(curve) curveHatch = rs.AddHatch(curve, hatchName, 150, 45) createdHatches.append(curveHatch) if curveHatch : rs.ObjectLayer(curveHatch, curveLayer) else: print "At least one curve was not closed" return createdHatches
if __name__=="__main__": rc = rs.Command("Section")
if rc: rs.Command("_SelLast") newCurves = rs.SelectedObjects()
curveToHatch =  for curve in newCurves: if rs.IsCurveClosed(curve): curveToHatch.append(curve)
if curveToHatch: hatchList = HatchCurves(curveToHatch)
objectsToSelect= objectsToSelect.extend(curveToHatch) objectsToSelect.extend(hatchList)
rs.SelectObjects(objectsToSelect) else: print "No closed curve to create hatches"