Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Check for Block attribute values in paperspace multiple pages?

7 REPLIES 7
Reply
Message 1 of 8
mid-awe
666 Views, 7 Replies

Check for Block attribute values in paperspace multiple pages?

Hi all,

 

I have several title blocks each in their own paperspace pages. Any one could have the attribute filled in, but more than likely only one page will have values filled in the attributes. I am looking for a VL method for finding which pages title block is filled in so that I can get those values and fill in the equivalent attributes for all of the other pages. Currently I am using a long set of :

 

(IF (setvar "ctab" "8.5x11")
    (IF	(TBLSEARCH "BLOCK" "TB-8.5x11")
      (IF (/= "" (get-att "OWNER" "TB-8.5x11")) ; Function to read a named attribute
	(editblk "TB-8.5x11") ; Function to pull up the attdia
	(IF (setvar "ctab" "11x17")
	  (IF (TBLSEARCH "BLOCK" "TB-11x17")
	    (IF	(/= "" (get-att "CUSTNMFIRST" "TB-11x17"))
	      (progn ; At the last page ditch the search and prompt for data entry
		(SETQ OWNERF (GETSTRING "\n\t =>> Owner's FIRST name : ")
                      OWNERL (GETSTRING "\n\t =>> Owner's LAST name : ")
                )
		(dict-put "OWNERNAME" "FIRST" OWNERF) ; Function to store information for later
		(dict-put "OWNERNAME" "LAST" OWNERL) ; Function to store information for later
	      )
              (progn ; Once filled attribute is found get and store the information for later
                (SETQ OWNERF (get-att "CUSTNMFIRST" "TB-11x17")
                      OWNERL (get-att "CUSTNMLAST" "TB-11x17")
                 )
                 (dict-put "OWNERNAME" "FIRST" OWNERF) ; Function to store information for later
		 (dict-put "OWNERNAME" "LAST" OWNERL) ; Function to store information for later
              )
	    )
	  )
	)
      )
      (PRINC "\n\t *>> Nothing Found! <<*\n")
    )
  )

 The example is just a very simplified version of what I'm doing. I just need to find the information, if it exists in any page and store it for later. Afterward, I'll fill in each page's TitleBlock with the stored information. If nothing is found I'll pull up the attdia or just prompt for immediately essential information.

 

I know that this can be done much more efficiently. As I am currently flipping through the pages too much action is occuring on the screen and it makes some people nervous. With VL I should be able to run the search quietly, but I would still like to (setvar "ctab" "to the page with the filled attribute value") after the LISP is finished storing values.

 

Any advice, suggestions, LISP is greatly appreciated. Thank you in advance. Smiley Frustrated

7 REPLIES 7
Message 2 of 8
umlauf2
in reply to: mid-awe

i guess

result of tblsearch is only, if this block is defined

make an ssget "_X" filter

with your block required

you will get more blocks with this name

step through with ssname (sslength)

than you can find the block with attributes inserted, and afterwards fill in the attributes in all blocks

 

Message 3 of 8
mid-awe
in reply to: mid-awe

Ok, I believe I'm getting closer.

 

I found this thread :

Change attribute multiple paper space tabs

 

I believe a variation of this might get me most of the way. Only, I don't want to immediately change the attribute value, I just need to check for the any value other than "", and if it is found then I need to do get it for later. 

Message 4 of 8
pbejse
in reply to: mid-awe


@mid-awe wrote:

Ok, I believe I'm getting closer.

 

I found this thread :

Change attribute multiple paper space tabs

 

I believe a variation of this might get me most of the way. Only, I don't want to immediately change the attribute value, I just need to check for the any value other than "", and if it is found then I need to do get it for later. 


Interesting idea mid-awe, explain this to us.

 

 <<< and if it is found then I need to do get it for later. >>>> 

 

 Assign the value as a dictionary entry and leave it there?

 

Should the "TB-8.5x11" be at layout tabname "8.5x11"? if not then what? same goes for "TB-11x17" at layout name "11x17"? 

 

Is it like check for values on either "TB-8.5x11" and  "TB-11x17" if found then assign value to dictionary OWNERNAME?  or "TB-8.5x11" values will take precedence over  "TB-11x17" ? 

 

is it one or the other? 

 

Message 5 of 8
mid-awe
in reply to: pbejse

Thank you for the response. I have been very busy and unable to check this forum for any activity.

 

It is like, "check for values on either "TB-8.5x11" and  "TB-11x17" if found then assign value to dictionary OWNERNAME?" And then, assign the values to all paperspace TB-x. Most likely only one Layout will Have any values entered, but I need to find which Layout has values, get those values and write them to all the Layout Title Blocks.

 

