Creation of a DXF Document with a Dog House Layer

This code snippet demonstrates how to create a DXF document using the ezdxf library in Python. It defines dimensions in centimeters and creates a layer named 'DogHouse' with basic shapes representing the base and walls of a dog house.
 avatar
unknown
python
a year ago
2.4 kB
7
Indexable
import ezdxf

# Definizione delle dimensioni in cm
width = 150  # larghezza
depth = 150  # profondità
height = 180  # altezza

# Creazione di un nuovo documento DXF
doc = ezdxf.new(dxfversion='R2010')

# Aggiunta di un nuovo layer per la cuccia
doc.layers.add(name='DogHouse', color=1)

# Creazione della base (pavimento)
msp = doc.modelspace()
msp.add_lwpolyline([(0, 0), (width, 0), (width, depth), (0, depth), (0, 0)], dxfattribs={'layer': 'DogHouse'})

# Creazione delle pareti
# Parete anteriore
msp.add_lwpolyline([(0, 0), (0, height)], dxfattribs={'layer': 'DogHouse'})
msp.add_lwpolyline([(width, 0), (width, height)], dxfattribs={'layer': 'DogHouse'})
msp.add_lwpolyline([(0, height), (width, height)], dxfattribs={'layer': 'DogHouse'})

# Parete posteriore
msp.add_lwpolyline([(0, depth), (0, depth + height)], dxfattribs={'layer': 'DogHouse'})
msp.add_lwpolyline([(width, depth), (width, depth + height)], dxfattribs={'layer': 'DogHouse'})
msp.add_lwpolyline([(0, depth + height), (width, depth + height)], dxfattribs={'layer': 'DogHouse'})

# Parete sinistra
msp.add_lwpolyline([(0, 0), (0, depth)], dxfattribs={'layer': 'DogHouse'})
msp.add_lwpolyline([(0, depth), (0, depth + height)], dxfattribs={'layer': 'DogHouse'})
msp.add_lwpolyline([(0, depth + height), (0, height)], dxfattribs={'layer': 'DogHouse'})

# Parete destra
msp.add_lwpolyline([(width, 0), (width, depth)], dxfattribs={'layer': 'DogHouse'})
msp.add_lwpolyline([(width, depth), (width, depth + height)], dxfattribs={'layer': 'DogHouse'})
msp.add_lwpolyline([(width, depth + height), (width, height)], dxfattribs={'layer': 'DogHouse'})

# Creazione del soffitto
msp.add_lwpolyline([(0, height), (width, height), (width, depth + height), (0, depth + height), (0, height)], dxfattribs={'layer': 'DogHouse'})

# Aggiunta della porta (plexiglass trasparente)
door_width = 60  # cm
door_height = 100  # cm
door_x = (width - door_width) / 2
msp.add_lwpolyline([(door_x, 0), (door_x, door_height)], dxfattribs={'layer': 'DogHouse'})
msp.add_lwpolyline([(door_x + door_width, 0), (door_x + door_width, door_height)], dxfattribs={'layer': 'DogHouse'})
msp.add_lwpolyline([(door_x, door_height), (door_x + door_width, door_height)], dxfattribs={'layer': 'DogHouse'})

# Salvataggio del file DXF
file_path = 'dog_house_project.dwg'
doc.saveas(file_path)

print(f"File salvato in {file_path}")
Editor is loading...
Leave a Comment