FreeCAD Logo FreeCAD 1.0
  • English Afrikaans Arabo Bielorusso Catalano Czech German Greek Spanish Spanish Basco Finnish Filippino Français Galiziano Croatian Hungarian Indonesiano Italiano Japanese Kabyle Coreano Lituano Dutch Norvegese Bokmal Polish Portuguese Portuguese Romanian Russian Slovak Slovenian Serbo Swedish Turkish Ukrainian Valenziano Vietnamita Cinese Cinese
  • Funzioni
  • Download
  • Blog
  • Documentazione
    Indice di documentazione Per iniziare Documentazione utenti Il manuale FreeCAD Documentazione degli ambienti di lavoro Documentazione di scripting Python Documentazione codice C++ Tutorial Domande frequenti Politica sulla Privacy Informazioni Su FreeCAD
  • Contribuire
    Come aiutare Sponsor Segnala un bug Fai una richiesta Opportunità di lavoro e ricompense Linee guida per contribuire Manuale degli sviluppatori Traduzioni
  • Comunità
    Codice di condotta Forum The FPA GitHub GitLab Codeberg Mastodon Matrix IRC IRC via Webchat Gitter Discord Reddit Twitter Facebook LinkedIn Calendario
  • ♥ Donate

Donate

$
Informazioni SEPA
Si prega di intestare il bonifico SEPA a:
Beneficiary: The FreeCAD project association
IBAN: BE04 0019 2896 4531
BIC/SWIFT: GEBABEBBXXX
Agenzia bancaria: BNP Paribas Fortis
Indirizzo: 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!

Facce e Schizzi da DXF

Descrizione
Questa macro crea faccia e schizzo da un file DXF

Versione macro: 02.00
Ultima modifica: 2017-10-23
Versione FreeCAD: All
Download: ToolBar Icon
Autore: shoogen, easyw-fc
Autore
shoogen, easyw-fc
Download
ToolBar Icon
Link
Raccolta di macro
Come installare le macro
Personalizzare la toolbar
Versione macro
02.00
Data ultima modifica
2017-10-23
Versioni di FreeCAD
All
Scorciatoia
Nessuna
Vedere anche
Nessuno

Descrizione

Questa macro converte gli elementi selezionati di un DXF importato in facce e schizzi.

Può essere utilizzato anche per convertire 'Shape2DView' in Schizzi e funziona anche se sono presenti B-Spline.

Utilizzo

  • Importare un file DXF
  • Selezionare gli elementi da elaborare
  • Avviare la macro: tutti gli oggetti selezionati vengono analizzati e trasformati in facce e schizzi.

Opzioni

  • Modificare create_face=True oppure create_sketch=True in False per generare solo un tipo di oggetti

Script

Icona barra degli strumenti


Macro_DXF_to_Face_and_Sketch.FCMacro

##    Select the items to be processed
##    Launch the macro, all selected objects are analyzed and transformed into faces and sketches.
##    change create_face=True or create_sketch=True to False to generate only one item
## todo: fix closed curves for bsplines method

import FreeCAD,Part,Path
from PathScripts import PathUtils

import sys, os
#sys.path.append('C:\Cad\Progetti_K\3D-FreeCad-tools/')
#sys.path.append(os.path.realpath(__file__)) #workaround to test OpenSCAD2DgeomMau
#import OpenSCAD2DgeomMau #OpenSCAD2Dgeom
#reload(OpenSCAD2DgeomMau)
import OpenSCAD2Dgeom

import PySide
from PySide import QtGui, QtCore


import DraftGeomUtils
import Draft
from DraftGeomUtils import geomType

create_face=True
create_sketch=True
dqd = 0.02 #discretize(QuasiDeflection=d) => gives a list of points with a maximum deflection 'd' to the edge (faster)


def clear_console():
    #clearing previous messages
    mw=FreeCADGui.getMainWindow()
    c=mw.findChild(QtGui.QPlainTextEdit, "Python console")
    c.clear()
    r=mw.findChild(QtGui.QTextEdit, "Report view")
    r.clear()

def shape2Sketch(shape):
    # replace shape.edges with arcs
    newEdges = PathUtils.cleanedges(shape.Edges,0.1)
    wire = Part.Wire([Part.Edge(i) for i in newEdges])
    sketch = Draft.makeSketch(wire,autoconstraints=True,delete=True)
    return sketch

