def make_3D_model(self):
        """ create a 3D model of a WAGO serie 734 connector.  Two parts will be created: plastic body, pins.

        This function will be called from the main_generator script.
        :return: list of the materials used for the 3D model
        :rtype: ``dictionary`` 
        """
        destination_dir = self.get_dest_3D_dir()
        
        case = self.makePlasticCase()
        pins = self.make_pins()
        show(case)
        show(pins)
     
        doc = FreeCAD.ActiveDocument
        objs = GetListOfObjects(FreeCAD, doc)

     
        body_color = shaderColors.named_colors[self.body_color_key].getDiffuseFloat()
        pin_color = shaderColors.named_colors[self.pin_color_key].getDiffuseFloat()

        # must be the same order of the above show(..) calls
        Color_Objects(Gui, objs[0], body_color)
        Color_Objects(Gui, objs[1], pin_color)

        col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
        col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
        
        material_substitutions={
            col_body[:-1]:self.body_color_key,
            col_pin[:-1]:self.pin_color_key,
        }
        
        expVRML.say(material_substitutions)

        # fuse all parts of model
        while len(objs) > 1:
                FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
                del objs
                objs = GetListOfObjects(FreeCAD, doc)

        #rotate if required
        if (self.rotation != 0):
            z_RotateObject(doc, self.rotation)

        s = objs[0].Shape
        shape = s.copy()
        shape.Placement = s.Placement;
        shape.translate(self.offsets)
        objs[0].Placement = shape.Placement

        return material_substitutions
def make_3D_model(models_dir, model_class, modelID):

    LIST_license = ["",]

    CheckedmodelName = 'A_' + modelID.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
    CheckedmodelName = CheckedmodelName
    Newdoc = App.newDocument(CheckedmodelName)
    App.setActiveDocument(CheckedmodelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedmodelName)
    destination_dir = model_class.get_dest_3D_dir(modelID)

    material_substitutions = model_class.make_3D_model(modelID)
    modelName = model_class.get_model_name(modelID)
    
    doc = FreeCAD.ActiveDocument
    doc.Label = CheckedmodelName

    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedmodelName
    restore_Main_Tools()

    script_dir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(models_dir)
    out_dir=models_dir+os.sep+destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    exportSTEP(doc, modelName, out_dir)
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir + os.sep, modelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,modelName,scale,out_dir)
    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+modelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    #expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)
    #scale=0.3937001
    #exportVRML(doc,modelName,scale,out_dir)
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, modelName,out_dir)
    #display BBox
    Gui.activateWorkbench("PartWorkbench")
    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()
def make_3D_model(models_dir, model_class, modelID):

    LIST_license = ["",]

    CheckedmodelName = modelID.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedmodelName)
    App.setActiveDocument(CheckedmodelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedmodelName)
    destination_dir = model_class.get_dest_3D_dir(modelID)
    
    material_substitutions = model_class.make_3D_model(modelID)
    modelName = model_class.get_model_name(modelID)
    
    
    doc = FreeCAD.ActiveDocument
    doc.Label = CheckedmodelName

    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedmodelName
    restore_Main_Tools()

    script_dir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(models_dir)
    out_dir=models_dir+os.sep+destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    exportSTEP(doc, modelName, out_dir)
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir + os.sep, modelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,modelName,scale,out_dir)
    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+modelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    #expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)
    #scale=0.3937001
    #exportVRML(doc,modelName,scale,out_dir)
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, modelName,out_dir)
    #display BBox
    Gui.activateWorkbench("PartWorkbench")
    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()
    for p in pins[1:]:
        merged_pins = merged_pins.union(p)
    pins = merged_pins

    #show(pins)
    #sleep
    # extract pins from case
    case = case.cut(pins)

    return (case, pins, pinmark)

import step_license as L


if __name__ == "__main__":
    expVRML.say(expVRML.__file__)
    FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')

# maui     run()
    color_pin_mark=True
    if len(sys.argv) < 3:
        FreeCAD.Console.PrintMessage('No variant name is given! building qfn16')
        model_to_build='QFN16'
    else:
        model_to_build=sys.argv[2]
        if len(sys.argv)==4:
            FreeCAD.Console.PrintMessage(sys.argv[3]+'\r\n')
            if (sys.argv[3].find('no-pinmark-color')!=-1):
                color_pin_mark=False
            else:
                color_pin_mark=True
def generateOneModel(params, log):
    excluded_pins_x = ()  ##no pin excluded
    excluded_pins_xmirror = ()  ##no pin excluded
    place_pinMark = True  ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark)

    ModelName = params.modelName
    FreeCAD.Console.PrintMessage('\n\n##############  ' + ModelName +
                                 '  ###############\n')
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace(
        '(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    Gui.ActiveDocument = Gui.getDocument(CheckedModelName)
    #case, pins, pinmark = make_case(params)
    case_bot, case, pins, pinmark = make_case(params)

    if case_bot is not None:
        show(case_bot)
    show(case)
    show(pins)
    show(pinmark)
    #stop

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    if case_bot is not None:
        Color_Objects(Gui, objs[0], body_bot_color)
        Color_Objects(Gui, objs[1], body_color)
        Color_Objects(Gui, objs[2], pins_color)
        Color_Objects(Gui, objs[3], marking_color)

        col_body_bot = Gui.ActiveDocument.getObject(
            objs[0].Name).DiffuseColor[0]
        col_body = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
        col_pin = Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
        col_mark = Gui.ActiveDocument.getObject(objs[3].Name).DiffuseColor[0]
        material_substitutions = {
            col_body_bot[:-1]: body_bot_color_key,
            col_body[:-1]: body_color_key,
            col_pin[:-1]: pins_color_key,
            col_mark[:-1]: marking_color_key
        }
        expVRML.say(material_substitutions)
        if (color_pin_mark == True) and (place_pinMark == True):
            CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[1].Name,
                            objs[3].Name)
        else:
            #removing pinMark
            App.getDocument(doc.Name).removeObject(objs[3].Name)
        ###
        #sleep
        del objs
        objs = GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                         objs[1].Name)
        objs = GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                         objs[1].Name)
    else:
        Color_Objects(Gui, objs[0], body_color)
        Color_Objects(Gui, objs[1], pins_color)
        Color_Objects(Gui, objs[2], marking_color)

        col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
        col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
        col_mark = Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
        material_substitutions = {
            col_body[:-1]: body_color_key,
            col_pin[:-1]: pins_color_key,
            col_mark[:-1]: marking_color_key
        }
        #expVRML.say(material_substitutions)
        if (color_pin_mark == True) and (place_pinMark == True):
            CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                            objs[2].Name)
        else:
            #removing pinMark
            App.getDocument(doc.Name).removeObject(objs[2].Name)
        ###
        #sleep
        del objs
        objs = GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                         objs[1].Name)
    ## objs[0].Label='body'
    ## objs[1].Label='pins'
    ## objs[2].Label='mark'
    ###
    ## print objs[0].Name, objs[1].Name, objs[2].Name

    ## sleep
    doc.Label = CheckedModelName
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedModelName
    restore_Main_Tools()
    #rotate if required
    if (params.rotation != 0):
        rot = params.rotation
        z_RotateObject(doc, rot)
    #out_dir=destination_dir+params.dest_dir_prefix+'/'
    script_dir = os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    #expVRML.say(models_dir)
    if len(params.dest_dir_prefix) >= 1:
        out_dir = models_dir + destination_dir + os.sep + params.dest_dir_prefix
    else:
        out_dir = models_dir + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, ModelName, out_dir)
    global LIST_license
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)

    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + ModelName + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    #expVRML.writeVRMLFile added creaeAngle
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license, 0.9)
    # Save the doc in Native FC format
    #saveFCdoc(App, Gui, doc, ModelName,out_dir)
    #display BBox
    #FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True
    if footprints_dir is not None and os.path.isdir(
            footprints_dir
    ) and not save_memory and not check_Model:  #it doesn't make sense to import the footprint right before we close the file.
        #expVRML.say (ModelName)
        #stop
        sys.argv = [
            "fc", "dummy", footprints_dir + os.sep + ModelName, "savememory"
        ]
        #setup = get_setup_file()  # << You need the parentheses
        expVRML.say(sys.argv[2])
        if not ksu_present:
            try:
                import kicadStepUptools
                ksu_present = True
                expVRML.say("ksu present!")
                kicadStepUptools.KSUWidget.close()
                #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                #kicadStepUptools.KSUWidget.destroy()
                #for i in QtGui.qApp.topLevelWidgets():
                #    if i.objectName() == "kicadStepUp":
                #        i.deleteLater()
                kicadStepUptools.KSUWidget.close()
            except:
                ksu_present = False
                expVRML.say("ksu not present")
        else:
            kicadStepUptools.KSUWidget.close()
            reload_lib(kicadStepUptools)
            kicadStepUptools.KSUWidget.close()
            #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
            #kicadStepUptools.KSUWidget.destroy()

    #FreeCADGui.insert(u"C:\Temp\FCAD_sg\QFN_packages\QFN-12-1EP_3x3mm_Pitch0_5mm.kicad_mod")
    #FreeCADGui.insert(script_dir+os.sep+"ModelName.kicad_mod")
    if save_memory == False:
        Gui.activateWorkbench("PartWorkbench")
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewBottom()
        #Gui.activeDocument().activeView().viewAxometric()
    saveFCdoc(App, Gui, doc, ModelName, out_dir)

    if save_memory == True or check_Model == True:
        doc = FreeCAD.ActiveDocument
        print("closing: {}".format(doc.Name))
        FreeCAD.closeDocument(doc.Name)

    if check_Model == True:
        step_path = out_dir + '/' + ModelName + ".step"
        runGeometryCheck(App,
                         Gui,
                         step_path,
                         log,
                         ModelName,
                         save_memory=save_memory)
Exemple #6
0
    def makeModels(self,
                   options,
                   series,
                   family,
                   params,
                   kicadStepUptools=None,
                   verbose=False):
        r"""Instantiates model creator classes and calls :func:`makeModel` repeatedly to create model files

        This is the main entry point to use for creating models

        :param options:
            * options[0]:
                * empty - create default model from all *series* when *family* is None, otherwise the default model for a single *series*
                * 'all' - generate all models
                * 'allsmd' - generate all SMD style models
                * 'list' - list all model names
                * regexp - a filter to select the models to create
        :type options: ``str``

        :param series:
            list of part creator classes inherited from :class:`cq_base_model.PartBase`
        :type  series: ``list of classes``

        :param family:
            index into the list of parameter classes (series) None if all
        :type  family: ``integer or None``

        :param params:
            instance of the class used to hold part parameters
        :type  params: ``class instance`` inherited from :class:`cq_base_model.PartBase`

        Example::

            import sys, os

            script_dir  = os.path.dirname(os.path.realpath(__file__))
            scripts_root = script_dir.split(script_dir.split(os.sep)[-1])[0]

            sys.path.append(script_dir)
            sys.path.append(scripts_root + "\_tools")

            import cq_model_generator
            from cq_base_model import *

            class my_part (PartBase)
                ...

            class my_part_params (PartParametersBase)
                ...

            family = 0 # set to None to generate all series

            series = [
              my_part
            ]

            generator = cq_model_generator.ModelGenerator(scripts_root, script_dir)

            options = generator.getOptions(sys.argv)

            generator.make_models(options, series, family, my_part_params())

        """

        clear_console()
        FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')

        if verbose:
            expVRML.say(self.models_dir)
            expVRML.say(options)

        models_made = 0

        if len(options) > 0 and not options[0] in params.base_params:

            models = params.getAllModels(series)

            if options[0] == "list":
                for variant in sorted(models):
                    models_made = models_made + 1
                    expVRML.say(variant +
                                "  ")  # added spaces for pasting into .md file
            else:
                buildAllSMD = options[0] == "allsmd"
                qfilter = '*' if options[0] == "all" or options[
                    0] == "allsmd" else options[0]
                qfilter = re.compile(fnmatch.translate(qfilter))
                for variant in list(models.keys()):
                    genericName = models[variant].variant
                    if qfilter.match(variant):
                        params = models[variant].params
                        model = models[variant].model(params)
                        if (buildAllSMD == False or params.type
                                == CaseType.SMD) and model.make_me:
                            models_made = models_made + 1
                            # Change MountyRox: see below     vvvvvvvvvvvvvvvvvv
                            self.makeModel(self.models_dir,
                                           models[variant].variant,
                                           model,
                                           keepDocument=False,
                                           verbose=verbose)
        else:

            if family == All:

                models = params.getSampleModels(series)

                for variant in list(models.keys()):
                    params = models[variant].params
                    model = models[variant].model(params)
                    # Change MountyRox: use genericName when calling makeModel instead variant,
                    # because variant holds the return value of model.makeModelName(genericName), not the original generic name
                    genericName = models[variant].variant
                    if model.make_me:
                        models_made = models_made + 1
                        self.makeModel(self.models_dir,
                                       genericName,
                                       model,
                                       keepDocument=True,
                                       verbose=verbose)
                    else:
                        FreeCAD.Console.PrintMessage(
                            '\r\n' + model.makeModelName(genericName) +
                            ' - not made')

            else:

                variant_to_build = "" if len(options) == 0 else options[0]
                if variant_to_build == "":
                    FreeCAD.Console.PrintMessage(
                        'No variant name is given! building default variants')
                for i in range(family, family + 1):
                    variant = series[
                        i].default_model if variant_to_build == "" else variant_to_build
                    model = params.getModel(series[i], variant)
                    if model != False:
                        models_made = models_made + 1
                        self.makeModel(self.models_dir,
                                       variant,
                                       model,
                                       keepDocument=True,
                                       verbose=verbose)
                    else:
                        FreeCAD.Console.PrintMessage('\r\n' + variant +
                                                     ' - not made')

        if models_made == 0:
            FreeCAD.Console.PrintMessage(
                '\r\nDone - no models matched the provided filter!\r\n')
        else:
            FreeCAD.Console.PrintMessage('\r\nDone - models made: ' +
                                         str(models_made) + '\r\n')

        sys.argv = []  # clear, running kicadStepUptools changes values
