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

Search for existing MLeader wtih attribute value.

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
mid-awe
712 Views, 8 Replies

Search for existing MLeader wtih attribute value.

Hi all,

 

I'm working out a LISP for searching my entire drawing for a MLeader with a given value and then do something if it is found.

 

Currently, my code dies with 

 

; error: Automation Error. Description was not provided.

 

I do not know what is going wrong & I don't know what must be done next.

 

(DEFUN ML-SRCHSTR (TXT LBL / SS n_txt_LBL ENT P1 P2) ;|(ML-SRCHSTR TXT)|;
  (IF (SSGET "x" '((0 . "MULTILEADER")))
    (PROGN
      (SETQ ss (VLA-GET-ACTIVESELECTIONSET (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT))))
      (VLAX-FOR	ent ss
	(IF (VL-STRING-SEARCH txt (STRCASE (VLA-GET-TEXTSTRING ent)))
	  (PROGN
	    (VLA-CLEAR ss)
	    (INITGET 1 "Yes No")
	    (SETQ n_txt_LBL (STRCAT "\n\t =>> " LBL " Label EXISTS! Add another " txt "? ")
		  y_n	    (GETKWORD (strcat n_txt_LBL " [Yes/No]: "))
	    )
	    (IF	(= y_n "Yes")
	      (PROGN (ppa-L-PLANTXT)
		     (VL-CMDF "cmleaderstyle" "LandscapeQua")
		     (INITGET 1)
		     (SETQ P1 (GETPOINT "\n\t =>> Specify leader start point: ")
			   P2 (GETPOINT P1 "\n\t =>> Specify next point: ")
		     )
		     (VL-CMDF "_.mleader" P1 P2 txt)
	      )
	    )
	  )
	)
      )
      (IF (> (VLA-GET-COUNT ss) 0)
	(PROGN (ppa-L-PLANTXT)
	       (VL-CMDF "cmleaderstyle" "LandscapeQua")
	       (INITGET 1)
	       (SETQ P1	(GETPOINT "\n\t =>> Specify leader start point: ")
		     P2	(GETPOINT P1 "\n\t =>> Specify next point: ")
	       )
	       (VL-CMDF "_.mleader" P1 P2 txt)
	)
      )
    )
    (PROGN (ppa-L-PLANTXT)
	   (VL-CMDF "cmleaderstyle" "LandscapeQua")
	   (INITGET 1)
	   (SETQ P1 (GETPOINT "\n\t =>> Specify leader start point: ")
		 P2 (GETPOINT P1 "\n\t =>> Specify next point: ")
	   )
	   (VL-CMDF "_.mleader" P1 P2 txt)
    )
  )
)

 FYI - (ppa-L-PLANTXT) only sets my current layer.

 

My MLeader has a _TagBox & it is the attribute of the _TagBox that I am trying to check/compare the "txt" value.

 

Any help is greatly appreciated.

8 REPLIES 8
Message 2 of 9
alanjt_
in reply to: mid-awe

You have to step through the mleader's attributes and check the value from there. Issue is, if I remember correctly, there was a bug with attributed mleaders where you can't extract the textstring from each attribute. There's all kinds of issues when working with mleaders.

 

I hope I can be corrected on this. 😕

Message 3 of 9
BlackBox_
in reply to: mid-awe

Hi mid-awe, can you post a sample drawing (2010)?



"How we think determines what we do, and what we do determines what we get."

Message 4 of 9
mid-awe
in reply to: BlackBox_

BlackBoxCAD,

 

Thanks for taking a look. I've attached an example with 3 MLeaders each with different attribute values.

Message 5 of 9
hmsilva
in reply to: mid-awe

mid-awe.
as alanjt_ already said, there are problems accessing to the attibutes in attributed mleaders, as vla objects...
One way to accessing to the text string in a attributed mleader, is is through the entity data.
Untested...I don't have Autocad in this laptop

 

