def execute(self, context):
        ng = context.space_data.node_tree
        gist_filename = ng.name
        gist_description = 'to do later? 2018'
        layout_dict = create_dict_of_tree(ng, skip_set={}, selected=self.selected_only)

        try:
            gist_body = json.dumps(layout_dict, sort_keys=True, indent=2)
        except Exception as err:
            if 'not JSON serializable' in repr(err):
                error(layout_dict)
            else:
                exception(err)
            self.report({'WARNING'}, "See terminal/Command prompt for printout of error")
            return {'CANCELLED'}

        try:
            gist_url = sv_gist_tools.main_upload_function(gist_filename, gist_description, gist_body, show_browser=False)
            
            context.window_manager.clipboard = gist_url   # full destination url
            info(gist_url)
            self.report({'WARNING'}, "Copied gistURL to clipboad")

            sv_gist_tools.write_or_append_datafiles(gist_url, gist_filename)
            return {'FINISHED'}
        except Exception as err:
            info(err)
            self.report({'ERROR'}, "Error 222: net connection or github login failed!")

        return {'CANCELLED'}
Beispiel #2
0
    def execute(self, context):
        if not self.id_tree:
            msg = "Node tree is not specified"
            error(msg)
            self.report({'ERROR'}, msg)
            return {'CANCELLED'}

        if not self.preset_name:
            msg = "Preset name is not specified"
            error(msg)
            self.report({'ERROR'}, msg)
            return {'CANCELLED'}

        ng = bpy.data.node_groups[self.id_tree]

        nodes = list(filter(lambda n: n.select, ng.nodes))
        if not len(nodes):
            msg = "There are no selected nodes to export"
            error(msg)
            self.report({'ERROR'}, msg)
            return {'CANCELLED'}

        layout_dict = create_dict_of_tree(ng, selected=True)
        preset = SvPreset(name=self.preset_name)
        preset.make_add_operator()
        destination_path = preset.path
        write_json(layout_dict, destination_path)
        msg = 'exported to: ' + destination_path
        self.report({"INFO"}, msg)
        info(msg)

        return {'FINISHED'}
Beispiel #3
0
def monad_make_unique(node):

    """
    Create a new version of the monad class (duplicate but unique)

    This will attempt to store the duplicate in a json using create_dict_of_tree (from the Gist IO).
    The upside is that this will test the pack/unpack routine continuously. 
    The downside is that this will likely expose all the shortcommings that we don't know 
    about because it wasn't being tested extensively.
    """

    node_tree = node.id_data
    nodes = node_tree.nodes

    # generate a new copy of monad group node. using ( copy? ) 
    monad_group = bpy.data.node_groups[node.monad.name]
    new_monad_group = monad_group.copy()
    new_cls_name = make_new_classname(new_monad_group) 

    # the new tree dict will contain information about 1 node only, and 
    # the node_group too (at the moment) but the node_group data can be ignored.
    layout_json = create_dict_of_tree(ng=node_tree, identified_node=node)

    # do not restore links this way. wipe this entry and restore at a later stage.
    layout_json['update_lists'] = []

    # massage content of node_items, to correspond with the new desired name.
    node_ref = layout_json['nodes'][node.name]
    node_items = node_ref['params']
    node_items['all_props']['name'] = new_monad_group.name
    node_items['all_props']['cls_bl_idname'] = new_cls_name
    node_items['monad'] = new_monad_group.name
    node_items['cls_dict']['cls_bl_idname'] = new_cls_name

    pre_nodes = set(nodes)

    # place new empty version of the monad node
    import_tree(node_tree, nodes_json=layout_json)

    """
    notions..:
    
        if (original instance has no connections) then 
            replace it outright.
        else
            if mode=='replace':
                store connections
                replace instance with new unique instance
                reconnect old connections
            elif mode=='dupe_translate':
                generate unique instance
                attache node to transform operator.


    """

    # return newly generated node!
    return (set(node_tree.nodes) ^ pre_nodes).pop() 