def MakePart(params, name, n=1):
    global formerDOC
    global LIST_license
    #name = PartName(params, n)

    full_path=os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name =full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir=sub_path+"_3Dmodels"
    script_dir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(models_dir)
    out_dir=models_dir+destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    #having a period '.' character in the model name REALLY messes with things. also '-'
    docname = name.replace(".","").replace("-","_")
   
    newdoc = App.newDocument(docname)
    App.setActiveDocument(docname)
    App.ActiveDocument=App.getDocument(docname)
    Gui.ActiveDocument=Gui.getDocument(docname)
    
    FreeCAD.Console.PrintMessage(params)
    pins_output = MakeResistorPin(params, n)
    base_output = MakeResistor(params, n)
    marking_output = MakeMarking(params, n)
    
    show(base_output)
    show(pins_output)
    if not (marking_output == 0):
        show(marking_output)

    doc = FreeCAD.ActiveDocument
    objs=GetListOfObjects(FreeCAD, doc)
    
    # select the color based on shape
    if (params.shape == "power") or (params.shape == "radial") or (params.shape == "shunt"):
        # white colour for power resistors
        chosen_body_color = ceramic_color
        chosen_body_color_key = ceramic_color_key
    elif (params.shape == "bare"):
        # metal/pin colour for bare resistors
        chosen_body_color = pins_color
        chosen_body_color_key = pins_color_key   
    else:
        # light brown colour for din/axial/arrays/etc.
        chosen_body_color = body_color
        chosen_body_color_key = body_color_key  
    
    # body and pin colours
    Color_Objects(Gui,objs[0],chosen_body_color)
    Color_Objects(Gui,objs[1],pins_color)
    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    material_substitutions={
        col_body[:-1]:chosen_body_color_key,
        col_pin[:-1]:pins_color_key
    }
    
    # optional marking bodies
    if (len(objs) >= 3):
        Color_Objects(Gui,objs[2],marking_color)
        col_marking=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
        material_substitutions[col_marking[:-1]] = marking_color_key
        
    expVRML.say(material_substitutions)

    # fuse everything
    while len(objs) > 1:
        FreeCAD.Console.PrintMessage(len(objs))
        FuseObjs_wColors(FreeCAD, FreeCADGui,
                   doc.Name, objs[0].Name, objs[1].Name)
        objs = GetListOfObjects(FreeCAD, doc)

    doc.Label=docname
    #objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label=docname
    restore_Main_Tools()

    doc.Label = docname
    
    #save the STEP file
    exportSTEP(doc, name, out_dir)
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', name+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)
    
    # scale and export Vrml model
    scale=1/2.54
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+name+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)
    
    if save_memory == False:
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()
    
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, name,out_dir)
    if save_memory == True:
        doc=FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)

    return 0
Exemple #8
0
def MakePart(params, name, n=1):
    global formerDOC
    global LIST_license
    #name = PartName(params, n)

    full_path = os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir = os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name = full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir = sub_path + "_3Dmodels"
    script_dir = os.path.dirname(os.path.realpath(__file__))
    expVRML.say(models_dir)
    out_dir = models_dir + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    #having a period '.' character in the model name REALLY messes with things. also '-'
    docname = name.replace(".", "").replace("-", "_")

    newdoc = App.newDocument(docname)
    App.setActiveDocument(docname)
    App.ActiveDocument = App.getDocument(docname)
    Gui.ActiveDocument = Gui.getDocument(docname)

    FreeCAD.Console.PrintMessage(params)
    pins_output = MakeResistorPin(params, n)
    base_output = MakeResistor(params, n)

    show(base_output)
    show(pins_output)

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    # select the color based on shape
    if (params.shape == "power") or (params.shape == "radial") or (params.shape
                                                                   == "shunt"):
        # white colour for power resistors
        chosen_body_color = ceramic_color
        chosen_body_color_key = ceramic_color_key
    elif (params.shape == "bare"):
        # metal/pin colour for bare resistors
        chosen_body_color = pins_color
        chosen_body_color_key = pins_color_key
    else:
        # light brown colour for din/axial/arrays/etc.
        chosen_body_color = body_color
        chosen_body_color_key = body_color_key

    Color_Objects(Gui, objs[0], chosen_body_color)
    Color_Objects(Gui, objs[1], pins_color)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    material_substitutions = {
        col_body[:-1]: chosen_body_color_key,
        col_pin[:-1]: pins_color_key,
    }
    expVRML.say(material_substitutions)

    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = docname
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = docname
    restore_Main_Tools()

    doc.Label = docname

    #save the STEP file
    exportSTEP(doc, name, out_dir)
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', name+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    objs = GetListOfObjects(FreeCAD, doc)
    expVRML.say(
        "######################################################################"
    )
    expVRML.say(objs)
    expVRML.say(
        "######################################################################"
    )
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + name + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)

    if save_memory == False:
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()

    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, name, out_dir)
    if save_memory == True:
        closeCurrentDoc(docname)
    return 0
Exemple #9
0
def make_3D_model(models_dir, variant):

    LIST_license = [
        "",
    ]
    modelName = all_params[variant].modelName

    CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace(
        '(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedmodelName)
    App.setActiveDocument(CheckedmodelName)
    Gui.ActiveDocument = Gui.getDocument(CheckedmodelName)

    case = make_case(all_params[variant], type, modelName)

    if (all_params[variant].type == CASE_THT_TYPE):
        pins = make_pins_tht(all_params[variant], type, modelName)

    if (all_params[variant].type == CASE_SMD_TYPE):
        pins = make_pins_smd(all_params[variant], type, modelName)

        # color_attr=case_color+(0,)
    # show(case, color_attr)
    # #FreeCAD.Console.PrintMessage(pins_color)
    # color_attr=pins_color+(0,)
    # #FreeCAD.Console.PrintMessage(color_attr)
    # show(pins, color_attr)
    #doc = FreeCAD.ActiveDocument
    #objs=GetListOfObjects(FreeCAD, doc)

    show(case)
    show(pins)
    #show(pinmark)
    #stop

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui, objs[0], body_color)
    Color_Objects(Gui, objs[1], pins_color)
    #Color_Objects(Gui,objs[2],marking_color)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions = {
        col_body[:-1]: body_color_key,
        col_pin[:-1]: pins_color_key
        #col_mark[:-1]:marking_color_key
    }
    expVRML.say(material_substitutions)

    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = CheckedmodelName
    del objs
    #objs=GetListOfObjects(FreeCAD, doc)
    #FuseObjs_wColors(FreeCAD, FreeCADGui,
    #                doc.Name, objs[0].Name, objs[1].Name)
    #doc.Label=modelName
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedmodelName
    restore_Main_Tools()

    # objs=GetListOfObjects(FreeCAD, doc)
    # objs[0].Label=modelName
    # restore_Main_Tools()
    #rotate if required
    if (all_params[variant].rotation != 0):
        rot = all_params[variant].rotation
        z_RotateObject(doc, rot)
    npins = all_params[variant].npins
    e = all_params[variant].e
    E = all_params[variant].E
    c = 0.254  # lead thickness
    mvY = (npins * e / 4 - e / 2)
    mvX = (E - c) / 2
    s = objs[0].Shape
    shape = s.copy()
    shape.Placement = s.Placement
    shape.translate((+mvX, -mvY, 0))
    objs[0].Placement = shape.Placement
    #case = case.translate ((-mvX,-mvY,0))
    #pins = pins.translate ((-mvX,-mvY,0))
    # out_dir=destination_dir
    # if not os.path.exists(out_dir):
    #     os.makedirs(out_dir)
    # #out_dir="./generated_qfp/"
    # # export STEP model
    # exportSTEP(doc,modelName,out_dir)
    script_dir = os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir = models_dir + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, modelName, out_dir)
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', modelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,modelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)
    expVRML.say(
        "######################################################################"
    )
    expVRML.say(objs)
    expVRML.say(
        "######################################################################"
    )
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + modelName + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    #expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)
    #scale=0.3937001
    #exportVRML(doc,modelName,scale,out_dir)
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, modelName, out_dir)
    #display BBox
    Gui.activateWorkbench("PartWorkbench")
    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()
def make_3D_model(models_dir, variant):
                
    LIST_license = ["",]
    modelName = all_params[variant].modelName
        
    CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedmodelName)
    App.setActiveDocument(CheckedmodelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedmodelName)

    case = make_case(all_params[variant], type, modelName)
    
    if (all_params[variant].type == CASE_THT_TYPE):
        pins = make_pins_tht(all_params[variant], type, modelName)

    if (all_params[variant].type == CASE_SMD_TYPE):
        pins = make_pins_smd(all_params[variant], type, modelName)


        # color_attr=case_color+(0,)
    # show(case, color_attr)
    # #FreeCAD.Console.PrintMessage(pins_color)
    # color_attr=pins_color+(0,)
    # #FreeCAD.Console.PrintMessage(color_attr)
    # show(pins, color_attr)
    #doc = FreeCAD.ActiveDocument
    #objs=GetListOfObjects(FreeCAD, doc)

    show(case)
    show(pins)
    #show(pinmark)
    #stop
    
    doc = FreeCAD.ActiveDocument
    objs=GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui,objs[0],body_color)
    Color_Objects(Gui,objs[1],pins_color)
    #Color_Objects(Gui,objs[2],marking_color)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions={
        col_body[:-1]:body_color_key,
        col_pin[:-1]:pins_color_key
        #col_mark[:-1]:marking_color_key
    }
    expVRML.say(material_substitutions)

    FuseObjs_wColors(FreeCAD, FreeCADGui,
                    doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = CheckedmodelName
    del objs
    #objs=GetListOfObjects(FreeCAD, doc)
    #FuseObjs_wColors(FreeCAD, FreeCADGui,
    #                doc.Name, objs[0].Name, objs[1].Name)
    #doc.Label=modelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedmodelName
    restore_Main_Tools()

    # objs=GetListOfObjects(FreeCAD, doc)
    # objs[0].Label=modelName
    # restore_Main_Tools()
    #rotate if required
    if (all_params[variant].rotation!=0):
        rot= all_params[variant].rotation
        z_RotateObject(doc, rot)
    npins=all_params[variant].npins
    e=all_params[variant].e
    E=all_params[variant].E
    c= 0.254 # lead thickness
    mvY = (npins*e/4-e/2)
    mvX = (E-c)/2
    s = objs[0].Shape
    shape=s.copy()
    shape.Placement=s.Placement;
    shape.translate((+mvX,-mvY,0))
    objs[0].Placement=shape.Placement
    #case = case.translate ((-mvX,-mvY,0))
    #pins = pins.translate ((-mvX,-mvY,0))
    # out_dir=destination_dir
    # if not os.path.exists(out_dir):
    #     os.makedirs(out_dir)
    # #out_dir="./generated_qfp/"
    # # export STEP model
    # exportSTEP(doc,modelName,out_dir)
    script_dir=os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir=models_dir+destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, modelName, out_dir)
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', modelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,modelName,scale,out_dir)
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+modelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    #expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)
    #scale=0.3937001
    #exportVRML(doc,modelName,scale,out_dir)
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, modelName,out_dir)
    #display BBox
    Gui.activateWorkbench("PartWorkbench")
    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()
def generateOneModel(params, log):
    ModelName = params.modelName
    FreeCAD.Console.PrintMessage('\n\n##############  ' +
                                 part_params['code_metric'] +
                                 '  ###############\n')
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace(
        '(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    Gui.ActiveDocument = Gui.getDocument(CheckedModelName)
    #body, base, mark, pins = make_tantalum_th(params)
    body, pins, pinmark = make_tantalum_th(
        params)  #body, base, mark, pins, top

    show(body)
    show(pins)
    show(pinmark)

    doc = FreeCAD.ActiveDocument
    print(GetListOfObjects(FreeCAD, doc))
    objs = GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui, objs[0], body_color)
    Color_Objects(Gui, objs[1], pins_color)
    Color_Objects(Gui, objs[2], marking_color)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    col_mark = Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]

    material_substitutions = {
        col_body[:-1]: body_color_key,
        col_pin[:-1]: pins_color_key,
        col_mark[:-1]: marking_color_key
    }
    expVRML.say(material_substitutions)
    del objs

    objs = GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    objs = GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    #stop
    doc.Label = CheckedModelName
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedModelName
    restore_Main_Tools()
    #rotate if required
    objs = GetListOfObjects(FreeCAD, doc)
    FreeCAD.getDocument(doc.Name).getObject(
        objs[0].Name).Placement = FreeCAD.Placement(
            FreeCAD.Vector(params.F / 2, 0, 0),
            FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), params.rotation))
    #out_dir=destination_dir+params.dest_dir_prefix+'/'
    script_dir = os.path.dirname(os.path.realpath(__file__))

    expVRML.say(script_dir)
    #out_dir=script_dir+os.sep+destination_dir+os.sep+params.dest_dir_prefix

    out_dir = models_dir + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model

    exportSTEP(doc, ModelName, out_dir)

    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)
    expVRML.say(
        "######################################################################"
    )
    expVRML.say(objs)
    expVRML.say(
        "######################################################################"
    )
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + ModelName + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)

    if save_memory == False:
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()

    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, ModelName, out_dir)
    if save_memory == True:
        doc = FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)
def generateOneModel(part_params, log):
    place_pinMark=True ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark)

    FreeCAD.Console.PrintMessage(
        '\n\n##############  ' +
        part_params['code_metric'] +
        '  ###############\n')
    dim_params = part_params['param_nominal'] if use_nominal_size else part_params['param_max']
    if dim_params == None:
        if show_all:
            if use_nominal_size:
                dim_params = part_params['param_max']
            else:
                dim_params = part_params['param_nominal']
    if dim_params == None:
        FreeCAD.Console.PrintMessage('No params found for current variant. Skipped\n')
        return

    ModelName = model_name_format_str.format(
      prefix=model_name_prefix,
      code_metric=part_params['code_metric'],
      code_letter=part_params['code_letter'],
      old_name=part_params['modelName_old'],
      maui_name=part_params['modelName_maui']
    )
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedModelName)
    body, pins, mark = make_tantalum(dim_params)

    show(body)
    show(pins)
    show(mark)
    
    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui,objs[0],body_color)
    Color_Objects(Gui,objs[1],pins_color)
    Color_Objects(Gui,objs[2],mark_color)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions={
        col_body[:-1]:body_color_key,
        col_pin[:-1]:pins_color_key,
        col_mark[:-1]:mark_color_key
    }
    #expVRML.say(material_substitutions)
    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    if (color_pin_mark==True) and (place_pinMark==True):
        CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[2].Name)
    else:
        #removing pinMark
        App.getDocument(doc.Name).removeObject(objs[2].Name)
    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = CheckedModelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedModelName
    restore_Main_Tools()
    #rotate if required
    if (rotation!=0):
        rot = rotation
        z_RotateObject(doc, rot)
    #out_dir=destination_dir+all_params[variant].dest_dir_prefix+'/'
    script_dir=os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir=models_dir+destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, ModelName, out_dir)
    global LIST_license
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs=GetListOfObjects(FreeCAD, doc)
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+ModelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    saveFCdoc(App, Gui, doc, ModelName, out_dir)

    #FreeCADGui.activateWorkbench("PartWorkbench")
    if save_memory == False and check_Model==False:
        FreeCADGui.SendMsgToActiveView("ViewFit")
        FreeCADGui.activeDocument().activeView().viewAxometric()

    if save_memory == True or check_Model==True:
        doc=FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)

    if check_Model==True:
        step_path = out_dir + '/' + ModelName + ".step"
        runGeometryCheck(App, Gui, step_path,
            log, ModelName, save_memory=save_memory)
