How to lock all table cells in a drawing

How to lock all table cells in a drawing

Anonymous
Not applicable
3,533 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,534 Views
29 Replies
Replies (29)
Message 2 of 30

pbejse
Mentor
Mentor

@Anonymous wrote:

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!


LOCKED.png

Only I have the key 🙂

 

0 Likes
Message 3 of 30

Anonymous
Not applicable

So do you know or not?

 

0 Likes
Message 4 of 30

ronjonp
Mentor
Mentor

Try this  .. feed it your vla-table:

 

(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
;; (_allcellsto (vlax-ename->vla-object (car (entsel))) 1)

 

0 Likes
Message 5 of 30

pbejse
Mentor
Mentor

@Anonymous wrote:

So do you know or not?

 


Since you ask nicely, No I Do Not Know, suffering from ID 10 T syndrome.

FWIW, if you are wanting to lock ALL cells might as well lock the table itself.  uhhm layer .. lock.. maybe

 

EDIT: No need for the act now @ronjonp  posted the code before i had the chance 😄

 

0 Likes
Message 6 of 30

pbejse
Mentor
Mentor

@ronjonp wrote:

Try this  .. feed it your vla-table:


You spoiler you 😁

Party pooper.

 

 

0 Likes
Message 7 of 30

ronjonp
Mentor
Mentor

@pbejse wrote:

@ronjonp wrote:

Try this  .. feed it your vla-table:


You spoiler you 😁

Party pooper.

 

 


🤓

0 Likes
Message 8 of 30

Anonymous
Not applicable

Hey! thanks for the response!

 

This is what I'm currently using to unlock all the table cells in my drawing-- I figured it would be a quick easy fix to use the same script to lock all my cells but I'm having some difficulty.

(defun AH:lockcell ( / x y)
(setvar 'ctab "Model")
(setq y 0)
(setq ss (ssget "X" (list (cons 0 "ACAD_TABLE"))))
(repeat (setq X (sslength ss))
(setq obj (vlax-ename->vla-object(ssname ss (setq x (- x 1)))))
(setq nRows (- (vla-get-rows obj) 1))
(setq nCols (- (vla-get-Columns obj) 1))
(setq row 0)
(setq cell 0)
(vla-put-RegenerateTableSuppressed obj :vlax-true)
(while (<= row nRows)
(while (<= cell nCols)
(vla-setcellstate obj row Cell 0)
(setq cell (1+ cell))
(princ (strcat "\nRow : " (itoa row) " , cell " (itoa cell)))
);while
(setq row (1+ row))
(setq cell 0)
)

(vla-put-RegenerateTableSuppressed obj :vlax-false)
)(princ)
)

(AH:unlockcell)

 

I have tried changing this value to a 1, 2, and 4 but it doesn't seem to work. Any ideas? I feel like it should be as simple as changing a single argument in a single command.

 

Pls help this will literally perfect my script

0 Likes
Message 9 of 30

ronjonp
Mentor
Mentor

OK .. spoon and all 😀

 

(defun c:foo (/ _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 0)
      )
    )
  )
  (princ)
)

 

Message 10 of 30

cadffm
Consultant
Consultant

Try it like lazy stupid people like me 

Set one cell lock like you  want (format,content or both),

then check the property..

Reverse engineering 😉

Sebastian

0 Likes
Message 11 of 30

Anonymous
Not applicable

That doesnt run at all for me 😞

0 Likes
Message 12 of 30

ronjonp
Mentor
Mentor

@Anonymous wrote:

That doesnt run at all for me 😞


Did you check your tables? The code above does not return anything. Works on my test drawing 🤔

0 Likes
Message 13 of 30

Anonymous
Not applicable

My tables are currently unlocked and I ran that routine and nothing happened. But yes it returns nothing, but the goal isnt being accomplished 😕 

0 Likes
Message 14 of 30

ronjonp
Mentor
Mentor

Post your sample drawing.

0 Likes
Message 15 of 30

Anonymous
Not applicable

rmurphyUCDDR_0-1602699429789.png

 

0 Likes
Message 16 of 30

ronjonp
Mentor
Mentor

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

Message 17 of 30

Anonymous
Not applicable

here ya go, had to strip it down to avoid giving away any company info 🤐

0 Likes
Message 18 of 30

ronjonp
Mentor
Mentor

Not sure what's happening for you. They all appear to lock when I run the code (FOO) .. take a looksee.

Message 19 of 30

hak_vz
Advisor
Advisor
(defun c:LockAllTables nil (LockAllTables))
(defun c:UnlockAllTables nil (UnlockAllTables))

(defun LockAllTables ( / 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 accellstatecontentlocked ))
							(progn
									(setq k 0)
									(while (< k ncols)(vla-SetCellState to j k accellstatecontentlocked)(setq k (+ k 1)))
							)
					(setq j (+ j 1))
					)
			(setq i (+ i 1))
			)
		)
	)
(princ "\nAll tables are locked!")
(princ)
)

(defun UnlockAllTables ( / 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 0 ))
							(progn
									(setq k 0)
									(while (< k ncols)(vla-SetCellState to j k 0)(setq k (+ k 1)))
							)
					(setq j (+ j 1))
					)
			(setq i (+ i 1))
			)
		)
	)
(princ "\nAll tables are unlocked!")
(princ)
)

 

If it works then accept is as solution!

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 20 of 30

Anonymous
Not applicable

It is not doing anything for me when I type foo in and hit enter

 

Literally nothing. I run an unlock routine first, and then the lock code you provided. I wonder if the unlock routine is overpowering the lock routine since it is automatic in my drawing?

0 Likes