Beispiel #4
0
def monad_make_unique(node):

    """
    Create a new version of the monad class (duplicate but unique)

    This will attempt to store the duplicate in a json using create_dict_of_tree (from the Gist IO).
    The upside is that this will test the pack/unpack routine continuously. 
    The downside is that this will likely expose all the shortcommings that we don't know 
    about because it wasn't being tested extensively.
    """

    node_tree = node.id_data
    nodes = node_tree.nodes

    # generate a new copy of monad group node. using ( copy? ) 
    monad_group = bpy.data.node_groups[node.monad.name]
    new_monad_group = monad_group.copy()
    new_cls_name = make_new_classname(new_monad_group) 

    # the new tree dict will contain information about 1 node only, and 
    # the node_group too (at the moment) but the node_group data can be ignored.
    layout_json = create_dict_of_tree(ng=node_tree, identified_node=node)

    # do not restore links this way. wipe this entry and restore at a later stage.
    layout_json['update_lists'] = []

    # massage content of node_items, to correspond with the new desired name.
    node_ref = layout_json['nodes'][node.name]
    node_items = node_ref['params']
    node_items['all_props']['name'] = new_monad_group.name
    node_items['all_props']['cls_bl_idname'] = new_cls_name
    node_items['monad'] = new_monad_group.name
    node_items['cls_dict']['cls_bl_idname'] = new_cls_name

    pre_nodes = set(nodes)

    # place new empty version of the monad node
    import_tree(node_tree, nodes_json=layout_json)

    """
    notions..:
    
        if (original instance has no connections) then 
            replace it outright.
        else
            if mode=='replace':
                store connections
                replace instance with new unique instance
                reconnect old connections
            elif mode=='dupe_translate':
                generate unique instance
                attache node to transform operator.


    """

    # return newly generated node!
    return (set(node_tree.nodes) ^ pre_nodes).pop() 
    def test_box_export(self):
        node = create_node("SvBoxNode", self.tree.name)
        node.Divx = 1
        node.Divy = 3
        node.Divz = 4
        node.Size = 1.0299999713897705

        export_result = create_dict_of_tree(self.tree)

        self.assert_json_equals_file(export_result, "box.json")
Beispiel #6
0
    def test_profile_export(self):

        try:
            upgrade_nodes.upgrade_nodes(self.tree)
        except:
            traceback.print_exc()

        export_result = create_dict_of_tree(self.tree)
        # self.store_reference_json("profile.json", export_result)
        self.assert_json_equals_file(export_result, "profile.json")
Beispiel #7
0
    def test_box_export(self):
        node = create_node("SvBoxNodeMk2", self.tree.name)
        node.Divx = 1
        node.Divy = 3
        node.Divz = 4
        node.Size = 1.0299999713897705

        export_result = create_dict_of_tree(self.tree)

        self.assert_json_equals_file(export_result, "box.json")
    def test_cylinder_export(self):
        node = create_node("CylinderNode", self.tree.name)
        node.Separate = 1
        node.cap_ = 0
        node.radTop_ = 1.0299999713897705
        node.radBot_ = 1.0299999713897705
        node.vert_ = 33
        node.height_ = 2.0299999713897705
        node.subd_ = 1

        export_result = create_dict_of_tree(self.tree)

        self.assert_json_equals_file(export_result, "cylinder.json")
Beispiel #9
0
    def execute(self, context):
        ng = context.space_data.node_tree
        gist_filename = ng.name

        app_version = bpy.app.version_string.replace(" ", "")
        time_stamp = strftime("%Y.%m.%d | %H:%M", localtime())
        gist_description = f"Sverchok.{version_and_sha} | Blender.{app_version} | {ng.name} | {time_stamp}"

        layout_dict = create_dict_of_tree(ng,
                                          skip_set={},
                                          selected=self.selected_only)

        try:
            gist_body = json.dumps(layout_dict, sort_keys=True, indent=2)
        except Exception as err:
            if 'not JSON serializable' in repr(err):
                error(layout_dict)
            exception(err)
            self.report({'WARNING'},
                        "See terminal/Command prompt for printout of error")
            return {'CANCELLED'}

        try:
            gist_url = sv_gist_tools.main_upload_function(gist_filename,
                                                          gist_description,
                                                          gist_body,
                                                          show_browser=False)
            if not gist_url:
                self.report(
                    {'ERROR'},
                    "You have not specified GitHub API access token, which is "
                    + "required to create gists from Sverchok. Please see " +
                    TOKEN_HELP_URL + " for more information.")
                return {'CANCELLED'}

            context.window_manager.clipboard = gist_url  # full destination url
            info(gist_url)
            self.report({'WARNING'}, "Copied gist URL to clipboad")

            sv_gist_tools.write_or_append_datafiles(gist_url, gist_filename)
            return {'FINISHED'}
        except Exception as err:
            exception(err)
            self.report({'ERROR'},
                        "Error 222: net connection or github login failed!")

        return {'CANCELLED'}
    def test_torus_export(self):
        node = create_node("SvTorusNode", self.tree.name)
        node.mode = "MAJOR_MINOR"
        node.Separate = 0
        node.torus_eR = 1.2799999713897705
        node.torus_R = 1.0299999713897705
        node.torus_r = 0.25
        node.torus_iR = 0.7799999713897705
        node.torus_n1 = 33
        node.torus_n2 = 17
        node.torus_rP = 0.029999999329447746
        node.torus_sP = 0.029999999329447746
        node.torus_sT = 1

        export_result = create_dict_of_tree(self.tree)

        self.assert_json_equals_file(export_result, "torus.json")
Beispiel #11
0
    def test_torus_export(self):
        node = create_node("SvTorusNodeMK2", self.tree.name)
        node.mode = "MAJOR_MINOR"
        node.Separate = 0
        node.torus_eR = 1.2799999713897705
        node.torus_R = 1.0299999713897705
        node.torus_r = 0.25
        node.torus_iR = 0.7799999713897705
        node.torus_n1 = 33
        node.torus_n2 = 17
        node.torus_rP = 0.029999999329447746
        node.torus_sP = 0.029999999329447746
        node.torus_sT = 1

        export_result = create_dict_of_tree(self.tree)

        self.assert_json_equals_file(export_result, "torus.json")
