Esempio n. 1
0
def save_current_scene(force=True, **kwargs):
    """
    Saves current scene
    :param force: bool
    """

    path_to_save = kwargs.get('path_to_save', None)
    name_to_save = kwargs.get('name_to_save', None)
    extension_to_save = kwargs.get('extension_to_save', get_extensions()[0])

    current_scene_name = rt.maxFileName
    if not extension_to_save.startswith('.'):
        extension_to_save = '.{}'.format(extension_to_save)
    name_to_save = name_to_save or current_scene_name
    if not name_to_save:
        return

    file_to_save = path_utils.join_path(path_to_save, name_to_save)
    if not file_to_save.endswith(extension_to_save):
        file_to_save = '{}{}'.format(file_to_save, extension_to_save)

    if force:
        return rt.saveMaxFile(file_to_save, quiet=True)
    else:
        file_check_state = rt.getSaveRequired()
        if not file_check_state:
            return rt.saveMaxFile(file_to_save)
        if rt.checkForSave():
            return rt.saveMaxFile(file_to_save)
Esempio n. 2
0
def main():
    """Demonstrate callback registration."""
    # List all callback names that we know
    list_codes()
    # Register all callback names
    register_all_callbacks()

    # Do some things
    print("Creating sphere")
    sphere1 = rt.sphere()
    print("Setting radius for sphere 1")
    sphere1.radius = 2.0
    print("Creating sphere 2")
    sphere2 = rt.sphere()
    print("Setting radius on sphere 2")
    sphere2.radius = 2.0
    print("Setting parent of node 2 to node 1")
    sphere2.Parent = sphere1

    print("Saving file")
    output_path = os.path.join(rt.sysInfo.tempdir, 'temp.max')
    rt.saveMaxFile(output_path)
    print("Opening file")
    rt.loadMaxFile(output_path)

    print('unregistering notification handlers')
    unregister_all_callbacks()
Esempio n. 3
0
 def applyLayerSelectionToPreset(self, preset, layerNames):
     r = qtUtils.popup_Yes_No(title="Apply Unsaved Changes ?",text="You need to save the scene to apply")
     baseFile = rt.maxFilePath + rt.maxFileName
     if r:
         preset.edit(layerNames=layerNames)
         self.btnApplyPresetLayer.setText("Apply")
         self.treeLayer.isEdited = False
         if baseFile != None:
             s = rt.saveMaxFile(baseFile)
             if s == False:
                 rt.messageBox("Save failed, choose another path, or checkout your file.")
                 f = rt.getSaveFileName(caption="Save as", filename=baseFile)
                 while f == None:
                     f = rt.getSaveFileName(caption="Save as", filename=baseFile)
                 rt.saveMaxFile(f) if f != None else rt.messageBox("Save failed")                      
             else:
                 print("successfully saved the scene ")
         else:
             while f == None:
                 f = rt.getSaveFileName(caption="Save as", filename=baseFile)
             rt.saveMaxFile(f) if f != None else rt.messageBox("Save failed")
Esempio n. 4
0
def save(file_path=None):
    """
    Saves current scene in current Max file
    :return: bool, Whether the scene was saved or not
    """

    file_path = file_path or ''
    file_check_state = rt.getSaveRequired()
    if file_check_state:
        msg_box = QMessageBox()
        msg_box.setText('The 3ds Max scene has been modified')
        msg_box.setInformativeText('Do you want to save your changes?')
        msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
        msg_box.setDefaultButton(QMessageBox.Yes)
        res = msg_box.exec_()
        if res == QMessageBox.Yes:
            file_path = file_path or directory.save_file_dialog('Save File', filters='*.max')
            if not file_path:
                return
            rt.saveMaxFile(file_path)
            return True

    return False
def create_scene():
    """Create and save scene_with_app_chunk.max"""
    rt.resetMaxFile(rt.Name('noPrompt'))

    # Create a teapot, a scene node and a material instance, they are all
    # objects of Animatable
    node = rt.teapot()
    teapot = node.baseObject
    mtl = rt.StandardMaterial()
    node.Material = mtl
    node.name = "MyTeapot123"

    # Now add some user specified strings to these objects
    rt.setAppdata(teapot, 112, "blah comit")
    rt.setAppdata(teapot, 1234, "I'm a teapot!")
    rt.setAppdata(teapot, 2345, u"我是一个茶壶!")

    rt.setAppdata(node, 5678, "Node of teapot")
    rt.setAppdata(node, 7890, "This is to be removed")
    rt.deleteAppdata(node, 7890)

    rt.setAppdata(mtl, 4567, "Material of teapot")
    rt.saveMaxFile("scene_with_app_chunk.max")
    print("scene with AppChunk is saved.")
    def test_publish_scene(self):
        """
        Try to publish a sphere.
        """
        # Create a publishable scene
        sphere = rt.Sphere()
        rt.saveMaxFile(os.path.join(self.current_max_project, "scene.max"))

        self._create_preview("rendering.mp4")
        self._create_export("scene.abc")

        # Collect the scene.
        self.manager.collect_session()
        self.manager.tree.pprint()

        # Ensure all items are present
        items = list(self.manager.tree)
        assert len(items) == 4

        items[0].name == "scene.max"
        items[0].type_display == "3dsmax Session"
        assert [task.name for task in items[0].tasks] == [
            "Begin file versioning",
            "Publish to ShotGrid",
        ]

        items[1].name == "rendering.mp4"
        items[1].type_display == "preview"
        assert [task.name for task in items[1].tasks] == [
            "Publish to ShotGrid",
            "Upload for review",
        ]

        items[2].name == "scene.abc"
        items[2].type_display == "Alembic Cache"
        assert [task.name
                for task in items[2].tasks] == ["Publish to ShotGrid"]

        items[3].name == "All Session Geometry"
        items[3].type_display == "Geometry"

        assert list(items[3].tasks) == []

        self.manager.validate()

        # Publish the scene
        self.manager.publish()

        # Mockgun does not set this property, so set it!
        publish_id = items[0].properties.sg_publish_data["id"]
        self.mockgun._db["PublishedFile"][publish_id]["path"][
            "link_type"] = "local"

        publish_id = items[1].properties.sg_publish_data["id"]
        self.mockgun._db["PublishedFile"][publish_id]["path"][
            "link_type"] = "local"

        publish_id = items[2].properties.sg_publish_data["id"]
        self.mockgun._db["PublishedFile"][publish_id]["path"][
            "link_type"] = "local"

        self.manager.finalize()
"""
    Demonstrate saving a 3ds Max file.
"""
from os import path
from pymxs import runtime as rt # pylint: disable=import-error

FILEPATH = path.join(rt.sysInfo.tempdir, "test.max")
rt.saveMaxFile(FILEPATH)
print(f"Requested filename {FILEPATH}\n path {rt.maxFilePath}\n file {rt.maxFileName}")
Esempio n. 8
0
def save_current_scene_to_temp_filename(config):
	# save the current scene to a temp file
	rt.saveMaxFile(config["temp_folder"]+config["temp_dcc_filename"],clearNeedSaveFlag=False,useNewFile=False,quiet=True)