def generate_output_file(ai_figure, ai_output_filename, ai_height, ai_info_txt=""):
    """ implement the swith --output_file_basename for 2D figure
  """
    if ai_output_filename != "":
        # create the output directory if needed
        l_output_dir = os.path.dirname(ai_output_filename)
        design_help.mkdir_p(l_output_dir)
        # l_output_basename = os.path.basename(ai_output_filename)
        # print("dbg449: l_output_basename:", l_output_basename)
        # mozman dxfwrite
        if re.search("\.dxf$", ai_output_filename):
            # print("Generate {:s} with mozman dxfwrite".format(ai_output_filename))
            outline_backends.write_figure_in_dxf(ai_figure, ai_output_filename)
        # mozman svgwrite
        elif re.search("\.svg$", ai_output_filename):
            # print("Generate {:s} with mozman svgwrite".format(ai_output_filename))
            outline_backends.write_figure_in_svg(ai_figure, ai_output_filename)
        # FreeCAD
        elif re.search("\.brep$", ai_output_filename):
            print("Generate with FreeCAD the BRep file {:s}".format(ai_output_filename))
            freecad_part = outline_backends.figure_to_freecad_25d_part(ai_figure, ai_height)
            freecad_part.exportBrep("{:s}".format(ai_output_filename))
            print("Generate with FreeCAD the DXF file {:s}.dxf".format(ai_output_filename))
            # slice freecad_part  in the XY plan at a height of ai_height/2
            export_2d.export_to_dxf(
                freecad_part, Base.Vector(0, 0, 1), ai_height / 2, "{:s}.dxf".format(ai_output_filename)
            )
        elif re.search("\.stl$", ai_output_filename):
            print("Generate with FreeCAD the STL file {:s}".format(ai_output_filename))
            freecad_part = outline_backends.figure_to_freecad_25d_part(ai_figure, ai_height)
            freecad_part.exportStl("{:s}".format(ai_output_filename))
            print("Generate with FreeCAD the DXF file {:s}.dxf".format(ai_output_filename))
            # slice freecad_part  in the XY plan at a height of ai_height/2
            export_2d.export_to_dxf(
                freecad_part, Base.Vector(0, 0, 1), ai_height / 2, "{:s}.dxf".format(ai_output_filename)
            )
        else:
            print(
                "ERR124: Error: the suffix of the filename {:s} is unknown. Try with suffix: .dxf, .svg, .brep or .stl".format(
                    ai_output_filename
                )
            )
            sys.exit(2)
        # info_txt
        # if(ai_info_txt!=''):
        #  output_basename = re.sub('(\.dxf$)|(\.svg$)', '', ai_output_filename)
        #  info_txt_filename = "{:s}.txt".format(output_basename)
        #  print("Generate the text info file {:s}".format(info_txt_filename))
        #  ofh = open(info_txt_filename, 'w')
        #  ofh.write("{:s} generated by Cnc25D on {:s}\n\n".format(info_txt_filename, datetime.now().isoformat()))
        #  ofh.write(ai_info_txt)
        #  ofh.close()
    # return
    return 0
示例#2
0
def figures_to_freecad_assembly(ai_figure_assembly):
    """ Extrude figures and place them from a list of figures and 3D positioning instructions
  """
    obj_nb = len(ai_figure_assembly)
    if (obj_nb < 1):
        print("ERR235: the freecad assembly must contain at least one figure")
        sys.exit(2)
    fc_obj = []
    for i in range(obj_nb):
        if (len(ai_figure_assembly[i]) != 11):
            print("ERR219: Error len of ai_figure_assembly {:d} must be 11".
                  format(len(ai_figure_assembly[i])))
            sys.exit(2)
        (part_figure, zero_x, zero_y, size_x, size_y, size_z, flip,
         orientation, translate_x, translate_y,
         translate_z) = ai_figure_assembly[i]
        part_figure_zero = rotate_and_translate_figure(part_figure, 0, 0, 0,
                                                       -1 * zero_x,
                                                       -1 * zero_y)
        part_extruded = outline_backends.figure_to_freecad_25d_part(
            part_figure_zero, size_z)
        part_placed = positioning.place_plank(part_extruded, size_x, size_y,
                                              size_z, flip, orientation,
                                              translate_x, translate_y,
                                              translate_z)
        fc_obj.append(part_placed.copy())
    #r_assembly = Part.makeCompound(fc_obj) # common face are not fused with makeCompound
    r_assembly = fc_obj[0]
    for i in range(obj_nb - 1):
        r_assembly = r_assembly.fuse(fc_obj[i + 1])
    return (r_assembly)
