FreeCAD Logo FreeCAD 1.0
  • angielski afrykanerski arabski białoruski kataloński czeski niemiecki grecki hiszpański hiszpański baskijski fiński filipiński francuski galicyjski chorwacki węgierski Indonezyjski włoski japoński kabylski koreański litewski duński Norweski Bokmal polski portugalski portugalski rumuński rosyjski słowacki słoweński serbski szwedzki turecki ukraiński walenciański wietnamski chiński chiński
  • Funkcjonalność programu
  • Pobierz
  • Blog
  • Dokumentacja
    Spis dokumentacji Jak zacząć Dokumentacja użytkowników Podręcznik do programu FreeCAD Dokumentacja środowisk pracy Dokumentacja skryptów środowiska Python Dokumentacja kodowania C++ Poradniki Najczęściej zadawane pytania Polityka prywatności O FreeCAD
  • Przyłącz się do projektu
    Jak pomóc Sponsor Zgłoś błąd Utwórz pull request Praca i finansowanie Zasady współpracy Podręcznik dla programistów Tłumaczenia
  • Społeczność
    Kodeks postępowania Forum The FPA GitHub GitLab Codeberg Mastodon Matrix IRC IRC via Webchat Gitter Discord Reddit Twitter Facebook LinkedIn Kalendarz
  • ♥ Donate

Donate

$
Informacje o SEPA
Skonfiguruj przelew bankowy SEPA do:
Beneficiary: The FreeCAD project association
IBAN: BE04 0019 2896 4531
BIC/SWIFT: GEBABEBBXXX
Bank: BNP Paribas Fortis
Adres: Rue de la Station 64, 1360 Perwez, Belgium

While Stripe doesn't support monthly donations, you can still become a sponsor! Simply make a one-time donation equivalent to 12 months of support, and you'll gain access to the corresponding sponsoring tier. It's an easy and flexible way to contribute.

If you are not sure or not able to commit to a regular donation, but still want to help the project, you can do a one-time donation, of any amount.

Choose freely the amount you wish to donate one time only.

You can support FreeCAD by sponsoring it as an individual or organization through various platforms. Sponsorship provides a steady income for developers, allowing the FPA to plan ahead and enabling greater investment in FreeCAD. To encourage sponsorship, we offer different tiers, and unless you choose to remain anonymous, your name or company logo will be featured on our website accordingly.

from 1 USD / 1 EUR per month. You will not have your name displayed here, but you will have helped the project a lot anyway. Together, normal sponsors maintain the project on its feet as much as the bigger sponsors.

from 25 USD / 25 EUR per month. Your name or company name is displayed on this page.

from 100 USD / 100 EUR per month. Your name or company name is displayed on this page, with a link to your website, and a one-line description text.

from 200 USD / 200 EUR per month. Your name or company name and logo displayed on this page, with a link to your website and a custom description text. Companies that have helped FreeCAD early on also appear under Gold sponsors.

Instead of donating each month, you might find it more comfortable to make a one-time donation that, when divided by twelve, would give you right to enter a sponsoring tier. Don't hesitate to do so!

Choose freely the amount you wish to donate each month.

Please inform your forum name or twitter handle as a notein your transfer, or reach to us, so we can give you proper credits!

Easy cutouts for Enclosure Design

Opis
To makro tworzy wycięcia dla obudów w bardzo wygodny sposób.

Macro version: 0.26
Last modified: 2016.08
FreeCAD version: 0.16
Download: Ikona paska narzędzi
Autor: maurice
Autor
maurice
Do pobrania
Ikona paska narzędzi
Odnośniki
Przepisy na makropolecenia
Jak zainstalować makrodefinicje
Dostosowanie pasków narzędzi
Wersja Makrodefinicji
0.26
Data zmian
2016.08
Wersja FreeCAD
0.16
Domyślny skrót
Brak
Zobacz również
-

Opis

To makro tworzy wycięcia dla obudów w bardzo wygodny sposób.

Demonstracja z obudową Arduino Uno

Użycie

Zaznacz ścianę obiektu, która będzie bazą dla wycięcia, a makro utworzy klon zewnętrznego konturu z marginesem 0,5 mm (ustawionym w makrze).

Skrypt

Ikona paska narzędzi

Macro_Easy_cutouts_for_Enclosure_Design.FCMacro

# -*- coding: utf-8 -*-
#
__Name__   = 'Easy cutouts for Enclosure Design'
__Comment__ = 'This macro makes Cutouts for Enclosures in a very handy way.'
__Author__ = 'easyyw-fc'
__Date__ = '08.2025'
__Version__ = '0.26'
__License__ = 'CC-BY-3.0'
__Web__ = ''
__Wiki__ = 'https://wiki.freecad.org/Macro_Easy_cutouts_for_Enclosure_Design'
__Status__ = 'original 11.2016, updated 08.2025 by drmacro'
__Communication__ = 'https://forum.freecad.org/viewtopic.php?t=4625'