def generateOneModel(params, log):
    ModelName = params.modelName
    FreeCAD.Console.PrintMessage(
        '\n\n##############  ' +
        part_params['code_metric'] +
        '  ###############\n')
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedModelName)
    #body, base, mark, pins = make_tantalum_th(params)
    body, pins, pinmark= make_tantalum_th(params) #body, base, mark, pins, top

    show(body)
    show(pins)
    show(pinmark)

    doc = FreeCAD.ActiveDocument
    print(GetListOfObjects(FreeCAD, doc))
    objs = GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui,objs[0],body_color)
    Color_Objects(Gui,objs[1],pins_color)
    Color_Objects(Gui,objs[2],marking_color)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]

    material_substitutions={
        col_body[:-1]:body_color_key,
        col_pin[:-1]:pins_color_key,
        col_mark[:-1]:marking_color_key
    }
    expVRML.say(material_substitutions)
    del objs

    objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    #stop
    doc.Label = CheckedModelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedModelName
    restore_Main_Tools()
    #rotate if required
    objs=GetListOfObjects(FreeCAD, doc)
    FreeCAD.getDocument(doc.Name).getObject(objs[0].Name).Placement = FreeCAD.Placement(FreeCAD.Vector(params.F/2,0,0),
    FreeCAD.Rotation(FreeCAD.Vector(0,0,1),params.rotation))
    #out_dir=destination_dir+params.dest_dir_prefix+'/'
    script_dir=os.path.dirname(os.path.realpath(__file__))

    expVRML.say(script_dir)
    #out_dir=script_dir+os.sep+destination_dir+os.sep+params.dest_dir_prefix

    out_dir=models_dir+destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model

    exportSTEP(doc, ModelName, out_dir)

    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+ModelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    if save_memory == False:
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()

    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, ModelName,out_dir)
    if save_memory == True:
        doc=FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)
    # extract pins from case
    case = case.cut(pins)
    #show(case)
    #show(pinmark)
    #show(pins)
    #stop
    return (case, pins, pinmark)


#################################################
import add_license as Lic

# when run from command line
if __name__ == "__main__" or __name__ == "main_generator":
    expVRML.say(expVRML.__file__)
    FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')

    full_path = os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir = os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name = full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir = sub_path + "_3Dmodels"

    color_pin_mark = True
Exemple #15
0
def MakeConnector(name, params):

    model_name = name
    full_model_name = name + "-6-0-{}{:02d}_1x{}_P2.50mm_Vertical".format(
        params["pins"], params["pins"], params["pins"])
    expVRML.say(model_name)
    expVRML.say(params)

    out_dir = "../../FCAD_script_generator/_3Dmodels/Connector_Stocko.3dshapes"

    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    body_color_key = "grey body"
    body_color = shaderColors.named_colors[body_color_key].getDiffuseFloat()
    pin_union_color_key = "metal silver"
    pin_union_color = shaderColors.named_colors[
        pin_union_color_key].getDiffuseFloat()

    newdoc = App.newDocument(model_name)
    App.setActiveDocument(model_name)
    App.ActiveDocument = App.getDocument(model_name)
    Gui.ActiveDocument = Gui.getDocument(model_name)

    body = cq.Workplane("XY").move(-params["outline_x"], 0).box((params["pitch"] * (params["pins"] - 1)) + 2 * params["outline_x"], \
    params["base_w"], params["base_h"], centered = (False,True,False))
    body = body.faces(">Z") \
    .workplane().rect(params["pitch"] * (params["pins"] - 1) + 2 * params["outline_x"] - params["lr_sides_t"], \
    params["base_w"] - params["tb_sides_t"]) \
    .cutBlind(-params["depth"]) \
    .faces(">Z") \
    .edges("not(<X or >X or <Y or >Y)") \
    .chamfer(0.7)
    body = body.edges("|Z and >X").fillet(0.5)
    body = body.edges("|Z and <X").fillet(0.5)
    body = body.faces(">Z").workplane().center(0, -params["base_w"] / 2 + params["base_cutout"] /2).rect( \
    params["pitch"] * (params["pins"] - 1) + 2 * (params["outline_x"] - params["leaf"]), \
    params["base_cutout"]) \
    .cutThruAll()
    if params["top_cutout"]:
        body = body.faces(">Y").workplane().center(0, 6.5).rect(
            params["t_cutout_w"], params["t_cutout_h"]).cutThruAll()
    for x in range(params["pins"]):
        temp = (params["b_cutout_long_w"] - params["b_cutout_short_w"]) / 2
        body = body.faces(">Y").workplane(centerOption='CenterOfBoundBox').center( \
            ((params["pitch"] * (params["pins"] - 1) + 2 * params["outline_x"]) / 2) - params["outline_x"] - (params["b_cutout_long_w"] / 2) - x*params["pitch"], \
            -7).lineTo(params["b_cutout_long_w"], 0).lineTo(params["b_cutout_long_w"] - temp, params["b_cutout_h"]).lineTo(temp, params["b_cutout_h"]).close().cutThruAll()

    total_pin_length = params["pin"]["length_above_board"] + params["pin"][
        "length_below_board"]
    pin = cq.Workplane("XY").workplane(offset=-params["pin"]["length_below_board"]).box(params["pin"]["width"], \
             params["pin"]["width"], total_pin_length, centered = (True,True,False))

    pin = pin.edges("#Z").chamfer(params["pin"]["end_chamfer"])
    pins_union = cq.Workplane("XY").workplane(
        offset=-params["pin"]["length_below_board"])

    for x in range(params["pins"]):
        pins_union = pins_union.union(
            pin.translate((x * params["pitch"], 0, 0)))

    show(body)
    show(pins_union)

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui, objs[0], body_color)
    Color_Objects(Gui, objs[1], pin_union_color)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]

    material_substitutions = {
        col_body[:-1]: body_color_key,
        col_pin[:-1]: pin_union_color_key,
    }
    expVRML.say(material_substitutions)

    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)

    doc.Label = model_name
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = model_name
    restore_Main_Tools()

    doc.Label = model_name

    #save the STEP file
    exportSTEP(doc, full_model_name, out_dir)
    global LIST_license
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', full_model_name+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + '/' + full_model_name + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)
    pinmark = pinmark.translate(((-(length / 2 - pin_band - 1.5 * pm), 0,
                                  height - 2 * pin_thickness - height * 0.02)))

    return (case, pins, pinmark)


# The dimensions of the box. These can be modified rather than changing the
# object's code directly.

#import step_license as L
import add_license as Lic

# when run from command line
if __name__ == "__main__" or __name__ == "main_generator":
    destination_dir = '/RF_Antenna.3dshapes'
    expVRML.say(expVRML.__file__)
    FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')

    full_path = os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir = os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name = full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir = sub_path + "_3Dmodels"
    #expVRML.say(models_dir)
    #stop
def run():
    ## # get variant names from command line

    return

#import step_license as L
import add_license as Lic

# when run from command line
if __name__ == "__main__" or __name__ == "main_generator":

    FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')

    full_path=os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name =full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir=sub_path + "_3Dmodels"
    
    if not os.path.exists(models_dir):
        os.makedirs(models_dir)
    
    if len(sys.argv) < 3:
        FreeCAD.Console.PrintMessage('No variant name is given! building serie BX0036\r\n')
def export_one_part(params, series_definition, log):
    ModelName = params.modelName
    footprint_dir = series_definition.footprint_dir
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')

    print('\n######################### {:s} ###########################\n'.format(ModelName))

    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    App.ActiveDocument=App.getDocument(CheckedModelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedModelName)

    color_keys = [
        series_definition.body_color_key,
        series_definition.pins_color_key,
        series_definition.mark_color_key
    ]
    colors = [shaderColors.named_colors[key].getDiffuseInt() for key in color_keys]

    body, pins, mark = make_gw(params)

    show(body, colors[0]+(0,))
    show(pins, colors[1]+(0,))
    show(mark, colors[2]+(0,))

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions={
        col_body[:-1]:series_definition.body_color_key,
        col_pin[:-1]:series_definition.pins_color_key,
        col_mark[:-1]:series_definition.mark_color_key
    }

    if (color_pin_mark==True) and (place_pinMark==True):
        CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[2].Name)
    else:
        #removing pinMark
        App.getDocument(doc.Name).removeObject(objs[2].Name)

    objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label=CheckedModelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label=CheckedModelName

    restore_Main_Tools()
    #rotate if required
    if (params.rotation!=0):
        rot= params.rotation
        z_RotateObject(doc, rot)

    if no_export:
        return

    out_dir='{:s}{:s}.3dshapes'.format(global_3dpath, series_definition.lib_name)

    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, ModelName, out_dir)
    global LIST_license
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                         STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)
    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs=GetListOfObjects(FreeCAD, doc)
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+ModelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)
    # Save the doc in Native FC format
    footprint_dir = series_definition.footprint_dir
    if footprint_dir is not None and os.path.isdir(footprint_dir) \
            and not save_memory and not check_Model:
        #expVRML.say (ModelName)
        #stop
        sys.argv = ["fc", "dummy", footprint_dir+os.sep+ModelName, "savememory"]
        #setup = get_setup_file()  # << You need the parentheses
        expVRML.say(sys.argv[2])
        ksu_already_loaded=False
        ksu_present=False
        for i in QtGui.qApp.topLevelWidgets():
            if i.objectName() == "kicadStepUp":
                ksu_already_loaded=True
        ksu_tab = FreeCADGui.getMainWindow().findChild(QtGui.QDockWidget, "kicadStepUp") #"kicad StepUp 3D tools")
        if ksu_tab:
            ksu_already_loaded=True
        if ksu_already_loaded!=True:
            try:
                import kicadStepUptools
                ksu_present=True
                ksu_already_loaded=True
                kicadStepUptools.KSUWidget.close()
                #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                #kicadStepUptools.KSUWidget.destroy()
                #for i in QtGui.qApp.topLevelWidgets():
                #    if i.objectName() == "kicadStepUp":
                #        i.deleteLater()
                kicadStepUptools.KSUWidget.close()
            except:
                ksu_present=False
                expVRML.say("ksu not present")
        else:
            kicadStepUptools.KSUWidget.close()
            reload(kicadStepUptools)
            kicadStepUptools.KSUWidget.close()
            #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
            #kicadStepUptools.KSUWidget.destroy()

    saveFCdoc(App, Gui, doc, ModelName,out_dir)

    #FreeCADGui.activateWorkbench("PartWorkbench")
    if save_memory == False and check_Model==False:
        FreeCADGui.SendMsgToActiveView("ViewFit")
        FreeCADGui.activeDocument().activeView().viewAxometric()

    if save_memory == True or check_Model==True:
        doc=FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)

    if check_Model==True:
        runGeometryCheck(App, Gui, out_dir+'/'+ ModelName+".step",
            log, ModelName, save_memory=save_memory)
Exemple #19
0
        else:
            Pads = Pads.union(cq.Workplane("XY").box(pads[Pad][0], pads[Pad][1], P, centered=(True, True, False)).translate((pads[Pad][2],pads[Pad][3],R)).edges("<Z").fillet(P*0.9))
    case = case.union(Pads)
    return (case, die)
    


# The dimensions of the box. These can be modified rather than changing the
# object's code directly.

#import step_license as L
import add_license as Lic

# when run from command line
if __name__ == "__main__" or __name__ == "main_generator":
    expVRML.say(expVRML.__file__)
    FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')

    full_path=os.path.realpath(__file__)
    expVRML.say(full_path)
    scriside_pins_Thicknessdir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name =full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir=sub_path+"_3Dmodels"
    #expVRML.say(models_dir)
    #stop
Exemple #20
0
def make_3D_model(models_dir, model_class, modelName):
    r"""Creates a 3D model and exports it to STEO and VRML.
    :param models_dir: directory name for STEP and VRML 3D model file export
    :type  models_dir: ``string``
    :param model_class: Class containing functions and parameter to generate the 3D model
    :type  model_class: ``class``
    :param modelName: The KiCad file name of the 3D model. 
    :type  modelName: ``string``

    """
    if not model_class.isValidModel ():
        FreeCAD.Console.PrintMessage("Model: " + modelName + ' has invalid parameter and was skipped.\r\n')
        return

    LIST_license = ["",]

    CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedmodelName)
    App.setActiveDocument(CheckedmodelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedmodelName)
    destination_dir = model_class.get_dest_3D_dir()
    
    material_substitutions = model_class.make_3D_model()
    
    doc = FreeCAD.ActiveDocument
    doc.Label = CheckedmodelName

    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedmodelName
    restore_Main_Tools()

    script_dir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(models_dir)
    out_dir=models_dir+os.sep+destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    exportSTEP(doc, modelName, out_dir)
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', modelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,modelName,scale,out_dir)
    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir + os.sep + modelName + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    #expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)
    #scale=0.3937001
    #exportVRML(doc,modelName,scale,out_dir)
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, modelName,out_dir)
    #display BBox
    Gui.activateWorkbench("PartWorkbench")
    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()
Exemple #21
0
        say("Nothing specified to build...")
        pins = cq_cad_tools.getListOfNumbers("10")
    else:
        arg = sys.argv[2]
        if arg.lower() == "all":
            close_doc = True
            pins = range(2, 41)
        else:
            pins = cq_cad_tools.getListOfNumbers(sys.argv[2])

    for pin in pins:
        MakeHeader(pin)
        App.setActiveDocument(docname)
        doc = FreeCAD.ActiveDocument
        if close_doc:  #closing doc to avoid memory leak
            expVRML.say("closing doc to save memory")
            expVRML.say(docname)
            App.closeDocument(doc.Name)
            App.setActiveDocument("")
            App.ActiveDocument = None
            Gui.ActiveDocument = None
        #if int(pin)==20:
        #    stop
    #if close_doc: #closing doc to avoid memory leak
    #    sys.exit(0)

# when run from freecad-cadquery
if __name__ == "temp.module":
    pass
    #ModelName="mypin"
    ## Newdoc = FreeCAD.newDocument(ModelName)
def make_3D_model(models_dir, variant):

    LIST_license = ["",]
    modelName = all_params[variant].modelName

    CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedmodelName)
    App.setActiveDocument(CheckedmodelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedmodelName)

    if (all_params[variant].serie == 'RV_Disc'):
        case = make_case_RV_Disc(all_params[variant])
        pins = make_pins_RV_Disc(all_params[variant])
        show(case)
        show(pins)
    else:
        print("Serie " + all_params[variant].serie + " is not supported")
        FreeCAD.Console.PrintMessage('\r\nSerie ' + all_params[variant].serie + ' is not supported\r\n')
        sys.exit()


    #show(pinmark)
    #stop
    doc = FreeCAD.ActiveDocument
    objs=GetListOfObjects(FreeCAD, doc)
    
    FreeCAD.Console.PrintMessage('#1\r\n')

    body_color_key = all_params[variant].body_color_key
    pin_color_key = all_params[variant].pin_color_key

    body_color = shaderColors.named_colors[body_color_key].getDiffuseFloat()
    pin_color = shaderColors.named_colors[pin_color_key].getDiffuseFloat()

    FreeCAD.Console.PrintMessage('#2\r\n')

    Color_Objects(Gui,objs[0],body_color)
    Color_Objects(Gui,objs[1],pin_color)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]

    FreeCAD.Console.PrintMessage('#3\r\n')
    
    material_substitutions={
        col_body[:-1]:body_color_key,
        col_pin[:-1]:pin_color_key
    }

    expVRML.say(material_substitutions)
    while len(objs) > 1:
            FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
            del objs
            objs = GetListOfObjects(FreeCAD, doc)
    doc.Label = CheckedmodelName

    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedmodelName
    restore_Main_Tools()

    script_dir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(models_dir)
    out_dir=models_dir+destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    exportSTEP(doc, modelName, out_dir)
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', modelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    FreeCAD.Console.PrintMessage('#4\r\n')

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,modelName,scale,out_dir)
    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+modelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    #expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)
    #scale=0.3937001
    #exportVRML(doc,modelName,scale,out_dir)
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, modelName,out_dir)
    #display BBox
    Gui.activateWorkbench("PartWorkbench")
    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()
