select only 1 block with effective name on multipe layouts

select only 1 block with effective name on multipe layouts

gisbradokla
Participant Participant
1,025 Views
6 Replies
Message 1 of 7

select only 1 block with effective name on multipe layouts

gisbradokla
Participant
Participant

I am building  a lisp to run without any interaction by the user. Also to run in accoreconsole on a list of mutliple drawings.

The anonymous name of the dynamic block on paperspace changes with different sets of drawings. (e.g.*U23, *U22, *U21)

I don't understand why this occurs. Nor do I understand why I can't just select the block with it's name "PRELIM_DYN". But I am able to select it with only the anonymous name (as long as i change my code to for the specific name. Also if I try to use 

 

 

 

(ssget "_X" '((0 . "INSERT") (2 . "`*U*,BLOCKNAME1")))

 

 

 

it selects other anonymous blocks in the drawing.

 

 

I am trying to change several things about this code. 

1. to select the prelim_dyn block with it's effective name/s and delete all instances

2. sometimes the insert uses the bottom of the block and other times it uses the middle.

3. get a variable for the pdf output location

4. check that all layouts are existing 

5. change the exportpdf command to export but need to select all layouts and export all to 1 pdf.

1st things first. #1 priority is to select the prelim_dyn Dynamic Block on all layouts and delete all instances of it. 

This block only exists in paperspace (no modelspace insertions)

 

 

 

 

(defun c:rs (/ ss1)
(setq filedia "0")
(setq cmddia "0")
(setq origPath (strcat (getenv "ACAD") ";")
	  addPath (strcat "X:\\MYPROGRAMS\\PDF_Creator\\Resources;")
	  newPath (strcat origPath addPath))
;set new ACAD string
(setenv "ACAD" newPath)
(setq NEWFILE (strcat (getvar "dwgprefix") "COMPLETE\\" (vl-filename-base (getvar "dwgname")) "_S"))
(setvar "ctab" "WELLSITE")
(if (setq ss (ssget "_x"
                     (list '(0 . "INSERT")
                           '(2 . "`*U21"))))
   (command "._erase" ss "")
   (prompt "\n** No blocks found ** "))
(command "._insert" "*SEAL" "6.74,2.94,0" "1" "0")
(setq ss nil)
(setvar "ctab" "SITE")
(if (setq ss (ssget "_x"
                     (list '(0 . "INSERT")
                           '(2 . "`*U21"))))
   (command "._erase" ss "")
   (prompt "\n** No blocks found ** "))
(command "._insert" "*SEAL" "1.94,2.59,0" "1" "0")
(setq ss nil)
(setvar "ctab" "C-SITE")
(command "._insert" "*SEAL" "7.05,0.92,0" "1" "0")
(command "-purge" "B" "`*U21,PRELIM_DYN" "N")
(command "_saveas" "" NEWFILE)
(command "EXPORTPDF" "")
(setvar "ctab" "C-SITE")
(command "_plot" "" "" "" "" "" "" "")
(command "_qsave")
(command "_close")
(setq filedia "1")
(setq cmddia "1")
(princ)
)

 

 

 

0 Likes
Accepted solutions (1)
1,026 Views
6 Replies
Replies (6)
Message 2 of 7

john.uhden
Mentor
Mentor

@gisbradokla
#1 - "`*U*" means ALL unnamed (anononymous) blocks.
#2 - You can use the ERASE command only in the current space. You should entdel each one of the items in the selection set, or vla-delete the vla-object thereof.
#3 - The same is true for the INSERT command... current space only. But I think you could entmake an insert in a different space if you specify the 410 code for the layout name.
#4 - How do you know that "*U21" is the correct target?
You may have to iterate through the entire selection set of blocks and vlax-get the 'EffectiveName (if you know it).
Oops, we have learned recently that vlax-* functions are not available in ACCORECONSOLE, but vl-* and vla-* functions are.
#5 - You don't have to purge anonymous blocks.

John F. Uhden

0 Likes
Message 3 of 7

gisbradokla
Participant
Participant

Thanks 

but in 1 dwg it is u21 and U22 or U23 in another. 
but if I do U* it gets other blocks that need to stay. 
I need to get the name Prelim_dyn but it doesn’t work even when I have set the layout to the correct one. 
thanks for the help

i wish I understood how to make effective_name work. 

0 Likes
Message 4 of 7

pbejse
Mentor
Mentor
Accepted solution

@gisbradokla wrote:

i wish I understood how to make effective_name work. 


Demo for effective name:

 

(Defun c:demo ( / ss i ent spc ipt )							    
	(if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "`*U*,PRELIM_DYN"))))
	  (repeat (setq i (sslength ss))
	    (setq ent (ssname ss (setq i (1- i)))
		  spc (cdr (assoc 410 (entget ent))))
	    
	    (setq Target_blk (getpropertyvalue ent "BlockTableRecord/Name"))
	    (if (and
		  (eq (getpropertyvalue ent "BlockTableRecord/Name") "PRELIM_DYN")
		  (setq ipt (cadr (assoc spc
				   '(("WELLSITE" "6.74,2.94,0")
				     ("SITE" "7.05,0.92,0")
				     ("C-SITE" "7.05,0.92,0")
				    )
			    )
			)
			)
		  )
		  (progn
		    (setvar 'ctab spc)
		    (command "._erase" ent "")
		    (command "._insert" "*SEAL" "_non" ipt "1" "0")
		    )
		  )
	      )
	    )
    (princ)
       )

 

HTH 

0 Likes
Message 5 of 7

gisbradokla
Participant
Participant

Thanks much.

I think i see how the effective name part works. (selecting the block table record name with any block *U*,prelim_dyn that matches the name prelim_dyn)  is that close?

and thanks so much for the other part making the insert with 1 setq 

 

0 Likes
Message 6 of 7

gisbradokla
Participant
Participant

my only problem is the C-SITE doesn't already have a prelim_dyn so it doesn't get the seal inserted.

I will try to just break that out to be like i had it before.

0 Likes
Message 7 of 7

pbejse
Mentor
Mentor

@gisbradokla wrote:

my only problem is the C-SITE doesn't already have a prelim_dyn so it doesn't get the seal inserted.

I will try to just break that out to be like i had it before.


What you're saying is delete the block (PRELIM_DYN) if its there

Insert *seal if it does not exists on the layout YES?

 

 

 

0 Likes