Yes, that is what it is… I just tried a button with this:
! _-RunPythonScript (
import System
import Rhino
import rhinoscriptsyntax as rs
def Export_Drill():
#Restore Layer state
plugin = rs.GetPlugInObject("Rhino Bonus Tools")
if plugin is not None:
plugin.RestoreLayerState("Wall Notch")
rs.ObjectsByLayer("Drill Alignment", True)
Export_Drill()
)
_-Explode
_-Explode
_-Explode
_-RunPythonScript (
import System
import Rhino
import rhinoscriptsyntax as rs
def Export_Drill():
folder = r'M:\CNC_Data\ Drill\2x4'
name = rs.DocumentName()
name = name.replace('Strut 2x4 ', '')
name = name.replace('Strut 2x6 ', '')
extension = ".igs"
path = System.IO.Path.Combine(folder, name)
path = System.IO.Path.ChangeExtension(path, extension)
print path
script = "_-Export _Pause \"{0}\" _Enter".format(path)
Export_Drill()
)
_-Undo
_-Undo
_-Undo
_-Undo
and the results are in the correct order:
Command: _-RunPythonScript
Python Script <import System (
import System
import Rhino
import rhinoscriptsyntax as rs
def Export_Drill():
#Restore Layer state
plugin = rs.GetPlugInObject("Rhino Bonus Tools")
if plugin is not None:
plugin.RestoreLayerState("Wall Notch")
rs.ObjectsByLayer("Drill Alignment", True)
Export_Drill()
)
Command: _-Explode
Cannot explode single curve segments.
Cannot explode 3 single surfaces.
Exploded an instance into 2 objects.
Command: _-Explode
Cannot explode single curve segments.
Cannot explode 3 single surfaces.
Exploded an instance into 12 objects.
Command: _-Explode
Cannot explode single curve segments.
Cannot explode 3 single surfaces.
Exploded 2 polysurfaces into 25 surfaces.
Exploded an instance into 684 objects.
Exploded 4 annotation objects into 16 curves.
Command: _-RunPythonScript
Python Script <import System (
import System
import Rhino
import rhinoscriptsyntax as rs
def Export_Drill():
folder = r'M:\CNC_Data\Drill\2x4'
name = rs.DocumentName()
name = name.replace('Strut 2x4 ', '')
name = name.replace('Strut 2x6 ', '')
extension = ".igs"
path = System.IO.Path.Combine(folder, name)
path = System.IO.Path.ChangeExtension(path, extension)
print path
script = "_-Export _Pause \"{0}\" _Enter".format(path)
Export_Drill()
)
M:\CNC_Data\Drill\2x4\C1C Upside Down test.igs
Command: _-Undo
Undoing Explode
Command: _-Undo
Undoing Explode
Command: _-Undo
Undoing Explode
Command: _-Undo
Undoing RunPythonScript
Notice I left the actual Rhino.RhinoApp.RunScript(script, True) out… and then the undo’s work…
Rhino.RhinoApp.RunScript(script, True) in the python script is what breaks everything.
If I put Rhino.RhinoApp.RunScript(script, True) to actually run the Export, then I get:
Command: _-RunPythonScript
Python Script <import System (
import System
import Rhino
import rhinoscriptsyntax as rs
def Export_Drill():
#Restore Layer state
plugin = rs.GetPlugInObject("Rhino Bonus Tools")
if plugin is not None:
plugin.RestoreLayerState("Wall Notch")
rs.ObjectsByLayer("Drill Alignment", True)
Export_Drill()
)
Command: _-Explode
Exploded an instance into 2 objects.
Command: _-Explode
Exploded an instance into 12 objects.
Command: _-Explode
Exploded 2 polysurfaces into 25 surfaces.
Exploded an instance into 684 objects.
Exploded 4 annotation objects into 16 curves.
Command: _-RunPythonScript
Python Script <import System (
import System
import Rhino
import rhinoscriptsyntax as rs
def Export_Drill():
folder = r'M:\CNC_Data\Drill\2x4'
name = rs.DocumentName()
name = name.replace('Strut 2x4 ', '')
name = name.replace('Strut 2x6 ', '')
extension = ".igs"
path = System.IO.Path.Combine(folder, name)
path = System.IO.Path.ChangeExtension(path, extension)
print path
script = "_-Export _Pause \"{0}\" _Enter".format(path)
Rhino.RhinoApp.RunScript(script, True)
Export_Drill()
)
M:\CNC_Data\Drill\2x4\C1C Upside Down test.igs
Python Script <import System _-Export
Python Script <import System _Pause
Save file name ( Version=7 SaveSmall=No GeometryOnly=No SaveTextures=Yes SaveNotes=No SavePlugInData=Yes Browse ): "M:\CNC_Data\Drill\2x4\C1C Upside Down test.igs"
IGES Export Type: Default ( ListTypes UnitSystem=Inches StringType=Unicode Tolerance=1e-14 ): _Enter
IGES Export Type: Default ( ListTypes UnitSystem=Inches StringType=Unicode Tolerance=1e-14 )
Saved M:\CNC_Data\Drill\2x4\C1C Upside Down test.igs.
File successfully saved as M:\CNC_Data\Drill\2x4\C1C Upside Down test.igs.
Command: _-Undo <--- these undo's all ran while it was saving the file.. the script wasn't done yet
Nothing to undo.
Command: _-Undo
Nothing to undo.
Command: _-Undo
Nothing to undo.
Command: _-Undo
Nothing to undo.
Command: _-Undo
Nothing to undo.
If I run another undo on my own, it does undo the script.
So… I think that given that
- Export can only be done with Rhino.RhinoApp.RunScript()
- Rhino.RhinoApp.RunScript() causes commands following the script to run too early
It will be impossible to get it to work that way… so that leaves me making copies and deleting the copies… I have got that to work… it’s just that I prefer to undo the entire script automatically because if things get more complicated then it’s more difficult to make sure I don’t delete something I shouldn’t.