Question: how to cancell the default save message dialog

Hi, I wrote a script about generating the Sphere model and saved_as Rhino5. When I closed Rhino , the default save message dialog " Save changes to untitled?" came up . How to ban this dialog in python? Also I don’t want save another extra file in Rhino6 or Rhino7 and any interaction.

str_parameters_file = 'sphere.json'
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
import sys
import json

# Create Sphere
def CreatesphereSurface(center, radius):
    center = Rhino.Geometry.Point3d(center[0], center[1], center[2])
    sphere = Rhino.Geometry.Sphere(center, radius)
    sphere_brep = sphere.ToNurbsSurface()
    return sphere_brep

def AddSphere(str_path):
     """
    *str_path*      (str)str_parameters_file='sphere.json'
    **return**
    *Rhino.Commands.Result.Success*   
    'Center':   (list) ,
    'Radius':   (float) ,
    *"SavePath" (str) "Sphere.3dm"*
    """
    dict_para = None
    try:
        with open(str_path, 'r') as load_file:
            dict_para = json.load(load_file)
    except:
        print("no nonfigure file Or file is not completed")

    if dict_para is None:
        dict_para = {
            'Center': [0, 0, 0],
            'Radius': 10,
            'SavePath': 'sphere.3dm', }
        fp = open(str_path, 'w')
        json.dump(dict_para, fp, ensure_ascii=False)
        fp.close()

    if 'Center' in dict_para:
        Center = dict_para['Center']
    if 'Radius' in dict_para:
        Radius = dict_para['Radius']

    sphere_brep = CreatesphereSurface(Center, Radius)

    str_save_path = ' '  # 3dm saving path
    if 'SavePath' in dict_para:
        str_save_path = dict_para['SavePath']
        if str_save_path:
            #
            str_save_command = '_-SaveAs _Version=5 _SaveSmall=_YES _SavePluginData=_No "%s" _Enter' % (str_save_path)
            rs.Command(str_save_command)
    return Rhino.Commands.Result.Success

if __name__ == "__main__":
    scriptcontext.doc.Objects.Clear()
    AddSphere(str_parameters_file)

# sphere.json
{"Radius": 10, "SavePath": "sphere.3dm", "Center": [0, 0, 0], "TargetCenter": [5, 5, 5]}

take a look at this simplified version and see if it helps

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

doc = scriptcontext.doc

def CreatesphereSurface(center, radius):
    center = Rhino.Geometry.Point3d(center[0], center[1], center[2])
    sphere = Rhino.Geometry.Sphere(center, radius)
    sphere_brep = sphere.ToNurbsSurface()
    return sphere_brep

def AddSphere():
    
    sphere_brep = CreatesphereSurface([0, 0, 0], 100)
    obj_id = doc.Objects.Add(sphere_brep)
    
    rs.Command('-_SaveAs _Version=5 _SaveSmall=_YES _SavePluginData=_No "sphere.3dm" _Enter')
    
    doc.Objects.Remove(doc.Objects.FindId(obj_id))
    doc.Modified = False
        
    return Rhino.Commands.Result.Success

if __name__ == "__main__":
    doc.Objects.Clear()
    AddSphere()
1 Like

Thanks! A very clever idea. I only thought of some commands to forbid the prompt directly. You Just delete what i don’t need and change the state of the doc. :+1: