Skip to content

Commit e9f1a5c

Browse files
committed
Previously, APoint's x, y, z defaulted to integers (0), which led to unintended type inference as int. Updated them to 0.0 to correctly infer as float, which is more appropriate for coordinate values.
Thanks to @Thomas737 for spotting this! And added send_command() and send_commands() functions
1 parent 45d6bbf commit e9f1a5c

File tree

6 files changed

+60
-16
lines changed

6 files changed

+60
-16
lines changed

AutoCAD/AutoCAD_Module.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import subprocess
2-
import time
2+
from enum import Enum
33
import psutil
44
import pythoncom
55
import win32com.client
6-
from enum import Enum
76

87

98
# project by jones peter
@@ -73,7 +72,7 @@ class LineStyle(Enum):
7372

7473
class APoint:
7574
"""Represents a 3D point in AutoCAD."""
76-
def __init__(self, x=0, y=0, z=0):
75+
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0):
7776
"""
7877
Initializes a 3D point.
7978
Args:
@@ -99,7 +98,7 @@ def to_tuple(self):
9998
Returns:
10099
tuple: A tuple containing the x and y coordinates.
101100
"""
102-
return (self.x, self.y)
101+
return self.x, self.y
103102

104103
def __repr__(self):
105104
return f"APoint({self.x}, {self.y}, {self.z})"
@@ -1356,3 +1355,38 @@ def add_table(self, table_obj: Table):
13561355
raise CADException(f"Invalid input for manual table creation: {ve}")
13571356
except Exception as e:
13581357
raise CADException(f"Error during manual table creation: {e}")
1358+
1359+
def send_command(self, command_string):
1360+
"""
1361+
Sends a single command string to the AutoCAD command line.
1362+
Note: This is an asynchronous operation. The script may continue
1363+
before the command is fully executed in AutoCAD. For commands that
1364+
require user input or have long processing times, consider adding delays
1365+
or using other methods to ensure completion.
1366+
Args:
1367+
command_string (str): The command string to send. It should be
1368+
formatted as if typed in the command line.
1369+
Crucially, end the command with a space ' ' or a
1370+
newline '\\r' to simulate pressing Enter.
1371+
Example: "LINE 0,0 100,100 " (two spaces for Enter twice)
1372+
Raises:
1373+
CADException: If the command cannot be sent.
1374+
"""
1375+
try:
1376+
self.doc.SendCommand(command_string)
1377+
except Exception as e:
1378+
raise CADException(f"Error sending command '{command_string}': {e}")
1379+
1380+
def send_commands(self, commands):
1381+
"""
1382+
Sends a sequence of command strings to the AutoCAD command line.
1383+
Args:
1384+
commands (list[str]): A list of command strings to send in sequence.
1385+
Raises:
1386+
CADException: If any command in the sequence fails.
1387+
"""
1388+
try:
1389+
for command in commands:
1390+
self.send_command(command)
1391+
except Exception as e:
1392+
raise CADException(f"Error sending command sequence: {e}")

AutoCAD/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .AutoCAD_Module import *
2-
__version__ = "0.1.9"
2+
__version__ = "0.1.10"

AutoCAD/__main__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
from AutoCAD import __version__
12
print("╔────────────────────────────────── WELCOME ──────────────────────────────────╗")
2-
print("| ▁ ▂ ▄ ▅ ▆ ▇ █ AutoCADlib █ ▇ ▆ ▅ ▄ ▂ ▁ |")
3-
print("| AutoCADlib is a Python library designed for automating AutoCAD |")
3+
print("| ▁ ▂ ▄ ▅ ▆ ▇ █ AutoCAD █ ▇ ▆ ▅ ▄ ▂ ▁ |")
4+
print("| AutoCAD is a Python library designed for automating AutoCAD |")
45
print("| workflows,enabling efficient drawing manipulations, custom |")
56
print("| scripting, and automation of repetitive CAD tasks |")
67
print("| using Python. |")
7-
print("| version : 0.1.9 By - JonesPeter |")
8-
print("| github : https://github.com/Jones-peter |")
8+
print("| github: https://github.com/Jones-peter By - JonesPeter |")
99
print("| |")
1010
print("╚──────────────────────────Unlimited CAD Automation───────────────────────────╝")
11+
print(f"Version - {__version__}")
1112
print("")

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![acadlib.png](https://i.postimg.cc/xjBy2P1f/acadlib.png)](https://postimg.cc/5jqF5LzT)
22

3-
# AutoCAD - python library Latest Version 0.1.9
3+
# AutoCAD - python library Latest Version 0.1.10
44
[![GitHub](https://img.shields.io/badge/GitHub-Jones--peter-181717?style=for-the-badge&logo=github&logoColor=white)](https://github.com/Jones-peter) [![Instagram](https://img.shields.io/badge/Instagram-jones__peter__-E4405F?style=for-the-badge&logo=instagram&logoColor=white)](https://www.instagram.com/jones_peter__/) [![LinkedIn](https://img.shields.io/badge/LinkedIn-Jones--Peter-0A66C2?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/jones-peter-121157221/) [![Website](https://img.shields.io/badge/Website-jonespeter.site-0078D4?style=for-the-badge&logo=google-chrome&logoColor=white)](https://jonespeter.site)
55

66
[![PyPI version](https://img.shields.io/pypi/v/AutoCAD)](https://pypi.org/project/AutoCAD/)
@@ -133,10 +133,8 @@ cad = AutoCAD()
133133
insertion_point=APoint(30, 30, 0),
134134
data=data,
135135
headers=headers,
136-
title="My Custom Table",
137136
col_widths=[30, 30, 30],
138137
text_height=2.0,
139-
alignment=Alignment.CENTER
140138
)
141139
table_obj = cad.add_table(table)
142140
```
@@ -320,7 +318,18 @@ cad = AutoCAD()
320318
```python
321319
cad.open_file("path/to/open.dwg")
322320
```
323-
321+
- **send_command(command) & send_commands(command_list[])**: Opens an existing file.
322+
323+
```python
324+
cad.send_command("LINE 0,0 100,100 ")
325+
commands_to_run = [
326+
"-LAYER N NewLayer C 1 NewLayer \r",
327+
"LAYER S NewLayer \r",
328+
"CIRCLE 50,50 25\r"
329+
]
330+
cad.send_commands(commands_to_run)
331+
```
332+
324333
### View Management 🔍
325334
- **zoom_extents():** Zooms the viewport to display all objects.
326335

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
# The full version, including alpha/beta/rc tags
2727
# This should match the version in your README/pyproject.toml
28-
release = '0.1.9'
28+
release = '0.1.10'
2929

3030

3131
# -- General configuration ---------------------------------------------------

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from setuptools import setup, find_packages
22
import sys
3-
3+
from AutoCAD import __version__
44
requirements = ['psutil']
55
# Add Windows-specific requirements only when on Windows
66
if sys.platform == 'win32':
77
requirements.append('pywin32')
88

99
setup(
1010
name="AutoCAD",
11-
version="0.1.9",
11+
version=__version__,
1212
packages=find_packages(),
1313
install_requires=requirements,
1414
entry_points={

0 commit comments

Comments
 (0)