import FreeCAD, FreeCADGui, Draft, Part, DraftTools
from FreeCAD import Base


def say(msg):
    FreeCAD.Console.PrintMessage(msg)
    FreeCAD.Console.PrintMessage('\n')

def sayw(msg):
    FreeCAD.Console.PrintWarning(msg)
    FreeCAD.Console.PrintWarning('\n')

def getNormal(self):
    return self.Object.Shape.Faces[0].normalAt(0,0)

#Init
if Gui.ActiveDocument:
    #say(Gui.ActiveDocument)

    cx = 1  # center x -> 1
    cy = 1  # center y -> 1
    cz = 1  # center z -> 1

    # scaleX = 1.1 # scale factor for Clone
    # scaleY = 1.1 # scale factor for Clone
    # scaleZ = 1.1 # scale factor for Clone

    margin = 0.5 #margin in mm
    extrudeLenght = 10 #10mm
    #selEx = FreeCADGui.Selection.getSelectionEx()
    sel = FreeCADGui.Selection.getSelection()

    #print sel[0].Label
    #objs = [selobj.Object for selobj in selEx]
    selF = FreeCADGui.Selection.getSelectionEx()

    #if len(Gui.Selection.getSelectionEx()[0].SubElementNames) <1:
    #    stop

    if len(sel) > 0:
        FreeCADGui.Selection.removeSelection(sel[0])
    #for o in FreeCADGui.ActiveDocument.getObjects():
    #    FreeCADGui.Selection.removeSelection(o.Name)
    coords = []
    j = 0
    #if len(sel) == 1: # only 1 object selected
    #if len(selF) == 1: # only 1 object selected
    if len(sel) > 0:
        if len(selF[0].SubElementNames) == 1:
            f_names=[]
            f = Draft.makeFacebinder(selF)
            f1=App.ActiveDocument.getObject(f.Name)
            face=0
            try:
                norm = f1.Shape.Faces[0].normalAt(0,0)
                say(norm)
                face=1
            except:
                App.Console.PrintMessage("Select ONLY one single Face of object!"+"\n")
                # stop
            if face == 1:
                l = Draft.downgrade(f,delete=False)
                k = 0; bbM = 0
                for o in l:
                    for w in o:
                        #print w.Name
                        f_names.append(w.Name)
                        say(w.Name)
                        if "Facebinder" not in w.Name:
                            bb=w.Shape.BoundBox
                            bbX=float(bb.XLength)
                            bbY=float(bb.YLength)
                            bbZ=float(bb.ZLength)
                            say(str(bbX)+";"+str(bbY)+";"+str(bbZ))
                            if bbX > bbM:
                                bbM = bbX; m = k
                            if bbY > bbM:
                                bbM = bbY; m = k
                            if bbZ > bbM:
                                bbM = bbZ; m = k
                        k=k+1
                print(f_names)
                k = 0
                #f_names=[]
                for o in l:
                    for w in o:
                        say(w.Name)
                        #f_names.append(w.Name)
                        if k!=m:
                            say("deleting "+f_names[k])
                            FreeCAD.ActiveDocument.removeObject(f_names[k])
                        else:
                            FreeCADGui.ActiveDocument.getObject(f_names[k]).Visibility=False
                            f = FreeCAD.ActiveDocument.addObject('Part::Extrusion', 'Extrude_for_cut')
                            f = FreeCAD.ActiveDocument.getObject(f.Name)
                            f.Base = FreeCAD.ActiveDocument.getObject(f_names[k])
                            f.Dir = norm * extrudeLenght * -1
                            f.Solid = (True)
                            f.TaperAngle = (0)
                        k=k+1
                #FreeCAD.ActiveDocument.removeObject(f_names[len(l)])
                say(f_names)
                say(f_names[m])
                say(bbM)

                FreeCADGui.Selection.addSelection(FreeCAD.ActiveDocument.getObject(f.Name))
                FreeCAD.ActiveDocument.recompute()

                sel = FreeCADGui.Selection.getSelection()
                #objs = [selobj.Object for selobj in selEx]

                coords = []
                j = 0
                s = sel[0].Shape

                bb=s.BoundBox

                bbX=float(bb.XLength)
                bbY=float(bb.YLength)
                bbZ=float(bb.ZLength)
                # boundBox
                boundBox_ = s.BoundBox

                a = str(boundBox_)
                a,b = a.split('(')
                c = b.split(',')
                oripl_X = float(c[0])
                oripl_Y = float(c[1])
                oripl_Z = float(c[2])
                coords.append([oripl_X+bbX/2, oripl_Y+bbY/2, oripl_Z+bbZ/2])
                App.Console.PrintMessage(str(boundBox_)+"\r\n")
                App.Console.PrintMessage("BBox           : "+str(bbX)+" x "+str(bbY)+" x "+str(bbZ)+"\r\n")
                App.Console.PrintMessage("Base Pos       : "+str(oripl_X)+" x "+str(oripl_Y)+" x "+str(oripl_Z)+"\r\n")
                App.Console.PrintMessage("Center Pos     : "+str(oripl_X+bbX/2)+" x "+str(oripl_Y+bbY/2)+" x "+str(oripl_Z+bbZ/2)+"\r\n")
                App.Console.PrintMessage("Coords         : "+str(coords[j])+"\r\n")

                #objC = FreeCAD.ActiveDocument.addObject('Part::AttachableObjectPython', 'Clone_for_cut')
                #objC = FreeCAD.ActiveDocument.getObject(objC.Name)
                objC=Draft.clone(sel)
                if bbX!=0:# -*- coding: utf-8 -*-
                    scaleX = (bbX + 2*margin) / bbX
                else:
                    scaleX = 1
                if bbY!=0:
                    scaleY = (bbY + 2*margin) / bbY
                else:
                    scaleY = 1
                if bbZ!=0:
                    scaleZ = (bbZ + 2*margin) / bbZ
                else:
                    scaleZ = 1
                objC.Scale = (scaleX,scaleY,scaleZ)
                #Draft.scale(objC,delta=App.Vector(scaleX,scaleY,scaleZ),center=App.Vector(0,0,0),copy=True,legacy=True)

                oL = sel[0].Label + "_enlarged"
                objC.Label = oL
                FreeCADGui.Selection.addSelection(objC)

                FreeCAD.ActiveDocument.recompute()

                selEx = FreeCADGui.Selection.getSelectionEx()
                objs = [selobj.Object for selobj in selEx]
                coords = []
                j = 0
                if len(objs) >= 1:
                    for obj in objs:
                        #s = objs[0].Shape
                        s = obj.Shape

                        # boundBox
                        boundBox_ = s.BoundBox
                        boundBoxLX = boundBox_.XLength
                        boundBoxLY = boundBox_.YLength
                        boundBoxLZ = boundBox_.ZLength

                        a = str(boundBox_)
                        a,b = a.split('(')
                        c = b.split(',')
                        oripl_X = float(c[0])
                        oripl_Y = float(c[1])
                        oripl_Z = float(c[2])
                        coords.append([oripl_X+boundBox_.XLength/2, oripl_Y+boundBox_.YLength/2, oripl_Z+boundBox_.ZLength/2])
                        App.Console.PrintMessage(str(boundBox_)+"\r\n")
                        App.Console.PrintMessage("BBox           : "+str(boundBox_.XLength)+" x "+str(boundBox_.YLength)+" x "+str(boundBox_.ZLength)+"\r\n")
                        App.Console.PrintMessage("Base Pos       : "+str(oripl_X)+" x "+str(oripl_Y)+" x "+str(oripl_Z)+"\r\n")
                        App.Console.PrintMessage("Center Pos     : "+str(oripl_X+boundBox_.XLength/2)+" x "+str(oripl_Y+boundBox_.YLength/2)+" x "+str(oripl_Z+boundBox_.ZLength/2)+"\r\n")
                        App.Console.PrintMessage("Coords         : "+str(coords[j])+"\r\n")
                        if j>0:
                            if cx == 1:
                                coordNx=coords[0][0]-coords[j][0]
                            else:
                                coordNx=0
                            if cy == 1:
                                coordNy=coords[0][1]-coords[j][1]
                            else:
                                coordNy=0
                            if cz == 1:
                                coordNz=coords[0][2]-coords[j][2]
                            else:
                                coordNz=0
                            obj.Placement.move(App.Vector(coordNx,coordNy,coordNz))
                            App.Console.PrintMessage("Moved     : "+str(coordNx)+" "+str(coordNy)+" "+str(coordNz)+"\r\n")
                        j=j+1

                        App.Console.PrintMessage("_____________________"+"\r\n")

                    FreeCADGui.Selection.removeSelection(objs[0])
                    FreeCADGui.ActiveDocument.getObject(objs[0].Name).Visibility=False
                    FreeCADGui.ActiveDocument.getObject(objs[0].Name).Transparency=70
                    App.ActiveDocument.recompute()

        else:
            App.Console.PrintMessage("Select ONLY one single Face of object!"+"\n")
    else:
        App.Console.PrintMessage("Select ONLY one single Face of object!"+"\n")
else:
    sayw("no document to work with")

Łącze

Forum: Easy cutouts for Enclosure Design Macro

Ta strona pochodzi z https://wiki.freecad.org/Macro_Easy_cutouts_for_Enclosure_Design

Bądźmy w kontakcie!
Forum GitHub Mastodon Matrix IRC Gitter.im Discord Reddit Twitter Facebook LinkedIn

© Załoga FreeCAD. Autorami grafiki na stronie głównej (od góry do dołu) są: ppemawm, r-frank, epileftric, regis, rider_mortagnais, bejant.

Ten projekt jest wspierany przez: , KiCad Services Corp. oraz pozostałych sponsorów

GitHubUlepsz tę stronę na GitHub