Exemple #23
0
    def makeModel(self,
                  models_dir,
                  genericName,
                  model,
                  keepDocument=True,
                  verbose=False):
        r"""Creates a model by calling an instance of a model generator class and writes out the model files

        .. note:: normally this method will be called by :func:`makeModels` but may be used directly

        :param models_dir:
            directory to write the created step and wrl files
        :type models_dir: ``str``

        :param genericName:
            the generic name from the base parameter list, may be used to create the model name
        :type  genericName: ``str``

        :param model:
            an instance of the model class to use
        :type   model: ``class instance`` inherited from :class:`cq_base_model.PartBase`

        :param keepDocument:
            * True: the FreeCAD document will shown after it is created, optionally with kicadStepUptools activated
            * False: the document window will be closed
        :type  keepDocument: ``boolean``

        """

        global kicadStepUptools

        modelName = model.makeModelName(genericName)

        FreeCAD.Console.PrintMessage('\r\n' + modelName)

        if model.make_me != True:
            FreeCAD.Console.PrintMessage(' - not made')
            return
        CheckedmodelName = modelName.replace('.',
                                             '').replace('-', '_').replace(
                                                 '(', '').replace(')', '')
        FreeCAD.newDocument(CheckedmodelName)
        FreeCAD.setActiveDocument(CheckedmodelName)
        Gui.ActiveDocument = Gui.getDocument(CheckedmodelName)

        model.make()

        doc = FreeCAD.ActiveDocument
        objs = GetListOfObjects(FreeCAD, doc)

        material_substitutions = {}

        for i in range(0, len(objs)):
            Color_Objects(
                Gui, objs[i], shaderColors.named_colors[
                    model.color_keys[i]].getDiffuseFloat())
            material_substitutions[Gui.ActiveDocument.getObject(
                objs[i].Name).DiffuseColor[0][:-1]] = model.color_keys[i]

        if verbose:
            expVRML.say(material_substitutions)
            expVRML.say(model.color_keys)
            expVRML.say(model.offsets)

        doc.Label = CheckedmodelName

        while len(objs) > 1:
            FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                             objs[1].Name)
            del objs
            objs = GetListOfObjects(FreeCAD, doc)

        objs[0].Label = CheckedmodelName
        restore_Main_Tools()

        #rotate if required
        if (model.rotation != 0):
            z_RotateObject(doc, model.rotation)

        s = objs[0].Shape
        shape = s.copy()
        shape.Placement = s.Placement
        shape.translate(model.offsets)
        objs[0].Placement = shape.Placement

        out_dir = models_dir + os.sep + model.destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)

        # Export STEP model
        exportSTEP(doc, modelName, out_dir)

        license_txt = list(
            add_license.LIST_int_license if self.license is None else
            self.license)  # make a copy to avoid modifying the original
        license_txt.append("")
        license_txt.append("")
        if self.scriptsource != "" and self.script_dir is not None:
            license_txt.append("Generated by script, source at:")
            license_txt.append(self.scriptsource +
                               self.script_dir.split(os.sep)[-1])
            license_txt.append("")

        if verbose:
            expVRML.say("")

        add_license.addLicenseToStep(out_dir + os.sep, modelName + ".step",
                                     license_txt, model.licAuthor,
                                     model.licEmail, model.licOrgSys,
                                     model.licOrg, model.licPreProc)

        # Scale and export Vrml model
        scale = 1.0 / 2.54
        objs = GetListOfObjects(FreeCAD, doc)
        if verbose:
            expVRML.say(
                "######################################################################"
            )
            expVRML.say(objs)
            expVRML.say(
                "######################################################################"
            )
        export_objects, used_color_keys = expVRML.determineColors(
            Gui, objs, material_substitutions)
        export_file_name = out_dir + os.sep + modelName + '.wrl'
        colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
        expVRML.writeVRMLFile(colored_meshes, export_file_name,
                              used_color_keys, license_txt)

        # Save the doc in native FC format
        out_dir = self.models_src_dir + os.sep + model.destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)

        saveFCdoc(FreeCAD, Gui, doc, modelName, out_dir)

        # Place on footprint for verification
        if keepDocument and model.footprints_dir is not None and self.footprints_dir is not None:

            sys.argv = [
                "fc", "dummy", self.footprints_dir + os.sep +
                model.footprints_dir + os.sep + modelName, "savememory"
            ]

            if verbose:
                expVRML.say('Footprint: ' + sys.argv[2])

            if self.kicadStepUptools is None:
                try:
                    import kicadStepUptools
                    expVRML.say("ksu present!")
                    self.kicadStepUptools = True
                    kicadStepUptools.KSUWidget.close()
                    #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                    #kicadStepUptools.KSUWidget.destroy()
                    #for i in QtGui.qApp.topLevelWidgets():
                    #    if i.objectName() == "kicadStepUp":
                    #        i.deleteLater()
                    #kicadStepUptools.KSUWidget.close()
                except:
                    self.kicadStepUptools = False
                    expVRML.say("ksu not present")

            if not self.kicadStepUptools == False:
                kicadStepUptools.KSUWidget.close()
                reload_lib(kicadStepUptools)
                kicadStepUptools.KSUWidget.close()
                #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                #kicadStepUptools.KSUWidget.destroy()

        #display BBox
        if keepDocument:
            Gui.activateWorkbench("PartWorkbench")
            Gui.SendMsgToActiveView("ViewFit")
            Gui.activeDocument().activeView().viewAxometric()
        else:
            doc = FreeCAD.ActiveDocument
            FreeCAD.closeDocument(doc.Name)
    #show(pins)
    #sleep
    # extract pins from case
    #case = case.cut(pins)
    case_bot = case_bot.cut(pins)

    return (case_bot, case, pins, pinmark)

#import step_license as L
import add_license as Lic

# when run from command line
if __name__ == "__main__" or __name__ == "main_generator":
    
    global save_memory #reducing memory consuming for all generation params 
    expVRML.say(expVRML.__file__)
    FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')

    full_path=os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name =full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir=sub_path+"_3Dmodels"

    color_pin_mark=True
def make_3D_model(models_dir, model_class, modelName):

    LIST_license = [
        "",
    ]

    CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace(
        '(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedmodelName)
    App.setActiveDocument(CheckedmodelName)
    Gui.ActiveDocument = Gui.getDocument(CheckedmodelName)
    destination_dir = model_class.get_dest_3D_dir(modelName)

    model_filename = model_class.get_dest_file_name(modelName)

    material_substitutions = model_class.make_3D_model(modelName)

    doc = FreeCAD.ActiveDocument
    doc.Label = CheckedmodelName

    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedmodelName
    restore_Main_Tools()

    script_dir = os.path.dirname(os.path.realpath(__file__))
    expVRML.say(models_dir)
    out_dir = models_dir + os.sep + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    exportSTEP(doc, model_filename, out_dir)
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', model_filename+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,model_filename,scale,out_dir)
    del objs
    objs = GetListOfObjects(FreeCAD, doc)
    expVRML.say(
        "######################################################################"
    )
    expVRML.say(objs)
    expVRML.say(
        "######################################################################"
    )
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + model_filename + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)
    Gui.activateWorkbench("PartWorkbench")
    #
    if save_memory == False:
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()

    check_Model = True
    if save_memory == True:
        check_Model = True
        doc = FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)

    step_path = os.path.join(out_dir, model_filename + u'.step')
    if check_Model == True:
        #ImportGui.insert(step_path,model_filename)
        ImportGui.open(step_path)
        docu = FreeCAD.ActiveDocument
        if cq_cad_tools.checkUnion(docu) == True:
            FreeCAD.Console.PrintMessage('step file for ' + model_filename +
                                         ' is correctly Unioned\n')
        else:
            FreeCAD.Console.PrintError('step file ' + model_filename +
                                       ' is NOT Unioned\n')
            FreeCAD.closeDocument(docu.Name)
            sys.exit()

    saveFCdoc(App, Gui, docu, model_filename, out_dir, False)

    if save_memory == True:
        FreeCAD.closeDocument(docu.Name)
def MakeHeader(n, model, all_params):
    global formerDOC
    global LIST_license
    ModelName = model.replace('yy', "{n:02}".format(n=n))

    full_path=os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name =full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir=sub_path+"_3Dmodels"
    script_dir=os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir=models_dir+all_params[model]['output_directory']
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
   
    newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    App.ActiveDocument=App.getDocument(CheckedModelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedModelName)
    
    header_type = all_params[model]['type']
    pitch = all_params[model]['pitch']
    rows = all_params[model]['rows']
    base_width = all_params[model]['base_width']
    base_height = all_params[model]['base_height']
    base_chamfer = all_params[model]['base_chamfer']
    pin_width = all_params[model]['pin_width']
    pin_length_above_base = all_params[model]['pin_length_above_base']
    
    pin_end_chamfer = all_params[model]['pin_end_chamfer']
    rotation = all_params[model]['rotation']
    
    if base_chamfer == 'auto':
        base_chamfer = pitch/10.

    if pin_end_chamfer == 'auto':
        pin_end_chamfer = pin_width/4.

    if header_type == 'Vertical_THT':
        pin_length_below_board = all_params[model]['pin_length_below_board']
        base = make_Vertical_THT_base(n, pitch, rows, base_width, base_height, base_chamfer)
        pins = make_Vertical_THT_pins(n, pitch, rows, pin_length_above_base, pin_length_below_board, base_height, pin_width, pin_end_chamfer)
    elif header_type == 'Horizontal_THT':
        pin_length_below_board = all_params[model]['pin_length_below_board']
        base_x_offset = all_params[model]['base_x_offset']
        base = make_Horizontal_THT_base(n, pitch, rows, base_width, base_height, base_x_offset, base_chamfer)
        pins = make_Horizontal_THT_pins(n, pitch, rows, pin_length_above_base, pin_length_below_board, base_height, base_width, pin_width, pin_end_chamfer, base_x_offset)
    elif header_type == 'Vertical_SMD':
        pin_length_horizontal = all_params[model]['pin_length_horizontal']
        base_z_offset = all_params[model]['base_z_offset']
        if rows == 1:
            pin_1_start = all_params[model]['pin_1_start']
        else:
            pin_1_start = None
        pins = make_Vertical_SMD_pins(n, pitch, rows, pin_length_above_base, pin_length_horizontal, base_height, base_width, pin_width, pin_end_chamfer, base_z_offset, pin_1_start)
        base = make_Vertical_SMD_base(n, pitch, base_width, base_height, base_chamfer, base_z_offset)
    else:
        print 'Header type: '
        print header_type
        print ' is not recognized, please check parameters'
        stop

    show(base)
    show(pins)

    doc = FreeCAD.ActiveDocument
    objs=GetListOfObjects(FreeCAD, doc)
    
    Color_Objects(Gui,objs[0],body_color)
    Color_Objects(Gui,objs[1],pins_color)
    #Color_Objects(Gui,objs[2],marking_color)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions={
        col_body[:-1]:body_color_key,
        col_pin[:-1]:pins_color_key,
        #col_mark[:-1]:marking_color_key
    }
    expVRML.say(material_substitutions)

    #objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui,
                   doc.Name, objs[0].Name, objs[1].Name)
    doc.Label=CheckedModelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label=CheckedModelName
    restore_Main_Tools()

    if (rotation !=0):
        z_RotateObject(doc, rotation)
    
    #out_dir = models_dir+"/generated_pinheaders"
    
    doc.Label = CheckedModelName
    
    #save the STEP file
    exportSTEP(doc, ModelName, out_dir)
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)
    
    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+ModelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    #save the VRML file
    #scale=0.3937001
    #exportVRML(doc,name,scale,out_dir)
    
    if save_memory == False:
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()

    # Save the doc in Native FC format 
    saveFCdoc(App, Gui, doc, ModelName, out_dir, False) 
    
    check_Model=True
    if save_memory == True or check_Model==True:
        doc=FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)
    step_path=os.path.join(out_dir,ModelName+u'.step')
    if check_Model==True:
        #ImportGui.insert(step_path,ModelName)
        ImportGui.open(step_path)
        docu = FreeCAD.ActiveDocument
        if cq_cad_tools.checkUnion(docu) == True:
            FreeCAD.Console.PrintMessage('step file is correctly Unioned\n')
        else:
            FreeCAD.Console.PrintError('step file is NOT Unioned\n')
            stop
        FC_majorV=int(FreeCAD.Version()[0])
        FC_minorV=int(FreeCAD.Version()[1])
        if FC_majorV == 0 and FC_minorV >= 17:
            for o in docu.Objects:
                if hasattr(o,'Shape'):
                    chks=cq_cad_tools.checkBOP(o.Shape)
                    print 'chks ',chks
                    print cq_cad_tools.mk_string(o.Label)
                    if chks != True:
                        msg='shape \''+o.Name+'\' \''+cq_cad_tools.mk_string(o.Label)+'\' is INVALID!\n'
                        FreeCAD.Console.PrintError(msg)
                        FreeCAD.Console.PrintWarning(chks[0])
                        stop
                    else:
                        msg='shape \''+o.Name+'\' \''+cq_cad_tools.mk_string(o.Label)+'\' is valid\n'
                        FreeCAD.Console.PrintMessage(msg)
        else:
            FreeCAD.Console.PrintError('BOP check requires FC 0.17+\n')
            # Save the doc in Native FC format
        saveFCdoc(App, Gui, docu, ModelName,out_dir, False)
        doc=FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)
        
    return 0
