Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ compile
CMakeCache.txt
cmake_install.cmake
src/intern/.dirstamp

# Docker build outputs
*.tar.gz
dxfrw-*.tar.gz
12 changes: 0 additions & 12 deletions Dockerfile

This file was deleted.

91 changes: 82 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,45 @@ cmake --build . --config Release --target install

### Docker Build

#### Build Docker Image:
Build portable binaries for multiple OS distributions using Docker.

> **Note:** Dockerfiles are in `docker/` directory. Build process updated from CentOS 7 (EOL) to AlmaLinux 9.

**Available OS Distributions:**

| OS | Tag | Use Case |
|----|-----|----------|
| AlmaLinux 9 | `almalinux` | RHEL/CentOS compatible (CentOS successor) |
| Ubuntu 22.04 LTS | `ubuntu` | Debian/Ubuntu compatible |
| Amazon Linux 2023 | `amazonlinux` | AWS optimized |
| Alpine Linux | `alpine` | Lightweight musl-based |

**Quick Start:**

```bash
docker build --rm -t codelibs/libdxfrw .
# Build for single OS (creates dxfrw-{os}.tar.gz)
./docker/build-docker.sh run almalinux
./docker/build-docker.sh run ubuntu

# Build for all OS distributions
./docker/build-docker.sh run all-os

# Extract and install
sudo tar xzf dxfrw-almalinux.tar.gz -C /opt
```

#### Build Library Using Docker:
**Manual Docker Commands (if needed):**

```bash
docker run -t --rm -v `pwd`:/work codelibs/libdxfrw:latest /work/build.sh
# Build image and library
docker build -t codelibs/libdxfrw:ubuntu -f docker/Dockerfile.ubuntu .
docker run -t --rm -v `pwd`:/work codelibs/libdxfrw:ubuntu /work/build.sh
```

This creates `dxfrw.tar.gz`. Extract it under `/opt` or your preferred location.

#### Push Docker Image:
**Push to Docker Hub:**

```bash
docker tag codelibs/libdxfrw codelibs/libdxfrw:centos7
docker push codelibs/libdxfrw:centos7
./docker/build-docker.sh push almalinux
```

## Installation
Expand Down Expand Up @@ -302,6 +322,59 @@ The source code in `dwg2dxf/` serves as a comprehensive reference implementation

Extracts text information from DWG files.

## Utility Scripts

The library includes utility scripts in the `bin/` directory for extracting text content from DXF/DWG files.

### dwg2txt - DWG to Text Converter

Extracts text entities from DWG files:

```bash
# Usage
./bin/dwg2txt <input.dwg> <output.txt>

# Example
./bin/dwg2txt drawing.dwg output.txt
```

**Requirements:**
- `dwg2text` executable (built with the library)

### dxf2txt - DXF to Text Converter

Extracts text entities from DXF files:

```bash
# Usage
./bin/dxf2txt <input.dxf> <output.txt>

# Example
./bin/dxf2txt drawing.dxf output.txt
```

**Requirements:**
- Python 3.9 or later (minimum version across all Docker build environments)
- `ezdxf` Python package: `pip install ezdxf`

**Features:**
- Supports both TEXT and MTEXT entities
- Handles multiple DXF versions (R12 through 2018+)
- Automatic encoding detection (UTF-8, CP932/Shift-JIS)
- Preserves multi-line text formatting

### Direct Python Usage

You can also use the Python script directly:

```bash
# Install ezdxf if not already installed
pip install ezdxf

# Run the script
python3 bin/dxf2txt.py input.dxf output.txt
```

## Testing

The library includes comprehensive tests covering various aspects:
Expand Down
61 changes: 56 additions & 5 deletions bin/dwg2txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,60 @@
#!/bin/bash
#
# dwg2txt - Convert DWG files to text format
# Uses dwg2text utility to extract text content from DWG files
#

INPUT_FILE=$1
OUTPUT_FILE=$2
set -e

`dirname $0`/dwg2text $INPUT_FILE > $OUTPUT_FILE
if [ $? != 0 ] ; then
echo > $OUTPUT_FILE
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Function to show usage
usage() {
cat << EOF
Usage: $0 <input.dwg> <output.txt>

Convert DWG file to text format by extracting text entities.

Arguments:
input.dwg Input DWG file path
output.txt Output text file path

Example:
$0 drawing.dwg output.txt

EOF
exit 1
}

# Check arguments
if [ $# -ne 2 ]; then
echo "Error: Invalid number of arguments"
usage
fi

INPUT_FILE="$1"
OUTPUT_FILE="$2"

# Check if input file exists
if [ ! -f "$INPUT_FILE" ]; then
echo "Error: Input file does not exist: $INPUT_FILE"
exit 1
fi

# Check if dwg2text exists
DWG2TEXT="${SCRIPT_DIR}/dwg2text"
if [ ! -x "$DWG2TEXT" ]; then
echo "Error: dwg2text utility not found or not executable: $DWG2TEXT"
exit 1
fi

# Convert DWG to text
if "$DWG2TEXT" "$INPUT_FILE" > "$OUTPUT_FILE" 2>&1; then
echo "✓ Successfully converted: $OUTPUT_FILE"
exit 0
else
echo "⚠ Warning: dwg2text failed, creating empty output file"
echo "" > "$OUTPUT_FILE"
exit 1
fi
73 changes: 70 additions & 3 deletions bin/dxf2txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,74 @@
#!/bin/bash
#
# dxf2txt - Convert DXF files to text format
# Uses Python script to extract text content from DXF files
#

INPUT_FILE=$1
OUTPUT_FILE=$2
set -e

python `dirname $0`/dxf2txt.py $INPUT_FILE $OUTPUT_FILE
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Function to show usage
usage() {
cat << EOF
Usage: $0 <input.dxf> <output.txt>

Convert DXF file to text format by extracting text entities.

Arguments:
input.dxf Input DXF file path
output.txt Output text file path

Example:
$0 drawing.dxf output.txt

Requirements:
- Python 3
- ezdxf Python package (pip install ezdxf)

EOF
exit 1
}

# Check arguments
if [ $# -ne 2 ]; then
echo "Error: Invalid number of arguments"
usage
fi

INPUT_FILE="$1"
OUTPUT_FILE="$2"

# Check if input file exists
if [ ! -f "$INPUT_FILE" ]; then
echo "Error: Input file does not exist: $INPUT_FILE"
exit 1
fi

# Find Python interpreter
PYTHON=""
for cmd in python3 python; do
if command -v $cmd >/dev/null 2>&1; then
PYTHON=$cmd
break
fi
done

if [ -z "$PYTHON" ]; then
echo "Error: Python not found. Please install Python 3."
exit 1
fi

# Check if ezdxf is available
if ! $PYTHON -c "import ezdxf" 2>/dev/null; then
echo "Error: ezdxf package not found. Please install it:"
echo " pip install ezdxf"
exit 1
fi

# Convert DXF to text
$PYTHON "${SCRIPT_DIR}/dxf2txt.py" "$INPUT_FILE" "$OUTPUT_FILE"

echo "✓ Successfully converted: $OUTPUT_FILE"

Loading