It would be much nicer if attributes could be set to contain the same value auto-syncronized, like vars. I did consider doing a gazillion viewports with the attributes stored in model-space somewhere but only as a last resort. Smiley Indifferent

Message 6 of 8
pbejse
in reply to: mid-awe


Thank you for the response. I have been very busy and unable to check this forum for any activity.

 

I've been busy myself this past few days.

 

 It would be much nicer if attributes could be set to contain the same value auto-syncronized, 

 

We can use FIELD value for the rest of the TBLocks

 

Try this:

 

(defun c:OwnerData ( / _AttFunc GetID _checkValue aDoc ss sel data _ctab)
(defun _AttFunc  (en lst flg / v s)
      (foreach at  (vlax-invoke (if (eq (type en) 'VLA-OBJECT)
                                  en (vlax-ename->vla-object en))
                        'GetAttributes)
            (cond ((and
                         (setq tg (assoc (vla-get-tagstring at) lst))
                         (setq v (list (Car tg) (if (cadr tg) (cadr tg)
                                         (vla-get-textstring at)) (GetID at)))
                         (setq s (cons v s))
			 flg
                         (vla-put-textstring at (cadr tg)))
                  )
            )
        )
      s 
      )
(defun GetID (j)
              (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                      (if (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                        (vlax-invoke-method (vla-get-Utility adoc) 'GetObjectIdString j :vlax-false)
                        (itoa (vla-get-Objectid j))
                      )
                      ">%).TextString>%"
              )
            )
(defun _checkValue (selset flg s1 s2 / d f ownerf ownerl)
       (setq d (vl-some '(lambda (x)
		            	(if  (and (setq f (_AttFunc x (list (list "CUSTNMFIRST" s1)
                                                                    (list "CUSTNMLAST" s2)) flg))
                                          (vl-every '(lambda (y)
                             				(/= y "")) (mapcar 'cadr f)))
                                  	(list   x f)))
					selset)
                      )
  	(if (null d)
          	(progn
	                   (setq ownerf (getstring "\n\t =>> Owner's FIRST name : ")
	                         ownerl (getstring "\n\t =>> Owner's LAST name : ")
	                   )
                  	(_checkValue selset t ownerf ownerl)
                  )
          d
          )
  )
                  	
  
(setq aDoc (vla-get-activedocument (vlax-get-acad-object)))  
  	(cond ((and
;;;		Suggest you insert regapp test ("OWNERNAME") here            		;;;
          	(setq ss (ssget "_X" '((0 . "INSERT")(66 . 1)(2 . "TB-8.5x11,TB-11x17")(410 . "~Model"))))
          	(setq sel (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
                (setq data (_checkValue sel nil nil nil))
                (setq _ctab (cdr (assoc 410 (entget (car data)))))
          	(setq sel (vl-remove (car data) sel) data (Cadr data))
;;;											;;;
;;;             (dict-put "OWNERNAME" "FIRST" (cadar data))
;;;		(dict-put "OWNERNAME" "LAST" (cadadr data)) 
;;;											;;;
          	(setq data (mapcar '(lambda (o)(list (car o)(last o))) data))            
          	(foreach tblk sel
          		 (_AttFunc tblk data t))
                (setvar 'ctab _ctab)
                )))
  (princ)
  )

 

If there are no data on BOTH "CUSTNMFIRST" and "CUSTNMLAST" then it will prompt you for the data.

Now if there are data found , it will assign the values on the other tblock(s) as field value.

and then set the layout where the data was found as current.

 

Curious why you need to assign the values to the OWNERNAME dictionary though. Perhaps you dont need to do that as code already pass the values on the other tblocks. im just saying.but if you still need to , take out the comments

 

;;;											;;;
;;;             (dict-put "OWNERNAME" "FIRST" (cadar data))
;;;		(dict-put "OWNERNAME" "LAST" (cadadr data)) 
;;;											;;;

please ensure that the "OWNERNAME" dictionary exists and dict-put function is loaded. 

 

 I did consider doing a gazillion viewports with the attributes stored in model-space somewhere but only as a last resort

 

I dont get this part mid-awe , notice the code i posted excludes Model space blocks and not layout name dependent.

 

HTH

Message 7 of 8
pbejse
in reply to: pbejse

arrggh. Found a bug. 

 

Field values will be considered as "" 

 

See attached file

 

 

 

 

Message 8 of 8
mid-awe
in reply to: pbejse

Thank you, I will give this a try in the morning. I store the values to the dictionary because it is the easiest way that I know of to access the data for printable reports and editing drawing properties.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost