Looking for a Lisp that can change the visibility states of series of blocks from cell value

Looking for a Lisp that can change the visibility states of series of blocks from cell value

ebandian
Participant Participant
3,578 Views
32 Replies
Message 1 of 33

Looking for a Lisp that can change the visibility states of series of blocks from cell value

ebandian
Participant
Participant

Hi Lisp experts, I needed some help regarding my project.

I want to run a specific lisp that can change the visibility state of a block which is stated on a Acad table (soon to be from Datalink).

 

Explanation:

Column 1 will be the name of the block

Column 2 will be the name of the visibility state to change to.

 

ebandian_0-1722539444037.png

 

 

0 Likes
3,579 Views
32 Replies
Replies (32)
Message 2 of 33

paullimapa
Mentor
Mentor

give VChgTbl.lsp a try


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 33

komondormrex
Mentor
Mentor

hey there,

check the following. sets given visibility state 'Visibility1'.

 

;********************************************************************************************************************

(defun get_dyn_property_by_name (dyn_property_name insert_object / dyn_property_found)
	(if (vl-some '(lambda (dyn_property) (= dyn_property_name
											(vla-get-propertyname (setq dyn_property_found dyn_property))
										 )
				  )
				  (vlax-invoke insert_object 'getdynamicblockproperties)
		)
		dyn_property_found
		nil
	)
)

;********************************************************************************************************************

(defun c:set_visibility_table (/ table_ename table_column_number table_dxf table_row_list table_all_row_list
								 dyn_property
							  )
	(vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
	(setq table_ename (car (entsel "\nPick table with blocks and vis-states: "))
	      table_column_number (vla-get-columns (vlax-ename->vla-object table_ename))
	      table_dxf (mapcar 'cdr (vl-remove-if-not '(lambda (group) (= 302 (car group))) (entget table_ename)))
	)
	(while table_dxf
		(setq table_row_list nil)
		(repeat table_column_number
			(setq table_row_list (append table_row_list (list (car table_dxf)))
			      table_dxf (cdr table_dxf)
			)
		)
	  	(setq table_all_row_list (append table_all_row_list (list table_row_list)))
	)
	(foreach insert (vl-remove-if '(lambda (insert) (not (member (vla-get-effectivename insert)
																 (mapcar 'car (cdr table_all_row_list))
														 )
													)
								   )
								   (mapcar 'vlax-ename->vla-object
								   		   (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget "_x" '((0 . "insert"))))))
								   )
					)
		(if (setq dyn_property (get_dyn_property_by_name "Visibility1" insert))
			(vla-put-value dyn_property (cadr (assoc (vla-get-effectivename insert) table_all_row_list)))
		)
	)
	(vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
	(princ)
)

;********************************************************************************************************************

 

0 Likes
Message 4 of 33

ebandian
Participant
Participant

Thank you so much Paullimapa

0 Likes
Message 5 of 33

paullimapa
Mentor
Mentor

glad to have helped...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 33

ebandian
Participant
Participant

Hi again paullimapa,

 

Do we have a way to still use it for a datalink table? or is there a way that we can convert the datalink table to a acad_table? I am planning to utilize using an excel file to generate the table reference for the visibility states of the blocks. Thanks in advance

0 Likes
Message 7 of 33

paullimapa
Mentor
Mentor

When you say datalink I'm assuming an excel table?

If so perhaps try this method to convert the excel table into acad_table:

https://www.autodesk.com/support/technical/article/caas/sfdcarticles/sfdcarticles/Importing-Excel-sp...


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 33

ebandian
Participant
Participant

Hi paullimapa ,

 

After I have tried this. the lisp does not work anymore. 

maybe the lisp only work on native acad table, that is not linked on excel.

Now, i am finding ways to transpose the value from datalink table to acad table

0 Likes
Message 9 of 33

paullimapa
Mentor
Mentor

Share the dwg that contains the converted table


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 10 of 33

ebandian
Participant
Participant

here

0 Likes
Message 11 of 33

paullimapa
Mentor
Mentor

I modified the code to accommodate all the additional text code formatting that comes from the Excel file into the AutoCAD cell text.

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 33

ebandian
Participant
Participant

I tried it on the datalink table but the block's visibility does not changed.

 

0 Likes
Message 13 of 33

paullimapa
Mentor
Mentor

I don't know why it doesn't work for you. Works perfectly for me.

See attached video demo


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 14 of 33

ebandian
Participant
Participant

Could it be I am lacking some drivers on my computer?

I am not sure why the command does not show on the clip, but I am using VCHGTBL.

Does the unregistered windows affect the lsp? lol

 

0 Likes
Message 15 of 33

paullimapa
Mentor
Mentor

You are using LT which my modified code does not support


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 16 of 33

ebandian
Participant
Participant

I see, it is a dead end for the datalink table

 

I guess I have to find another workaround, like transposing the cell content of the datalink table to the acad table

0 Likes
Message 17 of 33

paullimapa
Mentor
Mentor

Let me know if VChgTbl4LT.lsp works on LT


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 18 of 33

ebandian
Participant
Participant

Unfortunately, it still does not work.

 

0 Likes
Message 19 of 33

ebandian
Participant
Participant

Do I need to install additional drivers or dll on my pc so that it will work?

I tried the modified code for datalink table on Autocad 2021 version on my personal computer and it does not work. 

0 Likes
Message 20 of 33

paullimapa
Mentor
Mentor

That's odd. I've used the same code on 2020 to 2025 and there are no issues. There's nothing special about my setup. I'm running everything on Windows 10.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes