Table Cell Height and Text Height Lisp Routine

Table Cell Height and Text Height Lisp Routine

jeff_Moskovciak
Enthusiast Enthusiast
1,038 Views
4 Replies
Message 1 of 5

Table Cell Height and Text Height Lisp Routine

jeff_Moskovciak
Enthusiast
Enthusiast

Hi, I'm writing a lisp routine to change the cell height and cell text height of a table to specific values. I can't get the ActiveX version to work, and so far with traditional it changes the text height to the incorrect value, and I can't get the cell height to change. Here is what I have so far, please let me know what I'm missing:

 

Traditional:

(defun c:changecell ()
  (setq a (car (entsel "\nSelect table to update: ")))
  (setq b (entget a))
  ; Update the text height and cell height
  (setq textheight (subst (cons 140 0.1875) (assoc 140 b)  b))
  (setq cellheight (subst (cons 141 0.359375) (assoc 141 textheight)  cellheight))
  (entmod cellheight)
  (entupd a)
  (prompt "\nDone")
(princ)
)
 
 
ActiveX:
(defun c:changecell2 ()
  (setq d1 (car (entsel "\nSelect cells to update: ")))
  (setq dp (entget d1))
  ; Update the text height and cell height
  (vla-setcelltextheight dp 0.359375)
  (prompt "\nDone")
(princ)
)
(vl-load-com)
0 Likes
Accepted solutions (2)
1,039 Views
4 Replies
Replies (4)
Message 2 of 5

MrJSmith
Advocate
Advocate
Accepted solution

I always use activex to modify autocad tables. They are strange though, you have to get their values through a method call not a property call. So vla-setcelltextheight will not work. You can find the available methods here. https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-7B82400C-53D0-4D1A-94FA-66BB3040F0AA

 

In your case, you'd properly either use the SetTextHeight method or the SetCellTextHeight method depending on your use case. Here is an example changing them by cell.

 

(defun c:tableChangeHeights ()
	(defun numberList (limit / numbers i)
	  (setq numbers '())
	  (setq i 0)
	  (while (<= i (- limit 1))
		(setq numbers (cons i numbers))
		(setq i (1+ i))
	  )
	  (reverse numbers)
	)
	
	(setq ss (ssget '((0 . "ACAD_TABLE"))))
	(setq table (ssname ss 0))
	(setq table (vlax-ename->vla-object table))
	(setq col (numberList (vla-get-Columns table))
		row (numberList (vla-get-Rows table))
	)
	(foreach r row
		(foreach c col
			; (print (strcat "Next Cell Row: " (itoa r) " Col: " (itoa c)))
			(setq cellTextHeight (vlax-invoke table 'GetCellTextHeight r c))
			; (print cellTextHeight)
			(vlax-invoke table 'SetCellTextHeight r c 0.14)
			; (print "Updated")
		)
	)
)

 

Note: The numberList function may have to be tweaked. For some reason, my CAD was starting count for r/c for the text heights at 0 though a previous function I created used 1 as the starting point. Not sure why the change.

Message 3 of 5

jeff_Moskovciak
Enthusiast
Enthusiast

This is great and very helpful, thank you so much. 

 

Also, when you use code such as (vlax-ename->vla-object table) or when you load vl-load-com, does it actually change the properties of the drawing or drawing objects? I need to be careful to not change the drawings themselves or objects in the drawing with these routines. 

0 Likes
Message 4 of 5

MrJSmith
Advocate
Advocate
Accepted solution

From my understanding, no. vl-load-com just loads the visual LISP functions. However, I believe modern day versions of CAD do this automatically yet people still put it often as a catch-all. It only needs to be done once and it doesn't do anything if it is already loaded. Better safe than sorry.

 

The vlax-ename->vla-object  function just returns the autocad entity to the vla version of the entity. Basically AutoCAD data base objects that are interacted with via LISP are entities but when using VLA functions, you need the VLA version of that object in the data base so that function acts as a translator. Everything remains the same, you are getting the same object that is now in a form that can be manipulated via a different language (LISP vs ActiveX). 

0 Likes
Message 5 of 5

jeff_Moskovciak
Enthusiast
Enthusiast

Got it, thank you so much for all the help. 

0 Likes