def Discretize(shape, addToName=None):
    ##https://forum.freecad.org/viewtopic.php?f=12&t=16336#p129468
    ##Discretizes the edge and returns a list of points.
    ##The function accepts keywords as argument:
    ##discretize(Number=n) => gives a list of 'n' equidistant points
    ##discretize(QuasiNumber=n) => gives a list of 'n' quasi equidistant points (is faster than the method above)
    ##discretize(Distance=d) => gives a list of equidistant points with distance 'd'
    ##discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the edge
    ##discretize(QuasiDeflection=d) => gives a list of points with a maximum deflection 'd' to the edge (faster)
    ##discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a'
    ##and a curvature deflection of 'c'. Optionally a minimum number of points
    ##can be set which by default is set to 2. 

    global dqd

    # lng=(abs(FreeCAD.ActiveDocument.getObject(skt_name).Shape.BoundBox.XLength)+abs(FreeCAD.ActiveDocument.getObject(skt_name).Shape.BoundBox.YLength))
    # dv=int(dvm*lng) #discretize auto setting
    # #dv=int(0.5*lng) #discretize auto setting COARSE for testing
    # #print( dv)
    # if dv < 20:
    #     dv=20
    #b=FreeCAD.ActiveDocument.getObject(skt_name)
    #l=b.Shape.copy().discretize(dv)
    #l=b.Shape.copy().discretize(QuasiDeflection=0.02)
    l=shape.copy().discretize(QuasiDeflection=dqd)
    f=Part.makePolygon(l)
    Part.show(f)
    sh_name=FreeCAD.ActiveDocument.ActiveObject.Name
    if addToName is None:
        Draft.makeSketch(FreeCAD.ActiveDocument.ActiveObject,autoconstraints=True)
    else:
        Draft.makeSketch(FreeCAD.ActiveDocument.ActiveObject,autoconstraints=True, addTo=addToName)
    s_name=FreeCAD.ActiveDocument.ActiveObject.Name
    FreeCAD.ActiveDocument.removeObject(sh_name)
    #FreeCAD.ActiveDocument.removeObject(skt_name)
    FreeCAD.ActiveDocument.recompute() 
    return s_name
    #stop

def WireDiscretize(wire):
    ##https://forum.freecad.org/viewtopic.php?f=12&t=16336#p129468
    ##Discretizes the edge and returns a list of points.
    ##The function accepts keywords as argument:
    ##discretize(Number=n) => gives a list of 'n' equidistant points
    ##discretize(QuasiNumber=n) => gives a list of 'n' quasi equidistant points (is faster than the method above)
    ##discretize(Distance=d) => gives a list of equidistant points with distance 'd'
    ##discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the edge
    ##discretize(QuasiDeflection=d) => gives a list of points with a maximum deflection 'd' to the edge (faster)
    ##discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a'
    ##and a curvature deflection of 'c'. Optionally a minimum number of points
    ##can be set which by default is set to 2. 

    global dqd

    l=wire.copy().discretize(QuasiDeflection=dqd)
    f=Part.makePolygon(l)
    Part.show(f)
    sh_name=FreeCAD.ActiveDocument.ActiveObject.Name
    FreeCAD.ActiveDocument.recompute() 
    
    return sh_name
    #stop
    
    
#creating face from dxf
doc = App.ActiveDocument
clear_console()