def make_case(params):

    ef = params.ef
    cff = params.cff
    cf = params.cf
    fp_r = params.fp_r
    fp_d = params.fp_d
    fp_z = params.fp_z
    D = params.D
    E = params.E
    D1 = params.D1
    E1 = params.E1
    A1 = params.A1
    A2 = params.A2
    A = params.A
    molded = params.molded
    b = params.b
    e = params.e
    ex = params.ex
    sp = params.sp
    npx = params.npx
    npy = params.npy
    mN = params.modelName
    rot = params.rotation
    dest_dir_pref = params.dest_dir_prefix

    if ex == None:
        ex = e
    if ex == 0:
        ex = e

    if params.excluded_pins is not None:
        epl = list(params.excluded_pins)
        #expVRML.say(epl)
        i = 0
        for i in range(0, len(epl)):
            if isinstance(epl[i], int):  #long is not supported in python 3
                epl[i] = str(int(epl[i]))
                i = i + 1
        excluded_pins = tuple(epl)
        #expVRML.say(excluded_pins)
        #stop
    else:
        excluded_pins = ()  ##no pin excluded

    sphere_r = b / 2 * (1.05)  #added extra 0.5% diameter for fusion
    s_center = (0, 0, 0)
    sphere = cq.Workplane("XY", s_center). \
             sphere(sphere_r)
    bpin = sphere.translate((0, 0, b / 2 - sp))

    pins = []
    # create top, bottom side pins
    pincounter = 1
    first_pos_x = (npx - 1) * e / 2
    for j in range(npy):
        for i in range(npx):
            if "internals" in excluded_pins:
                if str(int(pincounter)) not in excluded_pins:
                    if j == 0 or j == npy - 1 or i == 0 or i == npx - 1:
                        pin = bpin.translate((first_pos_x-i*e, (npy*ex/2-ex/2)-j*ex, 0)).\
                                rotate((0,0,0), (0,0,1), 180)
                        pins.append(pin)
            elif str(int(pincounter)) not in excluded_pins:
                pin = bpin.translate((first_pos_x-i*e, (npy*ex/2-ex/2)-j*ex, 0)).\
                        rotate((0,0,0), (0,0,1), 180)
                pins.append(pin)
                #expVRML.say(j)
            pincounter += 1
    expVRML.say(pincounter - 1)

    # merge all pins to a single object
    merged_pins = pins[0]
    for p in pins[1:]:
        merged_pins = merged_pins.union(p)
    pins = merged_pins

    # first pin indicator is created with a spherical pocket
    if fp_r == 0:
        global place_pinMark
        place_pinMark = False
        fp_r = 0.1
    if molded is not None:
        the = 24
        if D1 is None:
            D1 = D * (1 - 0.065)
            E1 = E * (1 - 0.065)
        D1_t = D1 - 2 * tan(radians(the)) * (A - A1 - A2)
        E1_t = E1 - 2 * tan(radians(the)) * (A - A1 - A2)
        # draw the case
        cw = D - 2 * A1
        cl = E - 2 * A1
        case_bot = cq.Workplane("XY").workplane(offset=0)
        case_bot = make_plg(case_bot, cw, cl, cff, cf)
        case_bot = case_bot.extrude(A2 - 0.01)
        case_bot = case_bot.translate((0, 0, A1))
        #show(case_bot)

        case = cq.Workplane("XY").workplane(offset=A1)
        #case = make_plg(case, cw, cl, cce, cce)
        case = make_plg(case, D1, E1, 3 * cf, 3 * cf)
        #case = case.extrude(c-A1)
        case = case.extrude(0.01)
        case = case.faces(">Z").workplane()
        case = make_plg(case, D1, E1, 3*cf, 3*cf).\
            workplane(offset=A-A2-A1)
        case = make_plg(case, D1_t, E1_t, 3*cf, 3*cf).\
            loft(ruled=True)
        # fillet the bottom vertical edges
        if ef != 0:
            case = case.edges("|Z").fillet(ef)
        # fillet top and side faces of the top molded part
        if ef != 0:
            BS = cq.selectors.BoxSelector
            case = case.edges(
                BS((-D1 / 2, -E1 / 2, A2 + 0.001),
                   (D1 / 2, E1 / 2, A + 0.001))).fillet(ef)
            #case = case.edges(BS((-D1/2, -E1/2, c+0.001), (D1/2, E1/2, A+0.001+A1/2))).fillet(ef)
        case = case.translate((0, 0, A2 - 0.01))
        #show(case)
        #stop
        pinmark = cq.Workplane(
            "XZ", (-D / 2 + fp_d + fp_r, -E / 2 + fp_d + fp_r, fp_z)).rect(
                fp_r / 2, -2 * fp_z, False).revolve().translate(
                    (0, 0, A))  #+fp_z))
        pinmark = pinmark.translate(
            ((D - D1_t) / 2 + fp_d + cff, (E - E1_t) / 2 + fp_d + cff, -sp))
        #stop
        if (color_pin_mark == False) and (place_pinMark == True):
            case = case.cut(pinmark)
Exemple #28
0
def make_3D_model(models_dir, variant):

    LIST_license = ["",]
    modelName = all_params[variant].modelName

    CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedmodelName)
    App.setActiveDocument(CheckedmodelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedmodelName)

    case = make_case(all_params[variant])
    casetop = make_case_top(all_params[variant])
    pins = make_pins(all_params[variant])

    show(case)
    show(casetop)
    show(pins)
    #show(pinmark)
    #stop
    doc = FreeCAD.ActiveDocument
    objs=GetListOfObjects(FreeCAD, doc)

    body_color_key = all_params[variant].body_color_key
    body_top_color_key = all_params[variant].body_top_color_key
    pin_color_key = all_params[variant].pin_color_key


    body_color = shaderColors.named_colors[body_color_key].getDiffuseFloat()
    body_top_color = shaderColors.named_colors[body_top_color_key].getDiffuseFloat()
    pin_color = shaderColors.named_colors[pin_color_key].getDiffuseFloat()

    Color_Objects(Gui,objs[0],body_color)
    Color_Objects(Gui,objs[1],body_top_color)
    Color_Objects(Gui,objs[2],pin_color)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_body_top=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]

    material_substitutions={
        col_body[:-1]:body_color_key,
        col_body_top[:-1]:body_top_color_key,
        col_pin[:-1]:pin_color_key
    }

    expVRML.say(material_substitutions)
    while len(objs) > 1:
            FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
            del objs
            objs = GetListOfObjects(FreeCAD, doc)
    doc.Label = CheckedmodelName

    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedmodelName
    restore_Main_Tools()

    script_dir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(models_dir)
    out_dir=models_dir+os.sep+all_params[variant].dest_dir_prefix

    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=modelName)
    exportSTEP(doc, modelName, out_dir)


    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")

    Lic.addLicenseToStep(out_dir, '{:s}.step'.format(modelName),
            LIST_license,
            cq_parameters.LICENCE_Info.STR_licAuthor,
            cq_parameters.LICENCE_Info.STR_licEmail,
            cq_parameters.LICENCE_Info.STR_licOrgSys,
            cq_parameters.LICENCE_Info.STR_licPreProc)

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,modelName,scale,out_dir)
    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+modelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    # expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    # Save the doc in Native FC format
    doc.recompute()
    saveFCdoc(App, Gui, doc, modelName, out_dir)


    #FreeCADGui.activateWorkbench("PartWorkbench")
    if save_memory == False and check_Model==False:
        FreeCADGui.SendMsgToActiveView("ViewFit")
        FreeCADGui.activeDocument().activeView().viewAxometric()

    if save_memory == True or check_Model==True:
        FreeCAD.closeDocument(doc.Name)
        os.remove (out_dir+os.sep+modelName+'.FCStd')

    if check_Model==True:
        with open(out_dir+os.sep+check_log_file, 'a+') as log:
            log.write('# Check report for Molex 3d model genration\n')
            runGeometryCheck(App, Gui, step_path, log, modelName, save_memory=save_memory)
            log.close()
Exemple #29
0
def MakeHeader(n, model, all_params):
    global formerDOC
    global LIST_license
    ModelName = model.replace('yy', "{n:02}".format(n=n))

    full_path=os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name =full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir=sub_path+"_3Dmodels"
    script_dir=os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir=models_dir+all_params[model]['output_directory']
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
   
    newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    App.ActiveDocument=App.getDocument(CheckedModelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedModelName)
    
    header_type = all_params[model]['type']
    pitch = all_params[model]['pitch']
    rows = all_params[model]['rows']
    base_width = all_params[model]['base_width']
    base_height = all_params[model]['base_height']
    base_chamfer = all_params[model]['base_chamfer']
    pin_width = all_params[model]['pin_width']
    pin_length_above_base = all_params[model]['pin_length_above_base']
    
    pin_end_chamfer = all_params[model]['pin_end_chamfer']
    rotation = all_params[model]['rotation']
    
    if base_chamfer == 'auto':
        base_chamfer = pitch/10.

    if pin_end_chamfer == 'auto':
        pin_end_chamfer = pin_width/4.

    if header_type == 'Vertical_THT':
        pin_length_below_board = all_params[model]['pin_length_below_board']
        base = make_Vertical_THT_base(n, pitch, rows, base_width, base_height, base_chamfer)
        pins = make_Vertical_THT_pins(n, pitch, rows, pin_length_above_base, pin_length_below_board, base_height, pin_width, pin_end_chamfer)
    elif header_type == 'Horizontal_THT':
        pin_length_below_board = all_params[model]['pin_length_below_board']
        base_x_offset = all_params[model]['base_x_offset']
        base = make_Horizontal_THT_base(n, pitch, rows, base_width, base_height, base_x_offset, base_chamfer)
        pins = make_Horizontal_THT_pins(n, pitch, rows, pin_length_above_base, pin_length_below_board, base_height, base_width, pin_width, pin_end_chamfer, base_x_offset)
    elif header_type == 'Vertical_SMD':
        pin_length_horizontal = all_params[model]['pin_length_horizontal']
        base_z_offset = all_params[model]['base_z_offset']
        if rows == 1:
            pin_1_start = all_params[model]['pin_1_start']
        else:
            pin_1_start = None
        pins = make_Vertical_SMD_pins(n, pitch, rows, pin_length_above_base, pin_length_horizontal, base_height, base_width, pin_width, pin_end_chamfer, base_z_offset, pin_1_start)
        base = make_Vertical_SMD_base(n, pitch, base_width, base_height, base_chamfer, base_z_offset)
    else:
        print 'Header type: '
        print header_type
        print ' is not recognized, please check parameters'
        stop

    show(base)
    show(pins)

    doc = FreeCAD.ActiveDocument
    objs=GetListOfObjects(FreeCAD, doc)
    
    Color_Objects(Gui,objs[0],body_color)
    Color_Objects(Gui,objs[1],pins_color)
    #Color_Objects(Gui,objs[2],marking_color)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions={
        col_body[:-1]:body_color_key,
        col_pin[:-1]:pins_color_key,
        #col_mark[:-1]:marking_color_key
    }
    expVRML.say(material_substitutions)

    #objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui,
                   doc.Name, objs[0].Name, objs[1].Name)
    doc.Label=CheckedModelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label=CheckedModelName
    restore_Main_Tools()

    if (rotation !=0):
        z_RotateObject(doc, rotation)
    
    #out_dir = models_dir+"/generated_pinheaders"
    
    doc.Label = CheckedModelName
    
    #save the STEP file
    exportSTEP(doc, ModelName, out_dir)
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)
    
    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+ModelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    #save the VRML file
    #scale=0.3937001
    #exportVRML(doc,name,scale,out_dir)
    
    if save_memory == False:
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()

    # Save the doc in Native FC format 
    saveFCdoc(App, Gui, doc, ModelName, out_dir, False) 
    
    check_Model=True
    if save_memory == True or check_Model==True:
        closeCurrentDoc(CheckedModelName)
    step_path=os.path.join(out_dir,ModelName+u'.step')
    if check_Model==True:
        #ImportGui.insert(step_path,ModelName)
        ImportGui.open(step_path)
        docu = FreeCAD.ActiveDocument
        if cq_cad_tools.checkUnion(docu) == True:
            FreeCAD.Console.PrintMessage('step file is correctly Unioned\n')
        else:
            FreeCAD.Console.PrintError('step file is NOT Unioned\n')
            stop
        FC_majorV=int(FreeCAD.Version()[0])
        FC_minorV=int(FreeCAD.Version()[1])
        if FC_majorV == 0 and FC_minorV >= 17:
            for o in docu.Objects:
                if hasattr(o,'Shape'):
                    chks=cq_cad_tools.checkBOP(o.Shape)
                    print 'chks ',chks
                    print cq_cad_tools.mk_string(o.Label)
                    if chks != True:
                        msg='shape \''+o.Name+'\' \''+cq_cad_tools.mk_string(o.Label)+'\' is INVALID!\n'
                        FreeCAD.Console.PrintError(msg)
                        FreeCAD.Console.PrintWarning(chks[0])
                        stop
                    else:
                        msg='shape \''+o.Name+'\' \''+cq_cad_tools.mk_string(o.Label)+'\' is valid\n'
                        FreeCAD.Console.PrintMessage(msg)
        else:
            FreeCAD.Console.PrintError('BOP check requires FC 0.17+\n')
            # Save the doc in Native FC format
        saveFCdoc(App, Gui, docu, ModelName,out_dir, False)
        closeCurrentDoc(docu.Label)
        
    return 0
Exemple #30
0
def export_one_part(params, series_definition, log):
    ModelName = params.modelName
    footprint_dir = series_definition.footprint_dir
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace(
        '(', '').replace(')', '')

    print('\n######################### {:s} ###########################\n'.
          format(ModelName))

    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    App.ActiveDocument = App.getDocument(CheckedModelName)
    Gui.ActiveDocument = Gui.getDocument(CheckedModelName)

    color_keys = [
        series_definition.body_color_key, series_definition.pins_color_key,
        series_definition.mark_color_key
    ]
    colors = [
        shaderColors.named_colors[key].getDiffuseInt() for key in color_keys
    ]

    body, pins, mark = make_gw(params)

    show(body, colors[0] + (0, ))
    show(pins, colors[1] + (0, ))
    show(mark, colors[2] + (0, ))

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    col_mark = Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions = {
        col_body[:-1]: series_definition.body_color_key,
        col_pin[:-1]: series_definition.pins_color_key,
        col_mark[:-1]: series_definition.mark_color_key
    }

    if (color_pin_mark == True) and (place_pinMark == True):
        CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                        objs[2].Name)
    else:
        #removing pinMark
        App.getDocument(doc.Name).removeObject(objs[2].Name)

    objs = GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = CheckedModelName
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedModelName

    restore_Main_Tools()
    #rotate if required
    if (params.rotation != 0):
        rot = params.rotation
        z_RotateObject(doc, rot)

    if no_export:
        return

    out_dir = '{:s}{:s}.3dshapes'.format(global_3dpath,
                                         series_definition.lib_name)

    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, ModelName, out_dir)
    global LIST_license
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                         STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)
    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + ModelName + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)
    # Save the doc in Native FC format
    footprint_dir = series_definition.footprint_dir
    if footprint_dir is not None and os.path.isdir(footprint_dir) \
            and not save_memory and not check_Model:
        #expVRML.say (ModelName)
        #stop
        sys.argv = [
            "fc", "dummy", footprint_dir + os.sep + ModelName, "savememory"
        ]
        #setup = get_setup_file()  # << You need the parentheses
        expVRML.say(sys.argv[2])
        ksu_already_loaded = False
        ksu_present = False
        for i in QtGui.qApp.topLevelWidgets():
            if i.objectName() == "kicadStepUp":
                ksu_already_loaded = True
        ksu_tab = FreeCADGui.getMainWindow().findChild(
            QtGui.QDockWidget, "kicadStepUp")  #"kicad StepUp 3D tools")
        if ksu_tab:
            ksu_already_loaded = True
        if ksu_already_loaded != True:
            try:
                import kicadStepUptools
                ksu_present = True
                ksu_already_loaded = True
                kicadStepUptools.KSUWidget.close()
                #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                #kicadStepUptools.KSUWidget.destroy()
                #for i in QtGui.qApp.topLevelWidgets():
                #    if i.objectName() == "kicadStepUp":
                #        i.deleteLater()
                kicadStepUptools.KSUWidget.close()
            except:
                ksu_present = False
                expVRML.say("ksu not present")
        else:
            kicadStepUptools.KSUWidget.close()
            reload(kicadStepUptools)
            kicadStepUptools.KSUWidget.close()
            #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
            #kicadStepUptools.KSUWidget.destroy()

    saveFCdoc(App, Gui, doc, ModelName, out_dir)

    #FreeCADGui.activateWorkbench("PartWorkbench")
    if save_memory == False and check_Model == False:
        FreeCADGui.SendMsgToActiveView("ViewFit")
        FreeCADGui.activeDocument().activeView().viewAxometric()

    if save_memory == True or check_Model == True:
        doc = FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)

    if check_Model == True:
        runGeometryCheck(App,
                         Gui,
                         out_dir + '/' + ModelName + ".step",
                         log,
                         ModelName,
                         save_memory=save_memory)
    merged_pins=merged_pins.union(bpin1)
    merged_pins=merged_pins.union(bpin2)
    merged_pins=merged_pins.union(bpinv)
    pins = merged_pins

    #show(pins)
    #sleep

    return (body, pins, pinmark)

