@@ -525,6 +525,7 @@ def explode_object(self, obj):
525525 except Exception as e :
526526 raise CADException (f"Error exploding object: { e } " )
527527
528+
528529 def get_block_extents (self , block_name ):
529530 """
530531 Gets the geometric extents (bounding box) of a block reference.
@@ -538,28 +539,56 @@ def get_block_extents(self, block_name):
538539 try :
539540 for entity in self .iter_objects ("AcDbBlockReference" ):
540541 if entity .Name == block_name :
541- min_point = APoint ( * entity .GeometricExtents . MinPoint )
542- max_point = APoint ( * entity .GeometricExtents . MaxPoint )
543- return min_point , max_point
542+ print ( entity .GetBoundingBox )
543+ min_pt , max_pt = entity .GetBoundingBox ( )
544+ return APoint ( * min_pt ), APoint ( * max_pt )
544545 except Exception as e :
545546 raise CADException (f"Error getting extents of block '{ block_name } ': { e } " )
546547
548+ def get_entity_extents (self , entity ):
549+ """
550+ Returns the bounding box (min and max APoint) of any AutoCAD entity using GetBoundingBox.
551+
552+ Args:
553+ entity: The AutoCAD COM object (line, block, polyline, etc.)
554+ Returns:
555+ tuple(APoint, APoint): Min and Max APoint
556+ Raises:
557+ CADException: If bounding box can't be computed
558+ """
559+ try :
560+ min_pt , max_pt = entity .GetBoundingBox ()
561+ return APoint (* min_pt ), APoint (* max_pt )
562+ except Exception as e :
563+ raise CADException (f"Cannot get bounding box for entity: { e } " )
564+
547565 def add_overall_dimensions (self , entity ):
548566 """
549- Adds overall horizontal and vertical dimensions to an entity based on its geometric extents .
567+ Adds overall horizontal and vertical dimensions to an entity based on its bounding box .
550568 Args:
551569 entity: The AutoCAD object to dimension.
552570 Raises:
553571 CADException: If dimensions cannot be added.
554572 """
555573 try :
556- min_point , max_point = APoint (* entity .GeometricExtents .MinPoint ), APoint (* entity .GeometricExtents .MaxPoint )
557- self .add_dimension (Dimension (min_point , APoint (max_point .x , min_point .y , min_point .z ),
558- APoint (min_point .x , min_point .y - 5 , min_point .z ), DimensionType .ALIGNED ))
559- self .add_dimension (Dimension (min_point , APoint (min_point .x , max_point .y , min_point .z ),
560- APoint (min_point .x - 5 , min_point .y , min_point .z ), DimensionType .ALIGNED ))
574+ min_point , max_point = self .get_entity_extents (entity )
575+
576+ self .add_dimension (Dimension (
577+ min_point ,
578+ APoint (max_point .x , min_point .y , min_point .z ),
579+ APoint ((min_point .x + max_point .x ) / 2 , min_point .y - 5 , min_point .z ),
580+ DimensionType .ALIGNED
581+ ))
582+
583+ self .add_dimension (Dimension (
584+ min_point ,
585+ APoint (min_point .x , max_point .y , min_point .z ),
586+ APoint (min_point .x - 5 , (min_point .y + max_point .y ) / 2 , min_point .z ),
587+ DimensionType .ALIGNED
588+ ))
589+
561590 except Exception as e :
562- raise CADException (f"Error adding overall dimensions: { e } " )
591+ raise CADException (f"Failed to add overall dimensions: { e } " )
563592
564593 def get_user_defined_blocks (self ):
565594 """
@@ -1193,18 +1222,19 @@ def zoom_extents(self):
11931222
11941223 def zoom_to_object (self , obj ):
11951224 """
1196- Zooms the active viewport to fit a specific object.
1225+ Zooms the active viewport to fit a specific object using GetBoundingBox .
11971226 Args:
11981227 obj: The AutoCAD object to zoom to.
11991228 Raises:
12001229 CADException: If the zoom operation fails.
12011230 """
12021231 try :
1203- min_point_variant = win32com . client . VARIANT ( pythoncom . VT_ARRAY | pythoncom . VT_R8 ,
1204- obj . GeometricExtents . MinPoint )
1205- max_point_variant = win32com .client .VARIANT (pythoncom .VT_ARRAY | pythoncom .VT_R8 ,
1206- obj . GeometricExtents . MaxPoint )
1232+ min_pt , max_pt = obj . GetBoundingBox ()
1233+ min_point_variant = win32com . client . VARIANT ( pythoncom . VT_ARRAY | pythoncom . VT_R8 , min_pt )
1234+ max_point_variant = win32com .client .VARIANT (pythoncom .VT_ARRAY | pythoncom .VT_R8 , max_pt )
1235+
12071236 self .acad .ZoomWindow (min_point_variant , max_point_variant )
1237+
12081238 except Exception as e :
12091239 raise CADException (f"Error zooming to object: { e } " )
12101240
@@ -1219,7 +1249,6 @@ def add_table(self, table_obj: Table):
12191249 CADException: If the table cannot be created or data is inconsistent.
12201250 """
12211251 try :
1222- # --- 1. Validate input and determine dimensions ---
12231252 if not table_obj .data or not isinstance (table_obj .data [0 ], list ):
12241253 raise ValueError ("Input 'data' must be a non-empty list of lists." )
12251254
@@ -1256,13 +1285,13 @@ def add_table(self, table_obj: Table):
12561285
12571286 current_row = 0
12581287 if has_title :
1259- table .SetRowType (current_row , 1 ) # 1 = acTitleRow
1288+ table .SetRowType (current_row , 1 )
12601289 table .SetText (current_row , 0 , table_obj .title )
12611290 table .MergeCells (current_row , 0 , current_row , num_cols - 1 )
12621291 current_row += 1
12631292
12641293 if has_headers :
1265- table .SetRowType (current_row , 2 ) # 2 = acHeaderRow
1294+ table .SetRowType (current_row , 2 )
12661295 for col_idx , header_text in enumerate (table_obj .headers ):
12671296 table .SetText (current_row , col_idx , header_text )
12681297 current_row += 1
0 commit comments