(DEFUN ML-SRCHSTR (TXT LBL / SS n_txt_LBL ENT P1 P2) ;|(ML-SRCHSTR TXT)|;
  (IF (setq ss (SSGET "x" '((0 . "MULTILEADER"))))
    (PROGN
       (setq itm 0 num (sslength ss))
      (while (< itm num)
        (setq edata (entget (ssname ss itm)))
	(IF (equal txt (cdr (assoc 302 (member (cons 304  "LEADER_LINE{") edata))))
	  (PROGN
	    (VLA-CLEAR ss)
	    (INITGET 1 "Yes No")
	    (SETQ n_txt_LBL (STRCAT "\n\t =>> " LBL " Label EXISTS! Add another " txt "? ")
		  y_n	    (GETKWORD (strcat n_txt_LBL " [Yes/No]: "))
	    )
	    (IF	(= y_n "Yes")
	      (PROGN (ppa-L-PLANTXT)
		     (VL-CMDF "cmleaderstyle" "LandscapeQua")
		     (INITGET 1)
		     (SETQ P1 (GETPOINT "\n\t =>> Specify leader start point: ")
			   P2 (GETPOINT P1 "\n\t =>> Specify next point: ")
		     )
		     (VL-CMDF "_.mleader" P1 P2 txt)
	      )
	    )
	  )
	)
	(setq itm (1+ itm))
      )
      (IF (> (sslength ss) 0)
	(PROGN (ppa-L-PLANTXT)
	       (VL-CMDF "cmleaderstyle" "LandscapeQua")
	       (INITGET 1)
	       (SETQ P1	(GETPOINT "\n\t =>> Specify leader start point: ")
		     P2	(GETPOINT P1 "\n\t =>> Specify next point: ")
	       )
	       (VL-CMDF "_.mleader" P1 P2 txt)
	)
      )
    )
    (PROGN (ppa-L-PLANTXT)
	   (VL-CMDF "cmleaderstyle" "LandscapeQua")
	   (INITGET 1)
	   (SETQ P1 (GETPOINT "\n\t =>> Specify leader start point: ")
		 P2 (GETPOINT P1 "\n\t =>> Specify next point: ")
	   )
	   (VL-CMDF "_.mleader" P1 P2 txt)
    )
  )
)

 Henrique

EESignature

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

Can't wrap my head on what your routine is supposed to do, But to "catch" a specific TAG

 

(defun c:Demo (/ _MLAttValue BlockColl ss i e f)
(vl-load-com)
;;;	pBe 22May2013			;;;
;;	Demo for Mtext Block Attribute  ;;;
(defun _MLAttValue (en et tag coll / n i attag)
  (setq n -1
        i (1- (vla-get-count et))
  )
  (while (and (null attag) (< n i))
    (if (And (eq "AcDbAttributeDefinition"
                 (vla-get-ObjectName (setq x (vla-item et (setq n (1+ n)))))
             )
             (eq tag (vla-get-TagString x))
        )
      (setq attag (vla-getBlockAttributeValue en (vla-get-ObjectID x)))
      
    )
  ) 
)  
  (setq BlockColl
         (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object)))
  )

  (if (setq ss (ssget "_:L" '((0 . "MULTILEADER"))))
    (repeat (setq i (sslength ss))
      (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
      (if (And
            (Eq (vla-get-ContentBlockName e) "_TagBox")
            (setq f (_mlattvalue
                      e
                      (vla-item BlockColl "_TagBox")
                      "TAGNUMBER"
                      BlockColl
                    )
            )
          )
        (princ (Strcat "\nDo your thing here with the value: \"" f "\""))
        (princ "\nTag not Found:")
      )
    )
  )(princ)
)

 HTH

Message 7 of 9
pbejse
in reply to: pbejse

oops...

 

(_mlattvalue (vla-item BlockColl "_TagBox") "TAGNUMBER"

BlockColl;<---- What the ?!!??? No need for this: a leftover from my original sub
)

should be like htis

(_mlattvalue (vla-item BlockColl "_TagBox") "TAGNUMBER")

 

And

(defun _MLAttValue (en et tag coll / n i attag)

to

(defun _MLAttValue (en et tag  / n i attag)

 

My bad Smiley Very Happy

 

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

Thank you. After a few small changes, it works perfectly.
Message 9 of 9
Hallex
in reply to: mid-awe

In addition there is my 2c

(defun C:MTF(/ *error* _getids en ids matchstr mleadobj sset)
  (vl-load-com)
  (defun *error* (s)
    ;(vl-bt)
    (setvar "nomutt" 0)
    (and s(princ s)))
  ;; local subfunction
  (defun _getIds (blockname / blk ids)
    (setq blk(vla-item (vla-get-blocks
			 (vla-get-activedocument(vlax-get-acad-object) ))
		       blockname))
  (vlax-for item blk
    (if (eq  "AcDbAttributeDefinition" (vla-get-objectname item))
	     (setq ids (cons  (vla-get-objectid item)ids))
	    ))
  (reverse ids))
  ;;main part
(if (not (tblsearch "block" "NOTES"))
    (progn

      (alert "Add before block named \"NOTES\" before")
      (exit) (princ)))

(princ "\nSelect mleaders")
(setvar "nomutt" 1) 
(if
 (and (setq matchstr "Office Plan\\PFloor 7");<-- string to search you may use getstring for input
(setq sset (ssget 
			  (list	(cons -4 "<and")
				(cons 0 "multileader")
				(cons -4 "<not")
				(cons -4 "<or")
				(cons 296 0)
				(cons 296 1)
				(cons -4 "or>" )
				(cons -4 "not>")
				(cons -4 "and>")  
				))))
 
 (while (setq en(ssname sset 0))
				     
	(setq mleadobj (vlax-ename->vla-object en))
	(if (eq  "NOTES"(vla-get-contentblockname  mleadobj))(progn  
              (setq ids (_getIds "NOTES"))
	      (foreach id ids
		(if (eq matchstr (vla-GetBlockAttributeValue mleadobj id))
		 ;; If the text is found then change the color of mleader
		(vla-put-color mleadobj 1)))))(ssdel en sset )))
  (*error* nil)
  (princ)
  )

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

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

Post to forums  

Autodesk Design & Make Report

”Boost