#import step_license as L
import add_license as Lic

# when run from command line 
if __name__ == "__main__" or __name__ == "main_generator": 
    expVRML.say(expVRML.__file__)
    FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')

    full_path=os.path.realpath(__file__) 
    expVRML.say(full_path) 
    scriptdir=os.path.dirname(os.path.realpath(__file__)) 
    expVRML.say(scriptdir) 
    sub_path = full_path.split(scriptdir) 
    expVRML.say(sub_path) 
    sub_dir_name =full_path.split(os.sep)[-2] 
    expVRML.say(sub_dir_name) 
    sub_path = full_path.split(sub_dir_name)[0] 
    expVRML.say(sub_path) 
    models_dir=sub_path+"_3Dmodels" 

    color_pin_mark=True
Exemple #32
0
def generateOneModel(part_params, log):
    place_pinMark = True  ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark)

    FreeCAD.Console.PrintMessage('\n\n##############  ' +
                                 part_params['code_metric'] +
                                 '  ###############\n')
    dim_params = part_params[
        'param_nominal'] if use_nominal_size else part_params['param_max']
    if dim_params == None:
        if show_all:
            if use_nominal_size:
                dim_params = part_params['param_max']
            else:
                dim_params = part_params['param_nominal']
    if dim_params == None:
        FreeCAD.Console.PrintMessage(
            'No params found for current variant. Skipped\n')
        return

    ModelName = model_name_format_str.format(
        prefix=model_name_prefix,
        code_metric=part_params['code_metric'],
        code_letter=part_params['code_letter'],
        old_name=part_params['modelName_old'],
        maui_name=part_params['modelName_maui'])
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace(
        '(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    Gui.ActiveDocument = Gui.getDocument(CheckedModelName)
    body, pins, mark = make_tantalum(dim_params)

    show(body)
    show(pins)
    show(mark)

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui, objs[0], body_color)
    Color_Objects(Gui, objs[1], pins_color)
    Color_Objects(Gui, objs[2], mark_color)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    col_mark = Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions = {
        col_body[:-1]: body_color_key,
        col_pin[:-1]: pins_color_key,
        col_mark[:-1]: mark_color_key
    }
    #expVRML.say(material_substitutions)
    del objs
    objs = GetListOfObjects(FreeCAD, doc)
    if (color_pin_mark == True) and (place_pinMark == True):
        CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                        objs[2].Name)
    else:
        #removing pinMark
        App.getDocument(doc.Name).removeObject(objs[2].Name)
    del objs
    objs = GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = CheckedModelName
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedModelName
    restore_Main_Tools()
    #rotate if required
    if (rotation != 0):
        rot = rotation
        z_RotateObject(doc, rot)
    #out_dir=destination_dir+all_params[variant].dest_dir_prefix+'/'
    script_dir = os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir = models_dir + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, ModelName, out_dir)
    global LIST_license
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + ModelName + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)

    saveFCdoc(App, Gui, doc, ModelName, out_dir)

    #FreeCADGui.activateWorkbench("PartWorkbench")
    if save_memory == False and check_Model == False:
        FreeCADGui.SendMsgToActiveView("ViewFit")
        FreeCADGui.activeDocument().activeView().viewAxometric()

    if save_memory == True or check_Model == True:
        doc = FreeCAD.ActiveDocument
        FreeCAD.closeDocument(doc.Name)

    if check_Model == True:
        step_path = out_dir + '/' + ModelName + ".step"
        runGeometryCheck(App,
                         Gui,
                         step_path,
                         log,
                         ModelName,
                         save_memory=save_memory)
def MakeHeader(n, params):
    global formerDOC
    global LIST_license
    name = HeaderName(n, params)

    # destination_dir="/Pin_Headers"

    full_path = os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir = os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name = full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir = sub_path + "_3Dmodels"
    script_dir = os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir = models_dir + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    #having a period '.' character in the model name REALLY messes with things.
    docname = name.replace(".", "")

    newdoc = App.newDocument(docname)
    App.setActiveDocument(docname)
    App.ActiveDocument = App.getDocument(docname)
    Gui.ActiveDocument = Gui.getDocument(docname)

    baseblock = cq.Workplane("XY").rect(params.p, params.w).extrude(
        params.h).edges("|Z").chamfer(params.p / 10).translate(
            (0, 0, params.hb))
    base = baseblock
    for blocks in range(1, n):
        baseblock = baseblock.translate((params.p, 0, 0))
        base = base.union(baseblock)
        #move the base to the 'middle'
    if params.rows > 1:
        offset = params.p * (params.rows - 1) / 2.0
        base = base.translate((0, offset, 0))

    Inner_point = params.pw / sqrt(2)
    Outer_point = (params.pw * 2) / sqrt(2)
    single_pin = cq.Workplane("YZ", (0,0,0,)). \
    moveTo(params.pw/2,params.pa).line(0,-(params.pa-2*params.pw)).threePointArc((-(params.pw*1.5)+Outer_point,params.pw*2-Outer_point),(-(params.pw*1.5), 0)). \
    line(-(params.ph-2*params.pw),0).line(0,params.pw).line((params.ph-2*params.pw),0).threePointArc((-(params.pw*1.5)+Inner_point,params.pw*2-Inner_point), (-(params.pw/2), params.pw*2)). \
    line(0,params.pa-2*params.pw).close().extrude(params.pw).translate((-params.pw/2,0,0))
    single_pin = single_pin.faces(">Z").chamfer(params.pw / 4)
    single_pin = single_pin.faces("<Y").chamfer(params.pw / 4)
    pins = []
    if params.type:
        if params.type == 'Pin1Left':
            single_pin = single_pin.rotate((0, 0, 0), (0, 0, 1), 180)
        for pincount in range(0, n):
            single_pin = single_pin.rotate((0, 0, 0), (0, 0, 1), 180)
            pin = single_pin.translate((params.p * pincount, 0, 0))
            pins.append(pin)
    else:
        for pincount in range(0, n):
            pin = single_pin.translate((params.p * pincount, 0, 0))
            pins.append(pin)
        single_pin = single_pin.rotate((0, 0, 0), (0, 0, 1), 180)
        for pincount in range(0, n):
            pin = single_pin.translate((params.p * pincount, params.p, 0))
            pins.append(pin)

    merged_pins = pins[0]
    for p in pins[1:]:
        merged_pins = merged_pins.union(p)
    pins = merged_pins
    if params.rows > 1:
        row_offset = -params.p / 2
    else:
        row_offset = 0
    pins = pins.translate((-params.p * (n - 1) / 2, row_offset, 0))
    base = base.translate((-params.p * (n - 1) / 2, row_offset, 0))

    show(base)
    show(pins)

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui, objs[0], body_color)
    Color_Objects(Gui, objs[1], pins_color)
    #Color_Objects(Gui,objs[2],marking_color)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions = {
        col_body[:-1]: body_color_key,
        col_pin[:-1]: pins_color_key,
        #col_mark[:-1]:marking_color_key
    }
    expVRML.say(material_substitutions)

    ##assign some colors
    #base_color = (50,50,50)
    #pins_color = (225,175,0)
    #
    #show(base,base_color+(0,))
    #show(pins,pins_color+(0,))

    #objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = docname
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = docname
    restore_Main_Tools()

    if (params.rot != 0):
        z_RotateObject(doc, params.rot)

    #out_dir = models_dir+"/generated_pinheaders"

    doc.Label = docname

    #save the STEP file
    exportSTEP(doc, name, out_dir)
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', name+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)
    expVRML.say(
        "######################################################################"
    )
    expVRML.say(objs)
    expVRML.say(
        "######################################################################"
    )
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + name + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)

    #save the VRML file
    #scale=0.3937001
    #exportVRML(doc,name,scale,out_dir)

    if save_memory == False:
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()

    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, name, out_dir)
    if save_memory == True:
        closeCurrentDoc(docname)
    return 0
        #Gui.activeDocument().activeView().viewAxometric()
    saveFCdoc(App, Gui, doc, ModelName,out_dir)

    if save_memory == True or check_Model==True:
        doc=FreeCAD.ActiveDocument
        print("closing: {}".format(doc.Name))
        FreeCAD.closeDocument(doc.Name)

    if check_Model==True:
        step_path = out_dir + '/' + ModelName + ".step"
        runGeometryCheck(App, Gui, step_path,
            log, ModelName, save_memory=save_memory)

# when run from command line
if __name__ == "__main__" or __name__ == "main_generator":
    expVRML.say(expVRML.__file__)
    FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')

    full_path=os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name =full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir=sub_path+"_3Dmodels"

    color_pin_mark=True
def make_3D_model(models_dir, variant):

    LIST_license = ["",]

    FreeCAD.Console.PrintMessage("\r\nMaking %s\r\n" % variant)
    modelName = variant
    modelfileName = ''
    CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
    
    Newdoc = App.newDocument(CheckedmodelName)
    App.setActiveDocument(CheckedmodelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedmodelName)

    case = None
    pins = None

    if all_params[variant].modeltype == 'BX0036':
        case = make_case_BX0036(all_params[variant])
        pins = make_pins(all_params[variant])
        show(case)
        show(pins)
        modelfileName = make_modelfileName_Common(all_params[variant])
        #
        #
    elif all_params[variant].modeltype == 'Button1':
        case = make_case_Button1(all_params[variant])
        pins = make_pins(all_params[variant])
        show(case)
        show(pins)
        modelfileName = make_modelfileName_Common(all_params[variant])
        #
        #
    elif all_params[variant].modeltype == 'Button2':
        case = make_case_Button2(all_params[variant])
        pins = make_pins(all_params[variant])
        show(case)
        show(pins)
        modelfileName = make_modelfileName_Common(all_params[variant])
        #
        #
    elif all_params[variant].modeltype == 'Button3':
        case = make_case_Button3(all_params[variant])
        pins = make_pins(all_params[variant])
        show(case)
        show(pins)
        modelfileName = make_modelfileName_Common(all_params[variant])
        #
        #
    elif all_params[variant].modeltype == 'Button4':
        case = make_case_Button4(all_params[variant])
        pins = make_pins(all_params[variant])
        show(case)
        show(pins)
        modelfileName = make_modelfileName_Common(all_params[variant])
        #
        #
    elif all_params[variant].modeltype == 'Cylinder1':
        case = make_case_Cylinder1(all_params[variant])
        pins = make_pins(all_params[variant])
        show(case)
        show(pins)
        modelfileName = make_modelfileName_Common(all_params[variant])
        #
        #
    elif variant == 'Seiko_MS621F':
        case = make_case_Seiko_MS621F(all_params[variant])
        pins = make_pins_Seiko_MS621F(all_params[variant])
        show(case)
        show(pins)
        modelfileName = make_modelfileName_Common(all_params[variant])
        #
        #
    elif variant == 'Keystone_2993':
        case = make_case_Keystone_2993(all_params[variant])
        pins = make_pins_Keystone_2993(all_params[variant])
        show(case)
        show(pins)
        modelfileName = make_modelfileName_Common(all_params[variant])
        #
        #
    else:
        FreeCAD.Console.PrintMessage("\r\nSerie %s does not exist, skipping'\r\n" % all_params[variant].serie)
        return

    #show(pinmark)
    #stop
    doc = FreeCAD.ActiveDocument
    objs=GetListOfObjects(FreeCAD, doc)

    body_color_key = all_params[variant].body_color_key
    pin_color_key = all_params[variant].pin_color_key

    body_color = shaderColors.named_colors[body_color_key].getDiffuseFloat()
    pin_color = shaderColors.named_colors[pin_color_key].getDiffuseFloat()

    Color_Objects(Gui,objs[0],body_color)
    Color_Objects(Gui,objs[1],pin_color)

    col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]

    material_substitutions={
        col_body[:-1]:body_color_key,
        col_pin[:-1]:pin_color_key
    }

    expVRML.say(material_substitutions)
    while len(objs) > 1:
            FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
            del objs
            objs = GetListOfObjects(FreeCAD, doc)
    doc.Label = CheckedmodelName

    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedmodelName
    restore_Main_Tools()

    script_dir=os.path.dirname(os.path.realpath(__file__))
    expVRML.say(models_dir)
    out_dir=models_dir + os.sep +  all_params[variant].dest_dir_prefix
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    exportSTEP(doc, modelfileName, out_dir)
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir + os.sep, modelfileName + ".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc, modelfileName,scale,out_dir)
    del objs
    objs=GetListOfObjects(FreeCAD, doc)
    expVRML.say("######################################################################")
    expVRML.say(objs)
    expVRML.say("######################################################################")
    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir + os.sep + modelfileName + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    #expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)
    #scale=0.3937001
    #exportVRML(doc, modelfileName,scale,out_dir)
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, modelfileName, out_dir)
    #display BBox
    Gui.activateWorkbench("PartWorkbench")
    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()
