Ejemplo n.º 1
0
        def process(self):
            if not self.outputs['Compound'].is_linked:
                return
            if not any(sock.is_linked for sock in self.inputs):
                return

            solids_s = self.inputs['Solids'].sv_get(default=[[None]])
            curves_s = self.inputs['Curves'].sv_get(default=[[None]])
            surfaces_s = self.inputs['Surfaces'].sv_get(default=[[None]])

            if self.inputs['Solids'].is_linked:
                solids_s = ensure_nesting_level(solids_s,
                                                2,
                                                data_types=(Part.Shape, ))
                solids_level = get_data_nesting_level(
                    solids_s, data_types=(Part.Shape, ))
            else:
                solids_level = 2
            if self.inputs['Curves'].is_linked:
                curves_s = ensure_nesting_level(curves_s,
                                                2,
                                                data_types=(SvCurve, ))
                curves_level = get_data_nesting_level(curves_s,
                                                      data_types=(SvCurve, ))
            else:
                curves_level = 2
            if self.inputs['Surfaces'].is_linked:
                surfaces_s = ensure_nesting_level(surfaces_s,
                                                  2,
                                                  data_types=(SvSurface, ))
                surfaces_level = get_data_nesting_level(
                    surfaces_s, data_types=(SvSurface, ))
            else:
                surfaces_level = 2

            max_level = max(solids_level, curves_level, surfaces_level)
            compounds_out = []
            for solids, curves, surfaces in zip_long_repeat(
                    solids_s, curves_s, surfaces_s):
                shapes = solids + curves + surfaces
                shapes = [to_solid(s) for s in shapes if s is not None]
                compound = Part.Compound(shapes)
                compounds_out.append(compound)

            self.outputs['Compound'].sv_set(compounds_out)
Ejemplo n.º 2
0
        def execute(self, context):
            node = self.get_node(context)
            if not node: return {'CANCELLED'}

            if not node.inputs['Folder Path'].is_linked:
                self.report({'WARNING'}, "Folder path is not specified")
                return {'FINISHED'}
            if not node.inputs['Solids'].is_linked:
                self.report({'WARNING'},
                            "Object to be exported is not specified")
                return {'FINISHED'}

            folder_path = node.inputs[0].sv_get()[0][0]
            objects = node.inputs['Solids'].sv_get()
            #objects = flatten_data(objects, data_types=(Part.Shape, SvCurve, SvSurface))
            base_name = node.base_name
            if not base_name:
                base_name = "sv_solid"
            for i, shape in enumerate(objects):
                #shape = map_recursive(to_solid, object, data_types=(Part.Shape, SvCurve, SvSurface))
                debug("Exporting", shape)
                if isinstance(shape, (list, tuple)):
                    shape = flatten_data(shape, data_types=(Part.Shape, ))
                if isinstance(shape, (list, tuple)):
                    debug("Make compound:", shape)
                    shape = Part.Compound(shape)
                file_path = folder_path + base_name + "_" + "%05d" % i

                if node.mode == "BREP":
                    file_path += ".brp"
                    shape.exportBrep(file_path)
                elif node.mode == "IGES":
                    file_path += ".igs"
                    shape.exportIges(file_path)
                else:
                    file_path += ".stp"
                    shape.exportStep(file_path)
                self.report({'INFO'}, f"Saved object #{i} to {file_path}")

            return {'FINISHED'}