Modifying this lisp to target a specific block name

Modifying this lisp to target a specific block name

amorozJPB28
Explorer Explorer
557 Views
6 Replies
Message 1 of 7

Modifying this lisp to target a specific block name

amorozJPB28
Explorer
Explorer

I have this lisp that will set block attribute width to 1. It works great but I have a need for it to only adjust the block attribute width for a specific block name. Does anyone know of a way to make it target a block by name?

 

Thanks!

Al Moroz
0 Likes
558 Views
6 Replies
Replies (6)
Message 2 of 7

SeeMSixty7
Advisor
Advisor

(setq ss (ssget "_X" '((0 . "INSERT")(66 . 1))))

Modify this line to be (Replace BLOCKNAME with the name of your block)

(setq ss (ssget "_X" '((0 . "INSERT")(2 . "BLOCKNAME")(66 . 1))))

 

This will not account for block that are dynamic that though.

 

Good luck

 

 

 

Message 3 of 7

paullimapa
Mentor
Mentor

in addition to @SeeMSixty7 reply, you can also include an option to type in a blockname:

(while(not blkname)

 (setq blkname (getstring T "\nEnter Block Name:"))

 (if(not(tblsearch"BLOCK" blkname))(setq blkname nil))

)

(setq ss(ssget "_X" (list '(0 . "INSERT") (cons 2 blkname) '(66 . 1))))

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 7

Sea-Haven
Mentor
Mentor

You can also just pick one block and get the block name to use in the ssget.

 

(setq blkname (cdr (assoc 2 (entget  (car  (entsel "\nPick a block for name "))))))
Message 5 of 7

paullimapa
Mentor
Mentor

excellent @Sea-Haven and that gives me another idea for @amorozJPB28 

(princ"\nPick a Block with Attributes for name...")
(while(not ss)(if(setq ss (ssget "_+.:E:S" '((0 . "INSERT")(66 . 1))))(setq blkname(cdr(assoc 2(entget(ssname ss 0)))))(setq ss nil)))

 


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

john.uhden
Mentor
Mentor

@paullimapa 

Very nice.

Just make sure that ss is local.

John F. Uhden

Message 7 of 7

Sea-Haven
Mentor
Mentor

This may be useful pick a dynamic block as well as a normal block part of another program, please not tested for this task.

(defun c:wow ( / )
(princ "\n Pick 1 block object for block name ")
(setq ss (ssget "+E:S" '((0 . "INSERT"))))
(if (= ss nil)
(alert "You may not have picked a block please try again")
(progn
(setq blk (vlax-ename->vla-object (ssname ss 0)))
(setq bname (vla-get-name blk))
(if (wcmatch bname "*U#*")
(setq bname (vla-get-effectivename blk))
)
(princ "\nSelect the blocks ")
(setq ss (ssget '((0 . "INSERT"))))
(if (= ss nil)
(alert "No blocks picked will exit")
(progn
  (setq lst '())
  (repeat (setq x (sslength ss))
  (setq lst2 '())
    (setq blk (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
	(setq blkname (vla-get-name blk))
	(if (wcmatch blkname "*U#*")
	(setq blkname (vla-get-effectivename blk))
	)
	(if (= blkname bname)
	(progn
          (setq atts (vlax-invoke blk 'Getattributes))
          (if (= atts nil)
		  (princ "No Atts")
		  (progn
		  (foreach att atts
	        (setq lst2 (cons (vla-get-textstring att) lst2))
          )
		  (setq lst (cons lst2 lst))
		  )
        )
    )
	)
  )
)
)
)
)
(princ)
)
0 Likes