def make_case(params):

    ef  = params.ef
    cff = params.cff
    cf = params.cf
    fp_r  = params.fp_r
    fp_d  = params.fp_d
    fp_z  = params.fp_z
    D  = params.D
    E   = params.E
    D1  = params.D1
    E1  = params.E1
    A1  = params.A1
    A2  = params.A2
    A  = params.A
    molded = params.molded
    b   = params.b
    e   = params.e
    ex   = params.ex
    sp   = params.sp
    npx = params.npx
    npy = params.npy
    mN  = params.modelName
    rot = params.rotation
    dest_dir_pref = params.dest_dir_prefix

    if ex == None:
        ex = e
    if ex == 0:
        ex = e

    if params.excluded_pins is not None:
        epl = list(params.excluded_pins)
        #expVRML.say(epl)
        i=0
        for i in range (0, len(epl)):
            if isinstance(epl[i], ( int, long )):
                epl[i]=str(int(epl[i]))
                i=i+1
        excluded_pins=tuple(epl)
        #expVRML.say(excluded_pins)
        #stop
    else:
        excluded_pins=() ##no pin excluded


    sphere_r = b/2 *(1.05) #added extra 0.5% diameter for fusion
    s_center =(0,0,0)
    sphere = cq.Workplane("XY", s_center). \
             sphere(sphere_r)
    bpin=sphere.translate((0,0,b/2-sp))

    pins = []
    # create top, bottom side pins
    pincounter = 1
    first_pos_x = (npx-1)*e/2
    for j in range(npy):
        for i in range(npx):
            if "internals" in excluded_pins:
                if str(int(pincounter)) not in excluded_pins:
                    if j==0 or j==npy-1 or i==0 or i==npx-1:
                        pin = bpin.translate((first_pos_x-i*e, (npy*ex/2-ex/2)-j*ex, 0)).\
                                rotate((0,0,0), (0,0,1), 180)
                        pins.append(pin)
            elif str(int(pincounter)) not in excluded_pins:
                pin = bpin.translate((first_pos_x-i*e, (npy*ex/2-ex/2)-j*ex, 0)).\
                        rotate((0,0,0), (0,0,1), 180)
                pins.append(pin)
                #expVRML.say(j)
            pincounter += 1
    expVRML.say(pincounter-1)

    # merge all pins to a single object
    merged_pins = pins[0]
    for p in pins[1:]:
        merged_pins = merged_pins.union(p)
    pins = merged_pins

    # first pin indicator is created with a spherical pocket
    if fp_r == 0:
        global place_pinMark
        place_pinMark=False
        fp_r = 0.1
    if molded is not None:
        the=24
        if D1 is None:
            D1=D*(1-0.065)
            E1=E*(1-0.065)
        D1_t = D1-2*tan(radians(the))*(A-A1-A2)
        E1_t = E1-2*tan(radians(the))*(A-A1-A2)
        # draw the case
        cw = D-2*A1
        cl = E-2*A1
        case_bot = cq.Workplane("XY").workplane(offset=0)
        case_bot= make_plg(case_bot, cw, cl, cff, cf)
        case_bot = case_bot.extrude(A2-0.01)
        case_bot = case_bot.translate((0,0,A1))
        #show(case_bot)

        case = cq.Workplane("XY").workplane(offset=A1)
        #case = make_plg(case, cw, cl, cce, cce)
        case = make_plg(case, D1, E1, 3*cf, 3*cf)
        #case = case.extrude(c-A1)
        case = case.extrude(0.01)
        case = case.faces(">Z").workplane()
        case = make_plg(case, D1, E1, 3*cf, 3*cf).\
            workplane(offset=A-A2-A1)
        case = make_plg(case, D1_t, E1_t, 3*cf, 3*cf).\
            loft(ruled=True)
        # fillet the bottom vertical edges
        if ef!=0:
            case = case.edges("|Z").fillet(ef)
        # fillet top and side faces of the top molded part
        if ef!=0:
            BS = cq.selectors.BoxSelector
            case = case.edges(BS((-D1/2, -E1/2, A2+0.001), (D1/2, E1/2, A+0.001))).fillet(ef)
            #case = case.edges(BS((-D1/2, -E1/2, c+0.001), (D1/2, E1/2, A+0.001+A1/2))).fillet(ef)
        case = case.translate((0,0,A2-0.01))
        #show(case)
        #stop
        pinmark=cq.Workplane("XZ", (-D/2+fp_d+fp_r, -E/2+fp_d+fp_r, fp_z)).rect(fp_r/2, -2*fp_z, False).revolve().translate((0,0,A))#+fp_z))
        pinmark=pinmark.translate(((D-D1_t)/2+fp_d+cff,(E-E1_t)/2+fp_d+cff,-sp))
        #stop
        if (color_pin_mark==False) and (place_pinMark==True):
            case = case.cut(pinmark)
        # extract pins from case
        #case = case.cut(pins)
        case_bot = case_bot.cut(pins)
        ##

    else:
        A2 = A - A1 #body height
        #if m == 0:
        #    case = cq.Workplane("XY").box(D-A1, E-A1, A2)  #margin to see fused pins
        #else:
        case = cq.Workplane("XY").box(D, E, A2)  #NO margin, pins don't emerge
        if ef!=0:
            case.edges("|X").fillet(ef)
            case.edges("|Z").fillet(ef)
        #translate the object
        case=case.translate((0,0,A2/2+A1-sp)).rotate((0,0,0), (0,0,1), 0)

        #sphere_r = (fp_r*fp_r/2 + fp_z*fp_z) / (2*fp_z)
        #sphere_z = A + sphere_r * 2 - fp_z - sphere_r

        pinmark=cq.Workplane("XZ", (-D/2+fp_d+fp_r, -E/2+fp_d+fp_r, fp_z)).rect(fp_r/2, -2*fp_z, False).revolve().translate((0,0,A2+A1-sp))#+fp_z))
        #pinmark=pinmark.translate((0,0,A1-sp))
        #stop
        if (color_pin_mark==False) and (place_pinMark==True):
            case = case.cut(pinmark)
        # extract pins from case
        case = case.cut(pins)
        case_bot = None
        #show(pins)
        #show(pinmark)
        #show(case)
        #stop


    #show(pins)
    #show(case)
    #Gui.SendMsgToActiveView("ViewFit")
    #Gui.activeDocument().activeView().viewBottom()
    #stop
    #sleep

    return (case_bot, case, pins, pinmark)
Exemple #37
0
def make_3D_model(models_dir, variant):

    LIST_license = [
        "",
    ]
    modelName = all_params[variant].modelName

    CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace(
        '(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedmodelName)
    App.setActiveDocument(CheckedmodelName)
    Gui.ActiveDocument = Gui.getDocument(CheckedmodelName)

    case = make_case(all_params[variant])
    casetop = make_case_top(all_params[variant])

    if (all_params[variant].pintype == CASE_THT_TYPE):
        pins = make_pins_tht(all_params[variant])

    if (all_params[variant].pintype == CASE_THT_N_TYPE):
        pins = make_pins_tht_n(all_params[variant])

    if (all_params[variant].pintype == CASE_SMD_TYPE):
        pins = make_pins_smd(all_params[variant])

    show(case)
    show(casetop)
    show(pins)
    #show(pinmark)
    #stop
    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    body_color_key = all_params[variant].body_color_key
    body_top_color_key = all_params[variant].body_top_color_key
    pin_color_key = all_params[variant].pin_color_key

    body_color = shaderColors.named_colors[body_color_key].getDiffuseFloat()
    body_top_color = shaderColors.named_colors[
        body_top_color_key].getDiffuseFloat()
    pin_color = shaderColors.named_colors[pin_color_key].getDiffuseFloat()

    Color_Objects(Gui, objs[0], body_color)
    Color_Objects(Gui, objs[1], body_top_color)
    Color_Objects(Gui, objs[2], pin_color)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_body_top = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]

    material_substitutions = {
        col_body[:-1]: body_color_key,
        col_body_top[:-1]: body_top_color_key,
        col_pin[:-1]: pin_color_key
    }

    expVRML.say(material_substitutions)
    while len(objs) > 1:
        FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name,
                         objs[1].Name)
        del objs
        objs = GetListOfObjects(FreeCAD, doc)
    doc.Label = CheckedmodelName

    del objs
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = CheckedmodelName
    restore_Main_Tools()

    script_dir = os.path.dirname(os.path.realpath(__file__))
    expVRML.say(models_dir)
    out_dir = models_dir + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    exportSTEP(doc, modelName, out_dir)
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', modelName+".step", LIST_license,\
           STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,modelName,scale,out_dir)
    del objs
    objs = GetListOfObjects(FreeCAD, doc)
    expVRML.say(
        "######################################################################"
    )
    expVRML.say(objs)
    expVRML.say(
        "######################################################################"
    )
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + modelName + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    #expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)
    #scale=0.3937001
    #exportVRML(doc,modelName,scale,out_dir)
    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, modelName, out_dir)
    #display BBox
    Gui.activateWorkbench("PartWorkbench")
    Gui.SendMsgToActiveView("ViewFit")
    Gui.activeDocument().activeView().viewAxometric()
def generateOneModel(params, log):
    excluded_pins_x=() ##no pin excluded
    excluded_pins_xmirror=() ##no pin excluded
    place_pinMark=True ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark)


    ModelName = params.modelName
    FreeCAD.Console.PrintMessage(
        '\n\n##############  ' +
        ModelName +
        '  ###############\n')
    CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
    Newdoc = App.newDocument(CheckedModelName)
    App.setActiveDocument(CheckedModelName)
    Gui.ActiveDocument=Gui.getDocument(CheckedModelName)
    #case, pins, pinmark = make_case(params)
    case_bot, case, pins, pinmark = make_case(params)

    if case_bot is not None:
        show(case_bot)
    show(case)
    show(pins)
    show(pinmark)
    #stop

    doc = FreeCAD.ActiveDocument
    objs=GetListOfObjects(FreeCAD, doc)

    if case_bot is not None:
        Color_Objects(Gui,objs[0],body_bot_color)
        Color_Objects(Gui,objs[1],body_color)
        Color_Objects(Gui,objs[2],pins_color)
        Color_Objects(Gui,objs[3],marking_color)

        col_body_bot=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
        col_body=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
        col_pin=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
        col_mark=Gui.ActiveDocument.getObject(objs[3].Name).DiffuseColor[0]
        material_substitutions={
            col_body_bot[:-1]:body_bot_color_key,
            col_body[:-1]:body_color_key,
            col_pin[:-1]:pins_color_key,
            col_mark[:-1]:marking_color_key
        }
        expVRML.say(material_substitutions)
        if (color_pin_mark==True) and (place_pinMark==True):
            CutObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[1].Name, objs[3].Name)
        else:
            #removing pinMark
            App.getDocument(doc.Name).removeObject(objs[3].Name)
        ###
        #sleep
        del objs
        objs=GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[0].Name, objs[1].Name)
        objs=GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[0].Name, objs[1].Name)
    else:
        Color_Objects(Gui,objs[0],body_color)
        Color_Objects(Gui,objs[1],pins_color)
        Color_Objects(Gui,objs[2],marking_color)

        col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
        col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
        col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
        material_substitutions={
            col_body[:-1]:body_color_key,
            col_pin[:-1]:pins_color_key,
            col_mark[:-1]:marking_color_key
        }
        #expVRML.say(material_substitutions)
        if (color_pin_mark==True) and (place_pinMark==True):
            CutObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[0].Name, objs[2].Name)
        else:
            #removing pinMark
            App.getDocument(doc.Name).removeObject(objs[2].Name)
        ###
        #sleep
        del objs
        objs=GetListOfObjects(FreeCAD, doc)
        FuseObjs_wColors(FreeCAD, FreeCADGui,
                        doc.Name, objs[0].Name, objs[1].Name)
    ## objs[0].Label='body'
    ## objs[1].Label='pins'
    ## objs[2].Label='mark'
    ###
    ## print objs[0].Name, objs[1].Name, objs[2].Name

    ## sleep
    doc.Label=CheckedModelName
    objs=GetListOfObjects(FreeCAD, doc)
    objs[0].Label=CheckedModelName
    restore_Main_Tools()
    #rotate if required
    if (params.rotation!=0):
        rot= params.rotation
        z_RotateObject(doc, rot)
    #out_dir=destination_dir+params.dest_dir_prefix+'/'
    script_dir=os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    #expVRML.say(models_dir)
    if len(params.dest_dir_prefix)>=1:
        out_dir=models_dir+destination_dir+os.sep+params.dest_dir_prefix
    else:
        out_dir=models_dir+destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    #out_dir="./generated_qfp/"
    # export STEP model
    exportSTEP(doc, ModelName, out_dir)
    global LIST_license
    if LIST_license[0]=="":
        LIST_license=Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale=1/2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs=GetListOfObjects(FreeCAD, doc)

    export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
    export_file_name=out_dir+os.sep+ModelName+'.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    #expVRML.writeVRMLFile added creaeAngle
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license, 0.9)
    # Save the doc in Native FC format
    #saveFCdoc(App, Gui, doc, ModelName,out_dir)
    #display BBox
    #FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True
    if footprints_dir is not None and os.path.isdir(footprints_dir) and not save_memory and not check_Model: #it doesn't make sense to import the footprint right before we close the file.
        #expVRML.say (ModelName)
        #stop
        sys.argv = ["fc", "dummy", footprints_dir+os.sep+ModelName, "savememory"]
        #setup = get_setup_file()  # << You need the parentheses
        expVRML.say(sys.argv[2])
        if not ksu_present:
            try:
                import kicadStepUptools
                ksu_present=True
                expVRML.say("ksu present!")
                kicadStepUptools.KSUWidget.close()
                #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                #kicadStepUptools.KSUWidget.destroy()
                #for i in QtGui.qApp.topLevelWidgets():
                #    if i.objectName() == "kicadStepUp":
                #        i.deleteLater()
                kicadStepUptools.KSUWidget.close()
            except:
                ksu_present=False
                expVRML.say("ksu not present")
        else:
            kicadStepUptools.KSUWidget.close()
            reload(kicadStepUptools)
            kicadStepUptools.KSUWidget.close()
            #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
            #kicadStepUptools.KSUWidget.destroy()

    #FreeCADGui.insert(u"C:\Temp\FCAD_sg\QFN_packages\QFN-12-1EP_3x3mm_Pitch0_5mm.kicad_mod")
    #FreeCADGui.insert(script_dir+os.sep+"ModelName.kicad_mod")
    if save_memory == False:
        Gui.activateWorkbench("PartWorkbench")
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewBottom()
        #Gui.activeDocument().activeView().viewAxometric()
    saveFCdoc(App, Gui, doc, ModelName,out_dir)

    if save_memory == True or check_Model==True:
        doc=FreeCAD.ActiveDocument
        print("closing: {}".format(doc.Name))
        FreeCAD.closeDocument(doc.Name)

    if check_Model==True:
        step_path = out_dir + '/' + ModelName + ".step"
        runGeometryCheck(App, Gui, step_path,
            log, ModelName, save_memory=save_memory)