if FreeCADGui.Selection.getSelection():

    try:
        edges=sum((obj.Shape.Edges for obj in \
        FreeCADGui.Selection.getSelection() if hasattr(obj,'Shape')),[])
        for edge in edges:
            print( "geomType ",DraftGeomUtils.geomType(edge))
        face = OpenSCAD2Dgeom.edgestofaces(edges)
        #face = OpenSCAD2DgeomMau.edgestofaces(edges)
        face.check() # reports errors
        face.fix(0,0,0)
        faceobj = doc.addObject('Part::Feature','face_%s' % "dxf")
        faceobj.Label = 'face_%s' % "dxf"
        faceobj.Shape = face
        for obj in FreeCADGui.Selection.getSelection():
            Gui.ActiveDocument.getObject(obj.Name).Visibility=False   
        #creating sketch from face from dxf
        #wires,_faces = Draft.downgrade(FreeCADGui.Selection.getSelection(),delete=False)
        if create_sketch:
            if create_face:
                wires,_faces = Draft.downgrade(faceobj,delete=False)
            else:
                wires,_faces = Draft.downgrade(faceobj,delete=True)
            if 0: #try:
                sketch = Draft.makeSketch(wires[0:1])
                sketch.Label = "Sketch_dxf"
                for wire in wires[1:]:
                    Draft.makeSketch([wire],addTo=sketch)
                for wire in wires:
                    FreeCAD.ActiveDocument.removeObject(wire.Name)
            else: #except:
                FreeCAD.Console.PrintWarning("\nConverting Bezier curves to Arcs\n")
                #FreeCAD.ActiveDocument.removeObject(FreeCAD.ActiveDocument.ActiveObject.Name)
                
                #print()
                sketchesList=[]
                #for wire in wires:
                #    for e in wire.Shape.Edges:
                #        if geomType(e) == "BSplineCurve" or geomType(e) == "BezierCurve":
                #        #if 'spline' in e.Curve:
                #            sk_name = Discretize(e)
                #            sketchesList.append(sk_name)
                #        else:
                #            sketch = Draft.makeSketch(Part.Wire(e))
                #            sketchesList.append(sketch.Name)
                #print( sketchesList)
                
                newShapeList = []
                newShapes = []
                for wire in wires:
                    for e in wire.Shape.Edges:
                        if geomType(e) == "BSplineCurve" or geomType(e) == "BezierCurve":
                        #if 'spline' in e.Curve:
                            w = Part.Wire(e)
                            w_name =WireDiscretize(w)
                            newShapeList.append(w_name)
                            wn=FreeCAD.ActiveDocument.getObject(w_name)
                            newShapes.append(wn)
                        else:
                            w = Part.Wire(e)
                            Part.show(w)
                            newShapes.append(w)
                            w_name = FreeCAD.ActiveDocument.ActiveObject.Name
                            newShapeList.append(w_name)
                            
                #print( newShapes)
                sketch = Draft.makeSketch(newShapes[0])
                FreeCAD.ActiveDocument.ActiveObject.Label="Sketch_dxf"
                for w in newShapes[1:]:
                    Draft.makeSketch([w],addTo=sketch)    
                for wire in wires:
                    FreeCAD.ActiveDocument.removeObject(wire.Name)
                for w_name in newShapeList:
                    FreeCAD.ActiveDocument.removeObject(w_name)
                
                #stop
                #WireDiscretize(wire)
                
                
                #stop
                #sk_name=FreeCAD.ActiveDocument.ActiveObject.Name
                #skObj=FreeCAD.ActiveDocument.getObject(sk_name)
                #for wire in wires[1:]:
                #    Discretize(wire.Shape,skObj)
                    
                #for wire in wires:
                #    FreeCAD.ActiveDocument.removeObject(wire.Name)
                    
                #for wire in wires[1:]:
                #    Discretize(wire.Shape,sketch)
                #for wire in wires:
                #    FreeCAD.ActiveDocument.removeObject(wire.Name)
                #for wire in wires:
                #    FreeCAD.ActiveDocument.removeObject(wire.Name)
                #sketch = shape2Sketch(face)
                #sketch = Discretize(FreeCAD.ActiveDocument.getObject(faceobj.Name).Shape)
                #sketch = Discretize(FreeCAD.ActiveDocument.getObject(f1.Name))
                
    except Part.OCCError: # Exception: #
        FreeCAD.Console.PrintError('Error in dxf %s (%s)' % (faceobj.Name,faceobj.Label)+"\n")
else:
    #FreeCAD.Console.PrintError("Select elements from dxf imported file\n")
    FreeCAD.Console.PrintWarning("Select elements from dxf imported file\n")

Link

Link

  • Forum Creare uno sketch partendo da un file dxf importato
  • Esempi di macro Macro Creating faces from a DXF file
  • Precedente versione Macro Creating faces from a DXF file

Questa pagina è recuperata da https://wiki.freecad.org/Macro_DXF_to_Face_and_Sketch

Tieniti aggiornato!
Forum GitHub Mastodon Matrix IRC Gitter.im Discord Reddit Twitter Facebook LinkedIn

© The FreeCAD Team. Homepage image credits (top to bottom): ppemawm, r-frank, epileftric, regis, rider_mortagnais, bejant.

Questo progetto è supportato da: , KiCad Services Corp. e altri sponsor

GitHubMigliora questa pagina su GitHub