Extract block information from mutlileader

Extract block information from mutlileader

christian_paulsen98V29
Enthusiast Enthusiast
2,361 Views
37 Replies
Message 1 of 38

Extract block information from mutlileader

christian_paulsen98V29
Enthusiast
Enthusiast

So right now i have a lisp that takes all of my keynotes in my drawing, and inserts their information into my title block.

 

The only issue is that the keynote block and the Mleader have to be separate objects in order for this to work. Instead of making a multileader style with the block connected to the leader. This creates issues where sometimes people are moving the block without the leader, or moving the leader without the block. Or when you want to move them it now requires two steps instead of 1. So I'm trying to fix that issue by creating a Mleader style with the block connected, then extracting the information from there.

 

This chunk of code I'm posting is part of a much much larger lisp routine that connects with all kinds of other dlls and stuff. However I'm pretty sure this line right here is the root of the problem. Originally it only looked for block references but then i added the "or" condition to also look for Mleaders. The only issue is that im pretty sure its looking for the attributes of the Mleader, and not the attributes of the block connected to the Mleader.

 

(if (and (or (= (vlax-get-property G-OBJ "ObjectName") "AcDbBlockReference")
(= (vlax-get-property G-OBJ "ObjectName") "AcDbLeader"))

 

I know this is a tough one but any help would be greatly appreciated. I've got very limited knowledge and have been working on this for days.

 

;;;--------------------------------------------------------------------;
;;;  Subfunction: CPKS-GET-SYMBOLS                                    ;
;;;  Description: This function returns a sorted list of all keynote   ;
;;;               symbols in all spaces of current drawing including   ;
;;;               xrefs and binded blocks.                             ;
;;;--------------------------------------------------------------------;
(defun CPKS-GET-SYMBOLS (/           G-SS        G-SYM       G-TAG       G-STRLEN
                          G-STRVAL    G-OBJ       G-ATTR      G-I         G-LST-SYM
                          G-ARR-ATTR  G-OBJ-BLKS  G-XREFDB    G-XREFDB-MS G-NAME
                          G-LST-BADFAB            G-BADFAB    G-PART      G-SYM-PART
                         )
  ;; Process Symbols in current space ;
  (if (setq G-SS
             (ssget
               "x"
               (list
                 '(0 . "INSERT")
                 '(2
                   .
                   "*PNT,*MAT,*ALUM,*STEEL,*ELEC,*FAB,*HDWE,*FABTEXT,*CP_KNMAT,*CP_KNPNT,*CP_KNHDW,*CP_KNELC,*CP_KNALM,*CP_KNSTL,*CP_KNFAB,*CP_KNFAB2,*CP_KNFAB3,*CP_KNPAR,*CP_KNPAR2,*CP_KNPAR3,*CP_KNREV,*CP_FTAG,*CP_FABTAG,*CP_FABTAG-S,*CP_FABTAG-XS,*CP_FABTAG-L,*CP_FABTAG-XL,*CP_PARTAG,*CP_PARTAG-S,*CP_PARTAG-XS,*CP_PARTAG-L,*CP_PARTAG-XL"
                  )
               )
             )
      )
    (while (> (sslength G-SS) 0)
      (setq G-OBJ (vlax-ename->vla-object (ssname G-SS 0)))
      (if (and (or (= (vlax-get-property G-OBJ "ObjectName") "AcDbBlockReference")
               (= (vlax-get-property G-OBJ "ObjectName") "AcDbLeader"))
               (= (vlax-get-property G-OBJ "HasAttributes") :vlax-true)
               (setq
                 G-ARR-ATTR (vlax-safearray->list (vlax-variant-value (vla-getattributes G-OBJ)))
               )
          )
        (progn
          (foreach G-ATTR G-ARR-ATTR
            (setq G-TAG    (strcase (vlax-get-property G-ATTR "TagString"))
                  G-STRLEN (strlen (vlax-get-property G-ATTR "TextString"))
                  G-STRVAL (vlax-get-property G-ATTR "TextString")
                  G-SYM    NIL
            )
            (cond
              ((member G-TAG (list "FAB" "FABNUM")) (setq G-SYM (strcase G-STRVAL)))
              ((= G-TAG "FABNO")
               (setq G-SYM      (strcase G-STRVAL)
                     G-SYM-PART G-SYM
               )
              )
              ((= G-TAG "PART") (setq G-PART (strcase G-STRVAL)))
              ((member G-TAG (list "F" "KNF"))
               (setq G-SYM      (strcat "F-"
                                        (cond ((= G-STRLEN 3) (substr G-STRVAL 1))
                                              ((= G-STRLEN 2) (strcat "0" (substr G-STRVAL 1)))
                                              ((= G-STRLEN 1) (strcat "00" (substr G-STRVAL 1)))
                                              (t (substr G-STRVAL (- G-STRLEN 2)))
                                        )
                                )
                     G-SYM-PART G-SYM
               )
               (if (and (not (member G-STRLEN '(5 3))) (not (member G-STRVAL G-LST-BADFAB)))
                 (setq G-LST-BADFAB (append G-LST-BADFAB (list G-STRVAL)))
               )
              )
              ((member
                 G-TAG
                 (list "M" "P" "H" "E" "A" "S" "R" "PNT" "MAT" "ALUM" "STEEL" "ELEC" "HDWE")
               )
               (setq G-SYM (strcat (substr G-TAG 1 1) G-STRVAL))
              )
              ((member G-TAG (list "KNP" "KNM" "KNH" "KNE" "KNA" "KNS"))
               (setq G-SYM (strcat (substr G-TAG 3 1) G-STRVAL))
              )
            )
            (if (and G-SYM (not (member G-SYM G-LST-SYM)))
              (setq G-LST-SYM (append (list G-SYM) G-LST-SYM))
            )
          )
          (if (and G-PART G-SYM-PART (not (assoc G-SYM-PART G_LST-PARTS)))
            (setq G_LST-PARTS (append G_LST-PARTS (list (cons G-SYM-PART G-PART))))
          )
          (setq G-SYM-PART NIL
                G-PART NIL
          )
        )
      )
      (ssdel (ssname G-SS 0) G-SS)
    )
  )

 

0 Likes
Accepted solutions (2)
2,362 Views
37 Replies
Replies (37)
Message 2 of 38

komondormrex
Mentor
Mentor
Accepted solution

hth, for inserts and whole blocked mleaders

(defun CPKS-GET-SYMBOLS (/           G-SS        G-SYM       G-TAG       G-STRLEN
                          G-STRVAL    G-OBJ       G-ATTR      G-I         G-LST-SYM
                          G-ARR-ATTR  G-OBJ-BLKS  G-XREFDB    G-XREFDB-MS G-NAME
                          G-LST-BADFAB            G-BADFAB    G-PART      G-SYM-PART
                         )
  ;; Process Symbols in current space ;
  (if (setq G-SS
             (ssget
               "x"
               (list
		 '(-4 . "<or")
		 '(-4 . "<and")
		 '(0 . "INSERT")
                 '(2
                   .
                   "*PNT,*MAT,*ALUM,*STEEL,*ELEC,*FAB,*HDWE,*FABTEXT,*CP_KNMAT,*CP_KNPNT,*CP_KNHDW,*CP_KNELC,*CP_KNALM,*CP_KNSTL,*CP_KNFAB,*CP_KNFAB2,*CP_KNFAB3,*CP_KNPAR,*CP_KNPAR2,*CP_KNPAR3,*CP_KNREV,*CP_FTAG,*CP_FABTAG,*CP_FABTAG-S,*CP_FABTAG-XS,*CP_FABTAG-L,*CP_FABTAG-XL,*CP_PARTAG,*CP_PARTAG-S,*CP_PARTAG-XS,*CP_PARTAG-L,*CP_PARTAG-XL"
                  )
		 '(-4 . "and>")
		 '(0 . "MULTILEADER")
		 '(-4 . "or>")
               )
             )
      )
    (while (> (sslength G-SS) 0)
      (setq G-OBJ (vlax-ename->vla-object (ssname G-SS 0)))
      (if (or
		(and (= (vlax-get-property G-OBJ "ObjectName") "AcDbBlockReference")
		     (= (vlax-get-property G-OBJ "HasAttributes") :vlax-true)
		     (setq G-ARR-ATTR (vlax-safearray->list (vlax-variant-value (vla-getattributes G-OBJ))))
		)
		(and (= "AcDbMLeader" (vla-get-objectname G-OBJ))
		     (/= "" (setq ml_block_name (vla-get-contentblockName G-OBJ)))
		     (null (setq G-ARR-ATTR nil)) 
		     (vlax-map-collection (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) ml_block_name)
		       	'(lambda (object) (if (= (vla-get-objectname object) "AcDbAttributeDefinition") (setq G-ARR-ATTR (append G-ARR-ATTR (list object)))))
		     )
	        )
	  )
        (progn
          (foreach G-ATTR G-ARR-ATTR
	    (if (= (vlax-get-property G-OBJ "ObjectName") "AcDbBlockReference") 
	            (setq G-TAG    (strcase (vlax-get-property G-ATTR "TagString"))
	                  G-STRLEN (strlen (vlax-get-property G-ATTR "TextString"))
	                  G-STRVAL (vlax-get-property G-ATTR "TextString")
	                  G-SYM    NIL
	            )
	      	    (setq G-TAG    (strcase (vlax-get-property G-ATTR "TagString"))
	                  G-STRLEN (strlen (vla-getblockattributevalue G-OBJ (vla-get-objectid G-ATTR)))
	                  G-STRVAL (vla-getblockattributevalue G-OBJ (vla-get-objectid G-ATTR))
	                  G-SYM    NIL
	            )
      	    )
            (cond
              ((member G-TAG (list "FAB" "FABNUM")) (setq G-SYM (strcase G-STRVAL)))
              ((= G-TAG "FABNO")
               (setq G-SYM      (strcase G-STRVAL)
                     G-SYM-PART G-SYM
               )
              )
              ((= G-TAG "PART") (setq G-PART (strcase G-STRVAL)))
              ((member G-TAG (list "F" "KNF"))
               (setq G-SYM      (strcat "F-"
                                        (cond ((= G-STRLEN 3) (substr G-STRVAL 1))
                                              ((= G-STRLEN 2) (strcat "0" (substr G-STRVAL 1)))
                                              ((= G-STRLEN 1) (strcat "00" (substr G-STRVAL 1)))
                                              (t (substr G-STRVAL (- G-STRLEN 2)))
                                        )
                                )
                     G-SYM-PART G-SYM
               )
               (if (and (not (member G-STRLEN '(5 3))) (not (member G-STRVAL G-LST-BADFAB)))
                 (setq G-LST-BADFAB (append G-LST-BADFAB (list G-STRVAL)))
               )
              )
              ((member
                 G-TAG
                 (list "M" "P" "H" "E" "A" "S" "R" "PNT" "MAT" "ALUM" "STEEL" "ELEC" "HDWE")
               )
               (setq G-SYM (strcat (substr G-TAG 1 1) G-STRVAL))
              )
              ((member G-TAG (list "KNP" "KNM" "KNH" "KNE" "KNA" "KNS"))
               (setq G-SYM (strcat (substr G-TAG 3 1) G-STRVAL))
              )
            )
            (if (and G-SYM (not (member G-SYM G-LST-SYM)))
              (setq G-LST-SYM (append (list G-SYM) G-LST-SYM))
            )
          )
          (if (and G-PART G-SYM-PART (not (assoc G-SYM-PART G_LST-PARTS)))
            (setq G_LST-PARTS (append G_LST-PARTS (list (cons G-SYM-PART G-PART))))
          )
          (setq G-SYM-PART NIL
                G-PART NIL
          )
        )
      )
      (ssdel (ssname G-SS 0) G-SS)
    )
  )
 )

 

0 Likes
Message 3 of 38

christian_paulsen98V29
Enthusiast
Enthusiast

This 100% worked. Ive run into a new issue though. I need to make the lisp to where it only pulls the blocks and leaders for the current sheet(including xrefs on that sheet). Not for the entire dwg.

0 Likes
Message 4 of 38

ec-cad
Collaborator
Collaborator

Try adding: (cons 410 (getvar 'ctab))  to the ssget filter.

 

ECCAD

0 Likes
Message 5 of 38

ВeekeeCZ
Consultant
Consultant

@ec-cad wrote:

Try adding: (cons 410 (getvar 'ctab))  to the ssget filter.

 

ECCAD


 

0 Likes
Message 6 of 38

christian_paulsen98V29
Enthusiast
Enthusiast

Like this?

 

(setq G-SS
             (ssget (cons 410 (getvar 'ctab))
               "x"
               (list
		 '(-4 . "<or")
		 '(-4 . "<and")
		 '(0 . "INSERT")
                 '(2
                   .
                   "*PNT,*MAT,*ALUM,*STEEL,*ELEC,*FAB,*HDWE,*FABTEXT,*CP_KNMAT,*CP_KNPNT,*CP_KNHDW,*CP_KNELC,*CP_KNALM,*CP_KNSTL,*CP_KNFAB,*CP_KNFAB2,*CP_KNFAB3,*CP_KNPAR,*CP_KNPAR2,*CP_KNPAR3,*CP_KNREV,*CP_FTAG,*CP_FABTAG,*CP_FABTAG-S,*CP_FABTAG-XS,*CP_FABTAG-L,*CP_FABTAG-XL,*CP_PARTAG,*CP_PARTAG-S,*CP_PARTAG-XS,*CP_PARTAG-L,*CP_PARTAG-XL"
                  )
		 '(-4 . "and>")
		 '(0 . "MULTILEADER")
		 '(-4 . "or>")
               )
             )
      )
0 Likes
Message 7 of 38

ВeekeeCZ
Consultant
Consultant

No, within the (list... at <or or> level...

 

Learn more about it HERE 

 

 

(setq G-SS
       (ssget
	 "x"
	 (list
	   '(-4 . "<or")
	     '(-4 . "<and")
	       '(0 . "INSERT")
	       '(2 . "*PNT,*MAT,*ALUM,*STEEL,*ELEC,*FAB,*HDWE,*FABTEXT,*CP_KNMAT,*CP_KNPNT,*CP_KNHDW,*CP_KNELC,*CP_KNALM,*CP_KNSTL,*CP_KNFAB,*CP_KNFAB2,*CP_KNFAB3,*CP_KNPAR,*CP_KNPAR2,*CP_KNPAR3,*CP_KNREV,*CP_FTAG,*CP_FABTAG,*CP_FABTAG-S,*CP_FABTAG-XS,*CP_FABTAG-L,*CP_FABTAG-XL,*CP_PARTAG,*CP_PARTAG-S,*CP_PARTAG-XS,*CP_PARTAG-L,*CP_PARTAG-XL")
	     '(-4 . "and>")
	     '(0 . "MULTILEADER")
	   '(-4 . "or>")
	   (cons 410 (getvar 'ctab))
	   )
	 )
      )

 

Message 8 of 38

christian_paulsen98V29
Enthusiast
Enthusiast

tried it and it looks like its still pulling from the entire document, not just the current sheet.

0 Likes
Message 9 of 38

ec-cad
Collaborator
Collaborator

My bad, you are correct on that syntax.

Edited posting accordingly.

 

ECCAD

0 Likes
Message 10 of 38

ec-cad
Collaborator
Collaborator

 

Should be working for current 'tab', if you mean 'current sheet', that is part of a Sheet Set.. then

I don't know how to do those.

 

ECCAD

0 Likes
Message 11 of 38

christian_paulsen98V29
Enthusiast
Enthusiast

I mean the current paperspace layout that i am in when i run the command

0 Likes
Message 12 of 38

MrJSmith
Advocate
Advocate

@christian_paulsen98V29 May want to test it again. That filter will ONLY grab items from the currently viewed paperspace layout. 

0 Likes
Message 13 of 38

christian_paulsen98V29
Enthusiast
Enthusiast

Would xrefs mess with how it functions?

Pretty much every paperspace layout has nothing natively drawn onto it. It just has multiple xrefs to details from other dwg files. It then pulls the blocks from those xref files and uses that to populate the keynotes.

I can email file references if needed. However i cannot post the files to the forums since they are confidential.

0 Likes
Message 14 of 38

MrJSmith
Advocate
Advocate

@christian_paulsen98V29 Are the keynotes / multileaders placed in paper space on each layout?

0 Likes
Message 15 of 38

christian_paulsen98V29
Enthusiast
Enthusiast

No the keynotes / multileaders are in the xrefs. Which are then placed into the paperspace layouts. I hope that makes sense.

0 Likes
Message 16 of 38

ec-cad
Collaborator
Collaborator

Looks like you 'are' getting all the MLeaders

You will need to change these lines to include just those on 'ctab, not entire document.

 

 

(vlax-map-collection (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) ml_block_name)
		       	'(lambda (object) (if (= (vla-get-objectname object) "AcDbAttributeDefinition") (setq G-ARR-ATTR (append G-ARR-ATTR (list object)))))
		     )

 

 

I'll leave it to you to manage that one. Dinner is ready...

 

ECCAD

0 Likes
Message 17 of 38

christian_paulsen98V29
Enthusiast
Enthusiast

Im not getting all the mleaders. Im only pulling the specific blocks that are listed, or mleaders containing those specific blocks.

The issue is that its pulling all of those blocks from the entire drawing. Not just from that one layout.

0 Likes
Message 18 of 38

MrJSmith
Advocate
Advocate

If I understand you correctly, you have XREFs placed on layout tabs (in paper space). These XREFs contain keynotes and MLEADERS. You want to grab those keynotes and MLEADERS inside the XREF?

 

You can't do that with a simple SSGET function as that data resides in another drawing. I am surprised it is/has grabbed anything at all...

0 Likes
Message 19 of 38

komondormrex
Mentor
Mentor

is it correct that you have multileaders on various layouts which have blocks other than those filtered in the inserts section of the code?

0 Likes
Message 20 of 38

christian_paulsen98V29
Enthusiast
Enthusiast

No the only multileaders are the ones that are attached to the blocks referenced by the code. But those are not in paperspace layouts, they are in xrefs. I think the code is fuctioning properly as far as pulling all the referenced blocks, and multileaders with those referenced blocks. Its just pulling them from every page instead of just the current page.

0 Likes