Beispiel #12
0
    def test_cylinder_export(self):
        node = create_node("SvCylinderNodeMK2", self.tree.name)
        node.separate = False
        node.cap_bottom = 1
        node.cap_top = 1
        node.center = 0
        node.angle_units = 'RAD'
        node.radius_t = 1.0299999713897705
        node.radius_b = 1.0299999713897705
        node.parallels = 2
        node.meridians = 33
        node.height = 2.0299999713897705
        node.twist = 1.0299999713897705
        node.phase = 1.0299999713897705
        node.scale = 1.0299999713897705

        export_result = create_dict_of_tree(self.tree)

        self.assert_json_equals_file(export_result, "cylinder.json")
Beispiel #13
0
    def execute(self, context):
        ng = bpy.data.node_groups[self.id_tree]

        destination_path = self.filepath
        if not destination_path.lower().endswith('.json'):
            destination_path += '.json'

        # future: should check if filepath is a folder or ends in \

        layout_dict = create_dict_of_tree(ng)
        if not layout_dict:
            msg = 'no update list found - didn\'t export'
            self.report({"WARNING"}, msg)
            warning(msg)
            return {'CANCELLED'}

        write_json(layout_dict, destination_path)
        msg = 'exported to: ' + destination_path
        self.report({"INFO"}, msg)
        info(msg)

        if self.compress:
            comp_mode = zipfile.ZIP_DEFLATED

            # destination path = /a../b../c../somename.json
            base = basename(destination_path)  # somename.json
            basedir = dirname(destination_path)  # /a../b../c../

            # somename.zip
            final_archivename = base.replace('.json', '') + '.zip'

            # /a../b../c../somename.zip
            fullpath = os.path.join(basedir, final_archivename)

            with zipfile.ZipFile(fullpath, 'w',
                                 compression=comp_mode) as myzip:
                myzip.write(destination_path, arcname=base)
                info('wrote:', final_archivename)

        return {'FINISHED'}
    def execute(self, context):
        ng = bpy.data.node_groups[self.id_tree]

        destination_path = self.filepath
        if not destination_path.lower().endswith('.json'):
            destination_path += '.json'

        # future: should check if filepath is a folder or ends in \

        layout_dict = create_dict_of_tree(ng)
        if not layout_dict:
            msg = 'no update list found - didn\'t export'
            self.report({"WARNING"}, msg)
            warning(msg)
            return {'CANCELLED'}

        write_json(layout_dict, destination_path)
        msg = 'exported to: ' + destination_path
        self.report({"INFO"}, msg)
        info(msg)

        if self.compress:
            comp_mode = zipfile.ZIP_DEFLATED

            # destination path = /a../b../c../somename.json
            base = basename(destination_path)  # somename.json
            basedir = dirname(destination_path)  # /a../b../c../

            # somename.zip
            final_archivename = base.replace('.json', '') + '.zip'

            # /a../b../c../somename.zip
            fullpath = os.path.join(basedir, final_archivename)

            with zipfile.ZipFile(fullpath, 'w', compression=comp_mode) as myzip:
                myzip.write(destination_path, arcname=base)
                info('wrote:', final_archivename)

        return {'FINISHED'}
 def test_textview_expr_export(self):
     export_result = create_dict_of_tree(self.tree)
     self.assert_json_equals_file(export_result, "viewer_text.blend.json")
 def test_monad_export(self):
     export_result = create_dict_of_tree(self.tree)
     #self.store_reference_json("monad_e.json", export_result)
     self.assert_json_equals_file(export_result, "monad_1.json")
 def test_mesh_expr_export(self):
     export_result = create_dict_of_tree(self.tree)
     self.assert_json_equals_file(export_result, "mesh.json")
 def test_script_uv_export(self):
     export_result = create_dict_of_tree(self.tree)
     self.assert_json_equals_file(export_result, "script_uv.json")
Beispiel #19
0
 def test_mesh_expr_export(self):
     export_result = create_dict_of_tree(self.tree)
     self.assert_json_equals_file(export_result, "mesh.json")
Beispiel #20
0
 def test_monad_export(self):
     export_result = create_dict_of_tree(self.tree)
     #self.store_reference_json("monad_e.json", export_result)
     self.assert_json_equals_file(export_result, "monad_1.json")
Beispiel #21
0
 def test_textview_expr_export(self):
     export_result = create_dict_of_tree(self.tree)
     self.assert_json_equals_file(export_result, "viewer_text.blend.json")
 def test_textview_expr_export(self):
     export_result = create_dict_of_tree(self.tree)
     #self.store_reference_json("viewer_text.blend.json", export_result)
     self.assert_json_equals_file(export_result, "viewer_text.blend.json")
Beispiel #23
0
 def test_script_uv_export(self):
     export_result = create_dict_of_tree(self.tree)
     self.assert_json_equals_file(export_result, "script_uv.json")