Skip to content

Commit 8e0ea86

Browse files
committed
fix: Move object error fix
1 parent 0e1c696 commit 8e0ea86

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

AutoCAD/AutoCAD_Module.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,29 @@ def set_layer_linetype(self, layer_name, linetype_name):
498498
# Move an object
499499
def move_object(self, obj, new_insertion_point):
500500
try:
501-
obj.Move(obj.InsertionPoint, new_insertion_point.to_variant())
501+
# Ensure the object is movable
502+
if not hasattr(obj, "Move"):
503+
raise CADException("The object does not support Move().")
504+
505+
# Get a base point: try InsertionPoint first, fallback to MinPoint
506+
try:
507+
from_point = win32com.client.VARIANT(
508+
pythoncom.VT_ARRAY | pythoncom.VT_R8, list(obj.InsertionPoint)
509+
)
510+
except AttributeError:
511+
# Fallback for objects without InsertionPoint
512+
from_point = win32com.client.VARIANT(
513+
pythoncom.VT_ARRAY | pythoncom.VT_R8, list(obj.GeometricExtents.MinPoint)
514+
)
515+
516+
# Convert new target point to VARIANT
517+
to_point = new_insertion_point.to_variant()
518+
519+
# Try moving the object
520+
obj.Move(from_point, to_point)
521+
502522
except Exception as e:
503-
raise CADException(f"Error moving object: {e}")
523+
raise CADException(f"Error moving object (type: {obj.EntityName}): {e}")
504524

505525
# Scale an object
506526
def scale_object(self, obj, base_point, scale_factor):

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.2"
2+
__version__ = "0.1.4"

docs/conf.py

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

55
project = 'AutoCAD'
66
author = 'Jones Peter'
7-
release = '0.1.3'
7+
release = '0.1.4'
88

99
extensions = [
1010
'sphinx.ext.autodoc',

setup.py

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

88
setup(
99
name="AutoCAD",
10-
version="0.1.3",
10+
version="0.1.4",
1111
packages=find_packages(),
1212
install_requires=requirements,
1313
entry_points={

tests/test.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1-
from AutoCADlib import AutoCAD
1+
import time
22

3-
cad = AutoCAD()
3+
from AutoCAD import AutoCAD, APoint
4+
5+
acad = AutoCAD()
6+
time.sleep(1)
7+
acad.open_file("D:/jones/Jones/USTS_WHEELSENSOR_SHEET.DWG")
8+
time.sleep(1)
9+
# Collect all block references
10+
blocks = list(acad.iter_objects("AcDbBlockReference"))
11+
12+
# Print details about the blocks
13+
for block in blocks:
14+
print(f"Block Name: {block.Name}, Insertion Point: {block.InsertionPoint}")
15+
time.sleep(2)
16+
if not block.Name == "A$C625fddc0":
17+
acad.move_object(block, APoint(0, 0, 0))

0 commit comments

Comments
 (0)