def figures_to_freecad_assembly(ai_figure_assembly):
    """ Extrude figures and place them from a list of figures and 3D positioning instructions
  """
    obj_nb = len(ai_figure_assembly)
    if obj_nb < 1:
        print("ERR235: the freecad assembly must contain at least one figure")
        sys.exit(2)
    fc_obj = []
    for i in range(obj_nb):
        if len(ai_figure_assembly[i]) != 11:
            print("ERR219: Error len of ai_figure_assembly {:d} must be 11".format(len(ai_figure_assembly[i])))
            sys.exit(2)
        (
            part_figure,
            zero_x,
            zero_y,
            size_x,
            size_y,
            size_z,
            flip,
            orientation,
            translate_x,
            translate_y,
            translate_z,
        ) = ai_figure_assembly[i]
        part_figure_zero = rotate_and_translate_figure(part_figure, 0, 0, 0, -1 * zero_x, -1 * zero_y)
        part_extruded = outline_backends.figure_to_freecad_25d_part(part_figure_zero, size_z)
        part_placed = positioning.place_plank(
            part_extruded, size_x, size_y, size_z, flip, orientation, translate_x, translate_y, translate_z
        )
        fc_obj.append(part_placed.copy())
    # r_assembly = Part.makeCompound(fc_obj) # common face are not fused with makeCompound
    r_assembly = fc_obj[0]
    for i in range(obj_nb - 1):
        r_assembly = r_assembly.fuse(fc_obj[i + 1])
    return r_assembly
示例#4
0
def generate_output_file(ai_figure,
                         ai_output_filename,
                         ai_height,
                         ai_info_txt=''):
    """ implement the swith --output_file_basename for 2D figure
  """
    if (ai_output_filename != ''):
        # create the output directory if needed
        l_output_dir = os.path.dirname(ai_output_filename)
        design_help.mkdir_p(l_output_dir)
        #l_output_basename = os.path.basename(ai_output_filename)
        #print("dbg449: l_output_basename:", l_output_basename)
        # mozman dxfwrite
        if (re.search('\.dxf$', ai_output_filename)):
            #print("Generate {:s} with mozman dxfwrite".format(ai_output_filename))
            outline_backends.write_figure_in_dxf(ai_figure, ai_output_filename)
        # mozman svgwrite
        elif (re.search('\.svg$', ai_output_filename)):
            #print("Generate {:s} with mozman svgwrite".format(ai_output_filename))
            outline_backends.write_figure_in_svg(ai_figure, ai_output_filename)
        # FreeCAD
        elif (re.search('\.brep$', ai_output_filename)):
            print("Generate with FreeCAD the BRep file {:s}".format(
                ai_output_filename))
            freecad_part = outline_backends.figure_to_freecad_25d_part(
                ai_figure, ai_height)
            freecad_part.exportBrep("{:s}".format(ai_output_filename))
            print("Generate with FreeCAD the DXF file {:s}.dxf".format(
                ai_output_filename))
            # slice freecad_part  in the XY plan at a height of ai_height/2
            export_2d.export_to_dxf(freecad_part, Base.Vector(0, 0, 1),
                                    ai_height / 2,
                                    "{:s}.dxf".format(ai_output_filename))
        elif (re.search('\.stl$', ai_output_filename)):
            print("Generate with FreeCAD the STL file {:s}".format(
                ai_output_filename))
            freecad_part = outline_backends.figure_to_freecad_25d_part(
                ai_figure, ai_height)
            freecad_part.exportStl("{:s}".format(ai_output_filename))
            print("Generate with FreeCAD the DXF file {:s}.dxf".format(
                ai_output_filename))
            # slice freecad_part  in the XY plan at a height of ai_height/2
            export_2d.export_to_dxf(freecad_part, Base.Vector(0, 0, 1),
                                    ai_height / 2,
                                    "{:s}.dxf".format(ai_output_filename))
        else:
            print(
                "ERR124: Error: the suffix of the filename {:s} is unknown. Try with suffix: .dxf, .svg, .brep or .stl"
                .format(ai_output_filename))
            sys.exit(2)
        # info_txt
        #if(ai_info_txt!=''):
        #  output_basename = re.sub('(\.dxf$)|(\.svg$)', '', ai_output_filename)
        #  info_txt_filename = "{:s}.txt".format(output_basename)
        #  print("Generate the text info file {:s}".format(info_txt_filename))
        #  ofh = open(info_txt_filename, 'w')
        #  ofh.write("{:s} generated by Cnc25D on {:s}\n\n".format(info_txt_filename, datetime.now().isoformat()))
        #  ofh.write(ai_info_txt)
        #  ofh.close()
    # return
    return (0)