Select block by name within lisp

Select block by name within lisp

anieves228
Enthusiast Enthusiast
1,222 Views
13 Replies
Message 1 of 14

Select block by name within lisp

anieves228
Enthusiast
Enthusiast

Hi all,

 

I want to use LISP to select blocks by name. Ive seen here in the forums that most scripts pause and wait for user input to select the blocks. But I know the block's name and want to choose it within the lisp without user input. so the command selects the block. 

 

Im using this to automate Placing an engineer's signature, deletes it, then purges the dwg. 

 

How can I do this? The selection part. 

 

Thank you!

0 Likes
Accepted solutions (1)
1,223 Views
13 Replies
Replies (13)
Message 2 of 14

paullimapa
Mentor
Mentor
Accepted solution

assuming your block is not dynamic and has name called: my block

then you can use the following code to insert:

(command "_.-Insert" "my block" "0,0" "1" "1" "0")

next to select & delete all occurrences of "my block" use the following code:

(setq ss (ssget "_X" '((0 . "INSERT") (2 . "my block")))) ; select all blocks matching name
(repeat (setq i (sslength ss))(vla-delete (vlax-ename->vla-object (ssname ss (setq i (1- i)))))) ; delete all occurences of selected block

Finally to purge the block use the following code:

(command"_.-Purge" "_B" "my block" "_N")

 


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

ec-cad
Collaborator
Collaborator

I,m confused. You would not change the drawing if you insert myblock, select it, and delete it, and purge block myblock.

You would have no trace of that Engineer's signature in the drawing.

If your goal is to 'replace' myblock (last Engineer's signature), with a 'new' Engineer's signature, you

could Select the 'old' block (if exists), purge, (then) insert the myblock lastly.

If you want to go that route, here's paulli's code rearranged a bit.

(setq ss (ssget "_X" '((0 . "INSERT") (2 . "myblock")))) ; select all blocks matching name
(if ss
 (progn
  (repeat (setq i (sslength ss))(vla-delete (vlax-ename->vla-object (ssname ss (setq i (1- i)))))) ; delete all occurences of selected block
  (command"_.-Purge" "_B" "myblock" "_N")
 ); progn
); if

(command "_.-Insert" "myblock" "0,0" "1" "1" "0"); Insert updated Signature

(princ)

 

ECCAD

0 Likes
Message 4 of 14

john.uhden
Mentor
Mentor

@ec-cad ,

If "myblock" is the generic name for all signature insertions, then he just needs to get the replacement file name via (getfiled), and
(command "_.insert" (strcat myblock "=" <newfile_including path>))

(I just don't remember how to terminate the command.)

John F. Uhden

0 Likes
Message 5 of 14

paullimapa
Mentor
Mentor

one way to terminate is to add after the command insert sequence another command code:

(command "_.insert" (strcat myblock "=" <newfile_including path>))
(command) ; terminates the rest of the insert command steps

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

john.uhden
Mentor
Mentor

@paullimapa ,

One of the fellas with whom I recently worked got really good with dynamic blocks.

He made a signature block that somehow had all the PEs who would sign our plans including signature, name, address, license number, etc.  When you clicked on the block it would bring up a pop-up-list of all the engineers where you pick one and it would modify all the block's components.  Obviously the signature block was separate from the title block.

John F. Uhden

0 Likes
Message 7 of 14

paullimapa
Mentor
Mentor

nice


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

Sea-Haven
Mentor
Mentor

@john.uhden @paullimapa I have  a client they have a title block with around 20+ company logos, in a dynamic title block. Uses visibility states to display correct client logo. I wont go into it but the not used logos are removed as part of select client.

0 Likes
Message 9 of 14

anieves228
Enthusiast
Enthusiast

Hi all,

 

Sorry im finally back on this after other projects. But to clarify. We don't want signatures accessible to everyone and do not want to leave engineers' signatures on the network. We return some DWGs back to the clients (mainly utility clients). So for ethical and legal reasons, we do not leave signatures on the DWGs. Only on PDFs. In Illinois, digital signatures are required to be under the control of the respective engineer. 

0 Likes
Message 10 of 14

Kent1Cooper
Consultant
Consultant

So it sounds like you omitted a step in your first description, that of PLOTting the drawing.  Insert the signature, Plot, remove the signature, Purge.

 

How about having a routine just do this?

INSERT [the signature Block name can be built in, as already shown, or a file dialog can come up to select]

PLOT to PDF

U twice, once for the PLOT, the second for the INSERT, which will remove the Block definition in the process.

Kent Cooper, AIA
0 Likes
Message 11 of 14

anieves228
Enthusiast
Enthusiast
Well yes. The plotting is all setup. I have Lisps set up with all our printing settings so I can just can just call it. The problem was having was just being able to select the block. (which I had zero idea)
0 Likes
Message 12 of 14

anieves228
Enthusiast
Enthusiast

I don't get as much time to code as I would like too, so I have trouble, but thank you all for all your help!! It is working!!!

Eventually, I'll have a command or just a selection for each of our PE's signatures. The command will just streamline a task for us. Since in reality, only 2 people (including) will be applying signatures under the PE's instructions.So trying to make this task as quick as possible. We can Seal 1- 100 for any given project.

 

So the command does this in this order

 

Places signature

creates PDF

places it in a signed PDF folder

deletes signature

purges drawing

done

 

to give you insight into my code with your help here it is:

 

 

	(DEFUN C:sigdm ()
		(SETVAR "CMDECHO" 1)

			(SETVAR "CLAYER" "0")

			(setq SNAP
				(getvar "osmode")
			)

			(command 
				"osmode"
				"0"
			)

			(COMMAND 
				"-INSERT" 
				"C:/location/Engineer-SIGNATURE.dwg"
				(LIST 29.7 2)
				"1"
				"1"
				"0"
			)	

			;(command "explode" "last")

			(command "osmode" snap )
      
			(C:SLPDF) ; creates a signed pdf and places signed PDF in "02 SIGNED PDF" folder This command also Automatically Selects the Papaer size and paper orientation
      
      (setq ss (ssget "_X" '((0 . "INSERT") (2 . "Engineer-SIGNATURE")))) ; select all blocks matching name
      (repeat (setq i (sslength ss))(vla-delete (vlax-ename->vla-object (ssname ss (setq i (1- i)))))) ; delete all occurences of selected block
      
			;(command "erase")
    
      (c:PUA) ;purges all

		(SETVAR "CMDECHO" 1)
		(PROMPT "\n SIGNED PDF AND PLACED IN 02 SIGNED PDF FOLDER \n")
		(PRINC)
      
      
      (vl-load-com)
	)

 

 

0 Likes
Message 13 of 14

john.uhden
Mentor
Mentor

@anieves228 ,

How about just...

 

QSAVE

Places signature

creates PDF

places it in a signed PDF folder

deletes signature

purges drawing

QUIT or CLOSE (without saving)

done

?

John F. Uhden

0 Likes
Message 14 of 14

Sea-Haven
Mentor
Mentor

How many signatures ? If only a few can have a make choice selecting correct one before the Insert command, this is like adding 2 lines of code to your current code, have a look at examples at top of code. The dcl is made by the Multi radio program.

 

(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(setq ans (ah:butts but "V"   '("Choose " "AlanH" "John" "Anieves" "The other guy" ))) 	; ans holds the button picked value as a string

 

SeaHaven_0-1729294516420.png

 

 

 

0 Likes