Exemplo n.º 1
0
def open(filename):
    "called when freecad opens a file."
    dxf = convertToDxf(filename)
    if dxf:
        import importDXF
        doc = importDXF.open(dxf)
        return doc
    return
Exemplo n.º 2
0
def open(filename):
    "called when freecad opens a file."
    dxf = convertToDxf(filename)
    if dxf:
        import importDXF
        doc = importDXF.open(dxf)
        return doc
    return
Exemplo n.º 3
0
def open(filename):
    """Open filename and parse using importDXF.open().
    Parameters
    ----------
    filename : str
        The path to the filename to be opened.
    Returns
    -------
    App::Document
        The new FreeCAD document object created, with the parsed information.
    """
    dxf = convertToDxf(filename)
    if dxf:
        doc = importDXF.open(dxf)
        return doc
    return
Exemplo n.º 4
0
input_path = args.input
output_path = args.output

# List all the DXF files to read
files = [f for f in os.listdir(input_path) if isfile(join(input_path, f))]

obj_with_content = []
obj_with_content_fat = []
coordinates = []

print "---------- Creation des fichiers svg ----------"
for f in files:
    current_filename = splitext(f)[0]

    # Import the DXF with the FreeCad library
    importDXF.open(join(input_path, f))
    doc = FreeCAD.ActiveDocument
    importSVG.export(
        doc.Objects,
        join(output_path, 'all_objects_' + current_filename + '.svg'))

    #Display a progress bar
    widgets = [
        f + ' :',
        progressbar.Bar('=', '[', ']'), ' ',
        progressbar.Percentage()
    ]
    pbar = progressbar.ProgressBar(widgets=widgets,
                                   maxval=len(FreeCAD.ActiveDocument.Objects))
    pbar.start()
Exemplo n.º 5
0
search_folders[0] = search_folders[0][1:]
search_folders[-1] = search_folders[-1][:-1]
last_date = os.environ.get('LAST_DATE')
oda_path = os.environ.get('ODA_PATH')

document_index = 0
for search_folder in search_folders:
    for root, dirs, files in os.walk(search_folder):
        for file in files:
            if file.endswith('.dwg'):
                try:
                    file_path = root + "\\" + file
                    mtime = os.path.getctime(file_path)
                    last_modified_date = datetime.fromtimestamp(mtime)
                    if last_modified_date > datetime.strptime(
                            last_date, '%Y-%m-%d %H:%M:%S'):
                        convertToDxf(file_path)
                        importDXF.open(tmp_folder + "\\" + file[:-3] + "dxf")
                        document = list(
                            app.listDocuments().keys())[document_index]
                        document_index += 1
                        app.setActiveDocument(document)
                        app.ActiveDocument = app.getDocument(document)

                        gui.export(app.ActiveDocument.Objects,
                                   results_folder + "\\" + file[:-3] + "pdf")
                except OSError:
                    mtime = 0
dotenv.set_key(dotenv_path, "LAST_DATE",
               str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
Exemplo n.º 6
0
def makeFaceDXF():
    global copper_diffuse, silks_diffuse
    global use_LinkGroups, use_AppPart

    doc = FreeCAD.ActiveDocument
    if doc is None:
        FreeCAD.newDocument()
        doc = FreeCAD.ActiveDocument
    docG = FreeCADGui.ActiveDocument
    Filter = ""
    last_pcb_path = ""
    pg = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUp")
    last_pcb_path = pg.GetString("last_pcb_path")
    fn, Filter = PySide.QtGui.QFileDialog.getOpenFileNames(
        None, "Open File...", make_unicode(last_pcb_path), "*.dxf")
    for fname in fn:
        path, name = os.path.split(fname)
        filename = os.path.splitext(name)[0]
        #importDXF.open(os.path.join(dirname,filename))
        if len(fname) > 0:
            #importDXF.open(fname)
            last_pcb_path = os.path.dirname(fname)
            pg = FreeCAD.ParamGet(
                "User parameter:BaseApp/Preferences/Mod/kicadStepUp")
            pg.SetString("last_pcb_path",
                         make_string(last_pcb_path))  # py3 .decode("utf-8")
            pg = FreeCAD.ParamGet(
                "User parameter:BaseApp/Preferences/Mod/kicadStepUpGui")
            pcb_color_pos = pg.GetInt('pcb_color')
            #print(pcb_color_pos)
            if pcb_color_pos == 9:
                silks_diffuse = (0.18, 0.18, 0.18)  #slick black
            else:
                silks_diffuse = (
                    0.98, 0.92, 0.84
                )  # #antique white  # white (0.906,0.906,0.910)
            doc = FreeCAD.ActiveDocument
            objects = []
            say("loading... ")
            t = time.time()
            if doc is not None:
                for o in doc.Objects:
                    objects.append(o.Name)
                importDXF.insert(fname, doc.Name)
            else:
                importDXF.open(fname)
            FreeCADGui.SendMsgToActiveView("ViewFit")
            timeP = time.time() - t
            say("loading time = " + str(timeP) + "s")

            edges = []
            sorted_edges = []
            w = []

            for o in doc.Objects:
                if o.Name not in str(objects):
                    if hasattr(o, 'Shape'):
                        w1 = Part.Wire(Part.__sortEdges__(o.Shape.Edges))
                        w.append(w1)
            #print (w)
            f = Part.makeFace(w, 'Part::FaceMakerBullseye')
            for o in doc.Objects:
                if o.Name not in str(objects):
                    doc.removeObject(o.Name)
            if 'Silk' in filename:
                layerName = 'Silks'
            else:
                layerName = 'Tracks'
            if 'F.' in filename or 'F_' in filename:
                layerName = 'top' + layerName
            if 'B.' in filename or 'B_' in filename:
                layerName = 'bot' + layerName

            doc.addObject('Part::Feature', layerName).Shape = f
            newShape = doc.ActiveObject
            botOffset = 1.6
            if 'Silk' in layerName:
                docG.getObject(newShape.Name).ShapeColor = silks_diffuse
            else:
                docG.getObject(
                    newShape.Name
                ).ShapeColor = brass_diffuse  #copper_diffuse  #(0.78,0.56,0.11)
            if len(doc.getObjectsByLabel('Pcb')) > 0:
                newShape.Placement = doc.getObjectsByLabel('Pcb')[0].Placement
                #botTracks.Placement = doc.Pcb.Placement
                if len(doc.getObjectsByLabel('Board_Geoms')) > 0:
                    if use_AppPart and not use_LinkGroups:
                        doc.getObject('Board_Geoms').addObject(newShape)
                    elif use_LinkGroups:
                        doc.getObject('Board_Geoms').ViewObject.dropObject(
                            newShape, None, '', [])
                if hasattr(doc.getObjectsByLabel('Pcb')[0], 'Shape'):
                    botOffset = doc.getObjectsByLabel(
                        'Pcb')[0].Shape.BoundBox.ZLength
                else:
                    botOffset = doc.getObjectsByLabel(
                        'Pcb')[0].OutList[1].Shape.BoundBox.ZLength
            #elif 'bot' in layerName:
            #    newShape.Placement.Base.z-=1.6
            if 'top' in layerName:
                newShape.Placement.Base.z += 0.07
            if 'bot' in layerName:
                newShape.Placement.Base.z -= botOffset + 0.07
            timeD = time.time() - t - timeP
            say("displaying time = " + str(timeD) + "s")
    FreeCADGui.SendMsgToActiveView("ViewFit")
    docG.activeView().viewAxonometric()