How to lock all table cells in a drawing

How to lock all table cells in a drawing

Anonymous
Not applicable
3,556 Views
29 Replies
Message 1 of 30

How to lock all table cells in a drawing

Anonymous
Not applicable

I'm looking for a command to incorporate into my routine that will lock all the cells in various tables at the end of my routine. Does anybody know how to do this? Thanks!

Accepted solutions (2)
3,557 Views
29 Replies
Replies (29)
Message 21 of 30

ronjonp
Mentor
Mentor
Accepted solution

@hak_vz 

FWIW .. this would be a bit more flexible 😎

(defun tablestuff (mode / ss i j k nrows ncols to)
  (cond	((setq ss (ssget "_X" '((0 . "ACAD_TABLE"))))
	 (setq i 0)
	 (while	(< i (sslength ss))
	   (setq to (vlax-ename->vla-object (ssname ss i)))
	   (setq nrows (vlax-get to 'rows)
		 ncols (vlax-get to 'columns)
		 j     0
	   )
	   (while (< j nrows)
	     (if (= (vlax-invoke-method to 'getrowtype j) actitlerow)
	       (vla-setcellstate to j 0 mode)
	     )
	     (progn (setq k 0) (while (< k ncols) (vla-setcellstate to j k mode) (setq k (+ k 1))))
	     (setq j (+ j 1))
	   )
	   (setq i (+ i 1))
	 )
	)
  )
  (princ)
)
(defun c:lockalltables nil (tablestuff 1))
(defun c:unlockalltables nil (tablestuff 0))
0 Likes
Message 22 of 30

hak_vz
Advisor
Advisor

@ronjonp wrote:

FWIW .. this would be a bit more flexible 😎


Yes, you are right.

Last hour I spent my time reminding myself about scripting table object from the scratch and just posted it here.

I would probably optimize it later. 

 

In the end @Anonymous  selected this code as a solution. LOL

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 23 of 30

Anonymous
Not applicable

It works! Thanks so much for your time.

 

Now I need to figure out how to make this run automatically at the end of my routine.

 

Im super new to lisp so thank you!

0 Likes
Message 24 of 30

ronjonp
Mentor
Mentor
Accepted solution

@Anonymous wrote:

It works! Thanks so much for your time.

 

Now I need to figure out how to make this run automatically at the end of my routine.

 

Im super new to lisp so thank you!


Give this a try too .. I just noticed that the previous code had the flag set to unlock cells 🤣 ... sorry for the back and forth!

 

 

 

 

(defun _foo (mode / _allcellsto o s)
  (defun _allcellsto (tbl state / c r)
    ;; RJP » 2020-10-14
    ;; accellstatenone (0)
    ;; accellstatecontentlocked (1)
    ;; accellstatecontentreadonly (2)
    ;; accellstateformatlocked (4)
    ;; accellstateformatreadonly (8)
    ;; accellstatelinked (16)
    ;; accellstatecontentmodified (32)
    ;; accellstateformatmodified (64)
    (repeat (setq r (vla-get-rows tbl))
      (setq r (1- r))
      (setq c (vla-get-columns tbl))
      (repeat c (setq c (1- c)) (vl-catch-all-apply 'vla-setcellstate (list tbl r c state)))
    )
    (princ)
  )
  ;; Usage to lock all cells in all tables
  (if (setq s (ssget "_X" '((0 . "ACAD_TABLE"))))
    (foreach tbl (mapcar 'cadr (ssnamex s))
      (if (vlax-write-enabled-p (setq o (vlax-ename->vla-object tbl)))
	(_allcellsto o mode)
      )
    )
  )
  (princ)
)
(defun c:allcellsunlocked nil (_foo 0))
(defun c:allcellslocked nil (_foo 1))
(defun c:allcellsreadonly nil (_foo 2))
(defun c:allcellslockedandreadonly nil (_foo (+ 1 2)))
(defun c:allcellsformatlocked nil (_foo 4))

 

 

 

 

ronjonp_0-1602702045015.png

 

If you want this to run at the end of your code simply add this line to the end ( as well as the function of course )

 

(_foo 1)

 

0 Likes
Message 25 of 30

Anonymous
Not applicable

This is my current code and it isnt working. I have a unlock table code running at the startup as well as this. Did I just type the (_foo 1) in wrong or is this a bigger issue?

 

Thanks!!

 

(defun c:ft nil (ft (ssget "_:L" '((0 . "ACAD_TABLE")))) (princ))
(defun c:fr nil (fr (ssget "_:L" '((0 . "ACAD_TABLE")))) (princ))

(defun c:ftfr (/ s ) (if (setq s (ssget "_X" '((0 . "ACAD_TABLE")))) (progn (ft s) (fr s))) (princ))

(defun ft (ss / )
(princ "\n Select table objects to change the text height of all ceels to 0.10 ")
(if ss
((lambda (i / sn col row r c tbl)
(while (setq sn (ssname ss (setq i (1+ i))))
(setq tbl (vlax-ename->vla-object sn)
col (vla-get-columns tbl)
row (vla-get-rows tbl)
r 0
c 0
)
(repeat (* col row)
(if (eq r row)
(progn
(setq r 0)
(setq c (1+ c))
)
)
(vla-setcelltextheight tbl r c 0.10)
(setq r (1+ r))
)
)
)
-1
)
)
(princ)
)
(vl-load-com)


(defun fr (a / b c d i)
(if (and a
(setq b 0.27)
)
(repeat (setq i (sslength a))
(setq c (vlax-ename->vla-object (ssname a (setq i (1- i)))))
(setq d 1)
(while (< 0 d (vla-get-rows c))
(vla-setrowheight c d b)
(setq d (1+ d))
)
)
)
(princ)
)

(c:ftfr)

(defun _foo (mode / _allcellsto o s)
(defun _allcellsto (tbl state / c r)
;; RJP » 2020-10-14
;; accellstatenone (0)
;; accellstatecontentlocked (1)
;; accellstatecontentreadonly (2)
;; accellstateformatlocked (4)
;; accellstateformatreadonly (8)
;; accellstatelinked (16)
;; accellstatecontentmodified (32)
;; accellstateformatmodified (64)
(repeat (setq r (vla-get-rows tbl))
(setq r (1- r))
(setq c (vla-get-columns tbl))
(repeat c (setq c (1- c)) (vl-catch-all-apply 'vla-setcellstate (list tbl r c state)))
)
(princ)
)
;; Usage to lock all cells in all tables
(if (setq s (ssget "_X" '((0 . "ACAD_TABLE"))))
(foreach tbl (mapcar 'cadr (ssnamex s))
(if (vlax-write-enabled-p (setq o (vlax-ename->vla-object tbl)))
(_allcellsto o mode)
)
)
)
(princ)
)
(defun c:allcellsunlocked nil (_foo 0))
(defun c:allcellslocked nil (_foo 1))
(defun c:allcellsreadonly nil (_foo 2))
(defun c:allcellslockedandreadonly nil (_foo (+ 1 2)))
(defun c:allcellsformatlocked nil (_foo 4))

(_foo 1)

0 Likes
Message 26 of 30

ronjonp
Mentor
Mentor

What command are you calling? ( FT FR FTFR ?) If you want my code to run it has to be called within the function you're running.

0 Likes
Message 27 of 30

Anonymous
Not applicable

This is the error message i get-- 

 

error: no function definition: _FOO

0 Likes
Message 28 of 30

Anonymous
Not applicable

Those commands are there for changing the text and row height of my tables because my tables dont like autocad 2021

 

Long story short, my company's template is really buggy with autocad 2021 so im trying to find a function to fix it all upon startup so we can all move to 2021

0 Likes
Message 29 of 30

ronjonp
Mentor
Mentor

Then you have not loaded the function? Need to run an errand back in a bit.

0 Likes
Message 30 of 30

pbejse
Mentor
Mentor

@ronjonp wrote:

You need to post your drawing .. can't troubleshoot a screen capture.


😆 Very true. 

Legend has it, there is one forum member still staring intently at the snapshot ...

 

0 Likes