@tom.norris23 wrote:
Hi all,
Using Rhino 5:
I have a script which works fine in the editor as a script but as soon I run it as a command it stops behaving as expected. The result of the script is the same but the ability to escape and the updating of the command prompt does not work. I think it is to do with the while loop being too tight and the Rhino.rhinoapp.wait command not “waiting” enough? Any Ideas?
import rhinoscriptsyntax as rs import scriptcontext import Rhino __commandname__ = "ExplodeMesh" def makeNewMesh(mesh): print "Starting to Split Mesh" rs.EnableRedraw(False) faces = rs.MeshFaces(mesh,True) i = 0 bEsc = False total = len(faces) while i <= total-1: Rhino.RhinoApp.Wait() if scriptcontext.escape_test(False): print "ESC Pressed Objects Locked" bEsc = True break percent = int((i/total)*100) Rhino.RhinoApp.SetCommandPrompt("Exploded: " + str(percent) + "%") a = faces[i] b = faces[i+1] c = faces[i+2] d = faces[i+3] if c[0]==d[0] and c[1]==d[1] and c[2]==d[2]: rs.AddMesh([a,b,c,d], [[0,1,2,2]]) else: rs.AddMesh([a,b,c,d], [[0,1,2,3]]) i = i + 4 if bEsc == False: Rhino.RhinoApp.SetCommandPrompt("Exploded: 100%") print "Split Mesh into " + str(int(total/4)) rs.DeleteObject(mesh) else: rs.LockObject(mesh) rs.EnableRedraw(True) return 0 def RunCommand( is_interactive ): mesh = rs.GetObject("Select Mesh to explode",32,True,True) if mesh == None: return None current = rs.CurrentLayer() meshLayer = rs.ObjectLayer(mesh) rs.CurrentLayer(meshLayer) ex = Rhino.Input.Custom.GetObject makeNewMesh(mesh) rs.CurrentLayer(current) return 0
Posts: 2
Participants: 1