Exemple #39
0
def generate_package3d(params, part_params, mpn):

    # License information
    if LICENCE_Info.LIST_license[0] == "":
        LIST_license = add_license.LIST_int_license
    else:
        LIST_license = LICENCE_Info.LIST_license
    LIST_license[0] = "Copyright (C) " + datetime.datetime.now().strftime(
        "%Y") + ", " + LICENCE_Info.STR_licAuthor

    # Build model name
    model_name = "Connector_Wuerth_{series_prefix}_{type}_{rows}x{pins:02d}_P{pitch}_{orientation}_{mpn}".format(
        series_prefix=params['series_prefix'],
        type=params['type'],
        rows=part_params['rows'],
        pins=part_params['pins'] // 2,
        pitch=params['pitch'],
        orientation=params['orientation'],
        mpn=mpn)
    FreeCAD.Console.PrintMessage('\r\nGenerate: ' + model_name + '\r\n')

    # Create new document
    doc = FreeCAD.newDocument("doc")
    App.setActiveDocument("doc")
    App.ActiveDocument = App.getDocument("doc")
    Gui.ActiveDocument = Gui.getDocument("doc")

    # Generate body
    body_color_key = "black body"
    body_color = shaderColors.named_colors[body_color_key].getDiffuseFloat()
    body = generate_body(params, part_params)
    show(body, body_color + (0, ))

    # Generate pins
    pins_color_key = "gold pins"
    pins_color = shaderColors.named_colors[pins_color_key].getDiffuseFloat()
    pins = generate_pins(params, part_params)
    show(pins, pins_color + (0, ))

    # Finalize
    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)
    restore_Main_Tools()
    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    material_substitutions = {
        col_body[:-1]: body_color_key,
        col_pin[:-1]: pins_color_key
    }
    expVRML.say(material_substitutions)

    # Create output directory
    output_dir = 'Connector_Wuerth_{series_prefix}_Bottom-Entry.3dshapes/'.format(
        series_prefix=params['series_prefix'])
    if not os.path.isdir(output_dir):
        os.makedirs(output_dir)
    filename = '{output_dir:s}{model_name:s}.wrl'.format(output_dir=output_dir,
                                                         model_name=model_name)

    # Export wrl file
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, 1 / 2.54)
    expVRML.writeVRMLFile(colored_meshes, filename, used_color_keys,
                          LIST_license)

    # Export step file
    exportSTEP(doc, model_name, output_dir, objs[0])
    add_license.addLicenseToStep(
        output_dir, '{model_name}.step'.format(model_name=model_name),
        LIST_license, LICENCE_Info.STR_licAuthor, LICENCE_Info.STR_licEmail,
        LICENCE_Info.STR_licOrgSys, LICENCE_Info.STR_licPreProc)

    # Force recompute
    FreeCAD.activeDocument().recompute()

    # Save FCStd document
    saveFCdoc(App, Gui, doc, model_name, output_dir)

    # Close document
    doc = FreeCAD.ActiveDocument
    FreeCAD.closeDocument(doc.Name)
    def makeModel(self, models_dir, genericName, model, keepDocument=True, verbose=False):
        r"""Creates a model by calling an instance of a model generator class and writes out the model files

        .. note:: normally this method will be called by :func:`makeModels` but may be used directly

        :param models_dir:
            directory to write the created step and wrl files
        :type models_dir: ``str``

        :param genericName:
            the generic name from the base parameter list, may be used to create the model name
        :type  genericName: ``str``

        :param model:
            an instance of the model class to use
        :type   model: ``class instance`` inherited from :class:`cq_base_model.PartBase`

        :param keepDocument:
            * True: the FreeCAD document will shown after it is created, optionally with kicadStepUptools activated
            * False: the document window will be closed
        :type  keepDocument: ``boolean``

        """

        global kicadStepUptools

        modelName = model.makeModelName(genericName)

        FreeCAD.Console.PrintMessage('\r\n' + modelName)

        if model.make_me != True:
            FreeCAD.Console.PrintMessage(' - not made')
            return

        CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '')
        FreeCAD.newDocument(CheckedmodelName)
        FreeCAD.setActiveDocument(CheckedmodelName)
        Gui.ActiveDocument = Gui.getDocument(CheckedmodelName)

        model.make()

        doc = FreeCAD.ActiveDocument
        objs = GetListOfObjects(FreeCAD, doc)

        material_substitutions = {}

        for i in range(0, len(objs)):
            Color_Objects(Gui, objs[i], shaderColors.named_colors[model.color_keys[i]].getDiffuseFloat())
            material_substitutions[Gui.ActiveDocument.getObject(objs[i].Name).DiffuseColor[0][:-1]] = model.color_keys[i]

        if verbose:
            expVRML.say(material_substitutions)
            expVRML.say(model.color_keys)
            expVRML.say(model.offsets)

        doc.Label = CheckedmodelName

        while len(objs) > 1:
            FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
            del objs
            objs = GetListOfObjects(FreeCAD, doc)

        objs[0].Label = CheckedmodelName
        restore_Main_Tools()

        #rotate if required
        if (model.rotation != 0):
            z_RotateObject(doc, model.rotation)

        s = objs[0].Shape
        shape = s.copy()
        shape.Placement = s.Placement;
        shape.translate(model.offsets)
        objs[0].Placement = shape.Placement

        out_dir = models_dir + os.sep + model.destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)

        # Export STEP model
        exportSTEP(doc, modelName, out_dir)

        license_txt = list(add_license.LIST_int_license if self.license is None else self.license) # make a copy to avoid modifying the original
        license_txt.append("")
        license_txt.append("")
        if self.scriptsource != "" and self.script_dir is not None:
            license_txt.append("Generated by script, source at:")
            license_txt.append(self.scriptsource + self.script_dir.split(os.sep)[-1])
            license_txt.append("")

        if verbose:
            expVRML.say("")

        add_license.addLicenseToStep(out_dir + os.sep, modelName + ".step", license_txt, model.licAuthor, model.licEmail, model.licOrgSys, model.licOrg, model.licPreProc)

        # Scale and export Vrml model
        scale = 1.0 / 2.54
        objs = GetListOfObjects(FreeCAD, doc)
        if verbose:
            expVRML.say("######################################################################")
            expVRML.say(objs)
            expVRML.say("######################################################################")
        export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions)
        export_file_name = out_dir + os.sep + modelName + '.wrl'
        colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
        expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, license_txt)

        # Save the doc in native FC format
        out_dir = self.models_src_dir + os.sep + model.destination_dir
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)

        saveFCdoc(FreeCAD, Gui, doc, modelName, out_dir)

        # Place on footprint for verification
        if keepDocument and model.footprints_dir is not None and self.footprints_dir is not None:

            sys.argv = ["fc", "dummy", self.footprints_dir + os.sep + model.footprints_dir + os.sep + modelName, "savememory"]

            if verbose:
                expVRML.say('Footprint: ' + sys.argv[2])

            if self.kicadStepUptools is None:
                try:
                    import kicadStepUptools
                    expVRML.say("ksu present!")
                    self.kicadStepUptools = True
                    kicadStepUptools.KSUWidget.close()
                    #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                    #kicadStepUptools.KSUWidget.destroy()
                    #for i in QtGui.qApp.topLevelWidgets():
                    #    if i.objectName() == "kicadStepUp":
                    #        i.deleteLater()
                    #kicadStepUptools.KSUWidget.close()
                except:
                    self.kicadStepUptools = False
                    expVRML.say("ksu not present")

            if not self.kicadStepUptools == False:
                kicadStepUptools.KSUWidget.close()
                reload(kicadStepUptools)
                kicadStepUptools.KSUWidget.close()
                #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
                #kicadStepUptools.KSUWidget.destroy()

        #display BBox
        if keepDocument:
            Gui.activateWorkbench("PartWorkbench")
            Gui.SendMsgToActiveView("ViewFit")
            Gui.activeDocument().activeView().viewAxometric()
        else:
            doc=FreeCAD.ActiveDocument
            FreeCAD.closeDocument(doc.Name)
def run():
    ## # get variant names from command line

    return


#import step_license as L
import add_license as Lic

# when run from command line
if __name__ == "__main__" or __name__ == "main_generator":

    FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')

    full_path = os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir = os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name = full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir = sub_path + "_3Dmodels"

    model_to_build = ''
    gender_to_build = ''
    if len(sys.argv) < 3:
        FreeCAD.Console.PrintMessage(
            'No variant name is given, add a valid model name as an argument or the argument "all"\r\n'
    def makeModels(self, options, series, family, params, kicadStepUptools=None, verbose=False):
        r"""Instantiates model creator classes and calls :func:`makeModel` repeatedly to create model files

        This is the main entry point to use for creating models

        :param options:
            * options[0]:
                * empty - create default model from all *series* when *family* is None, otherwise the default model for a single *series*
                * 'all' - generate all models
                * 'allsmd' - generate all SMD style models
                * 'list' - list all model names
                * regexp - a filter to select the models to create
        :type options: ``str``

        :param series:
            list of part creator classes inherited from :class:`cq_base_model.PartBase`
        :type  series: ``list of classes``

        :param family:
            index into the list of parameter classes (series) None if all
        :type  family: ``integer or None``

        :param params:
            instance of the class used to hold part parameters
        :type  params: ``class instance`` inherited from :class:`cq_base_model.PartBase`

        Example::

            import sys, os

            script_dir  = os.path.dirname(os.path.realpath(__file__))
            scripts_root = script_dir.split(script_dir.split(os.sep)[-1])[0]

            sys.path.append(script_dir)
            sys.path.append(scripts_root + "\_tools")

            import cq_model_generator
            from cq_base_model import *

            class my_part (PartBase)
                ...

            class my_part_params (PartParametersBase)
                ...

            family = 0 # set to None to generate all series

            series = [
              my_part
            ]

            generator = cq_model_generator.ModelGenerator(scripts_root, script_dir)

            options = generator.getOptions(sys.argv)

            generator.make_models(options, series, family, my_part_params())

        """

        clear_console()
        FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')

        if verbose:
            expVRML.say(self.models_dir)
            expVRML.say(options)

        models_made = 0

        if len(options) > 0 and not params.base_params.has_key(options[0]):

            models = params.getAllModels(series)

            if options[0] == "list":
                for variant in sorted(models):
                    models_made = models_made + 1
                    expVRML.say(variant + "  ") # added spaces for pasting into .md file
            else:
                buildAllSMD = options[0] == "allsmd"
                qfilter = '*' if options[0] == "all" or options[0] == "allsmd" else options[0]
                qfilter = re.compile(fnmatch.translate(qfilter))
                for variant in models.keys():
                    if qfilter.match(variant):
                        params = models[variant].params
                        model = models[variant].model(params)
                        if (buildAllSMD == False or params.type == CaseType.SMD) and model.make_me:
                            models_made = models_made + 1
                            self.makeModel(self.models_dir, variant, model, keepDocument=False, verbose=verbose)
        else:

            if family == All:

                models = params.getSampleModels(series)

                for variant in models.keys():
                    params = models[variant].params
                    model = models[variant].model(params)
                    if model.make_me:
                        models_made = models_made + 1
                        self.makeModel(self.models_dir, variant, model, keepDocument=True, verbose=verbose)
                    else:
                        FreeCAD.Console.PrintMessage('\r\n' + model.makeModelName(variant) + ' - not made')

            else:

                variant_to_build = "" if len(options)== 0 else options[0]
                if variant_to_build == "":
                    FreeCAD.Console.PrintMessage('No variant name is given! building default variants')
                for i in range(family, family + 1):
                    variant = series[i].default_model if variant_to_build == "" else variant_to_build
                    model = params.getModel(series[i], variant)
                    if model != False:
                        models_made = models_made + 1
                        self.makeModel(self.models_dir, variant, model, keepDocument=True, verbose=verbose)
                    else:
                        FreeCAD.Console.PrintMessage('\r\n' + variant + ' - not made')

        if models_made == 0:
            FreeCAD.Console.PrintMessage('\r\nDone - no models matched the provided filter!')
        else:
            FreeCAD.Console.PrintMessage('\r\nDone - models made: ' + str(models_made))

        sys.argv = [] # clear, running kicadStepUptools changes values
Exemple #43
0
def MakeHeader(n):

    global LIST_license, docname
    name = HeaderName(n)

    destination_dir = "/Box_Headers"

    full_path = os.path.realpath(__file__)
    expVRML.say(full_path)
    scriptdir = os.path.dirname(os.path.realpath(__file__))
    expVRML.say(scriptdir)
    sub_path = full_path.split(scriptdir)
    expVRML.say(sub_path)
    sub_dir_name = full_path.split(os.sep)[-2]
    expVRML.say(sub_dir_name)
    sub_path = full_path.split(sub_dir_name)[0]
    expVRML.say(sub_path)
    models_dir = sub_path + "_3Dmodels"
    script_dir = os.path.dirname(os.path.realpath(__file__))
    #models_dir=script_dir+"/../_3Dmodels"
    expVRML.say(models_dir)
    out_dir = models_dir + destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    #having a period '.' character in the model name REALLY messes with things.
    docname = name.replace(".", "")

    newdoc = App.newDocument(docname)
    App.setActiveDocument(docname)
    a_doc = Gui.ActiveDocument
    Gui.ActiveDocument = Gui.getDocument(docname)

    pins = MakePinRow(n)
    pins = pins.union(MakePinRow(n).translate((0, 2.54, 0)))

    base = MakeBase(n)

    ##assign some colors
    #base_color = (50,50,50)
    #pins_color = (225,175,0)
    #
    #show(base,base_color+(0,))
    #show(pins,pins_color+(0,))
    show(base)
    show(pins)

    doc = FreeCAD.ActiveDocument
    objs = GetListOfObjects(FreeCAD, doc)

    Color_Objects(Gui, objs[0], body_color)
    Color_Objects(Gui, objs[1], pins_color)
    #Color_Objects(Gui,objs[2],marking_color)

    col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
    col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
    #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
    material_substitutions = {
        col_body[:-1]: body_color_key,
        col_pin[:-1]: pins_color_key,
        #col_mark[:-1]:marking_color_key
    }
    expVRML.say(material_substitutions)

    #objs=GetListOfObjects(FreeCAD, doc)
    FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name)
    doc.Label = docname
    objs = GetListOfObjects(FreeCAD, doc)
    objs[0].Label = docname
    restore_Main_Tools()

    #out_dir = "./generated_pinheaders/"

    doc.Label = docname

    #save the STEP file
    exportSTEP(doc, name, out_dir)
    if LIST_license[0] == "":
        LIST_license = Lic.LIST_int_license
        LIST_license.append("")
    Lic.addLicenseToStep(out_dir+'/', name+".step", LIST_license,\
                       STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc)

    # scale and export Vrml model
    scale = 1 / 2.54
    #exportVRML(doc,ModelName,scale,out_dir)
    objs = GetListOfObjects(FreeCAD, doc)
    expVRML.say(
        "######################################################################"
    )
    expVRML.say(objs)
    expVRML.say(
        "######################################################################"
    )
    export_objects, used_color_keys = expVRML.determineColors(
        Gui, objs, material_substitutions)
    export_file_name = out_dir + os.sep + name + '.wrl'
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys,
                          LIST_license)

    ###save the VRML file
    ##scale=0.3937001
    ##exportVRML(doc,name,scale,out_dir)

    # Save the doc in Native FC format
    saveFCdoc(App, Gui, doc, name, out_dir)

    if close_doc != True:  # avoid operations for memory leak
        Gui.SendMsgToActiveView("ViewFit")
        Gui.activeDocument().activeView().viewAxometric()

    return 0
    for p in pins[1:]:
        merged_pins = merged_pins.union(p)
    pins = merged_pins

    #show(pins)
    #sleep
    # extract pins from case
    case = case.cut(pins)

    return (case, pins, pinmark)


import step_license as L

if __name__ == "__main__":
    expVRML.say(expVRML.__file__)
    FreeCAD.Console.PrintMessage('\r\nRunning...\r\n')

    # maui     run()
    color_pin_mark = True
    if len(sys.argv) < 3:
        FreeCAD.Console.PrintMessage(
            'No variant name is given! building qfn16')
        model_to_build = 'QFN16'
    else:
        model_to_build = sys.argv[2]
        if len(sys.argv) == 4:
            FreeCAD.Console.PrintMessage(sys.argv[3] + '\r\n')
            if (sys.argv[3].find('no-pinmark-color') != -1):
                color_pin_mark = False
            else: