How to drill into Dynamic Array object to obtain entity data of source objects?

How to drill into Dynamic Array object to obtain entity data of source objects?

rapidcad
Collaborator Collaborator
891 Views
2 Replies
Message 1 of 3

How to drill into Dynamic Array object to obtain entity data of source objects?

rapidcad
Collaborator
Collaborator

Hi all. A little background:

I'm trying to access the contents of a dynamic array object that contains dynamic blocks. I have individual conveyor bed dynamic blocks that could be strung together in rectangular arrays. The source object could be manipulated through grips or property palette before arraying, or even after the array has been created through the ARRAYEDIT command. These options make it a nice idea to create dynamic arrays of these dynamic blocks so that they can be strung together and create long runs of these conveyor beds which are easily manipulated, and perfectly spaced.

 

My problem is that each of our dynamic blocks contain key properties that are extracted and then sent to a CSV file for Excel processing in order to create parts lists. My extraction lisp filters for our dynamic blocks since our effective names follow a key pattern and my SSGET grabs anonymous blocks with '*U* and filters for effective names as well - so we pick up only our dynamic blocks, whether they have been manipulated from their default state or not. Apparently, array objects created by using the ARRAYRECT  command with the ASSOCIATIVE option active create kind of a dynamic block on the fly that are also anonymous, so I'm trying to figure out how to test them and drill into them to collect all our dynamic blocks and mine their data.

 

Here's a code snippet:

(princ "\nSelect dynamic blocks for export ")
(setq SS (ssget (list (cons 0 "INSERT")(cons 2 (strcat "`*U*," "###_*," "TGWSP-*")))))
 (setq INC 0)
 (setq FINALSS (ssadd));creates an empty SS
(while (setq EN (ssname SS INC))
  (setq BLOCKNAME (vla-get-effectivename (vlax-ename->vla-object EN)))
   
   (setq LASTBLOCKCHR (substr BLOCKNAME  (strlen BLOCKNAME) 1));;finds version suffix
       (if (wcmatch  LASTBLOCKCHR "#");;if block is original beta non-indexed (ends in a number)
	 (setq ROOTBLOCKNAME BLOCKNAME );;set rootblockname=blockname to be caught
  	(setq ROOTBLOCKNAME (substr BLOCKNAME 1 (- (strlen BLOCKNAME) 1)));;if it is a later version block - set rootblockname to be caught w/o version letter
	 )
   (if (and (wcmatch (substr BLOCKNAME 1 4 ) "###_")(not (wcmatch  BLOCKNAME  "*EFWK*")) (not (vl-some '(lambda (s) (wcmatch ROOTBLOCKNAME s)) NAUGHTlist)))
  (progn (setq IC (substr BLOCKNAME 1 3 ))
    (ssadd EN FINALSS);add to the new SS, finalss
	(setq BLKDEF (vlax-ename->vla-object EN));check for, number and collect bogus mirrored block handles
	   	(setq  sclX (vlax-get BLKDEF 'XScaleFactor))
      		(setq  sclY (vlax-get BLKDEF 'YScaleFactor))
    		(if (or (minusp sclX) (minusp sclY)) ;find if either block scale factor is negative
	    		(progn
			  (Setq ALERTFLAG 1);set ALERTFLAG 1
			  (if (= MIRRLIST nil);if no list exists, create one, if it does, append it
			    (setq MIRRLIST (list (vla-get-handle blkdef))
				  COUNTVAR 1);if... do this
			    (setq MIRRLIST (append MIRRLIST(list (vla-get-handle BLKDEF)))
				    COUNTVAR (+ 1 COUNTVAR));else
			      )
			 )
		  )
		  )
    
   ) 
  (setq INC (1+ INC))
 )
...do processing of data on FINALSS.....

 

Any idea how to tell if dynamic array anonymous blocks are different from other dynamic blocks? 

ADN CAD Developer/Operator
0 Likes
892 Views
2 Replies
Replies (2)
Message 2 of 3

marko_ribar
Advisor
Advisor

Not sure, but if your dynamic blocks don't behave like dynamic array blocks - in my testing they differ in that that dynamic array blocks have (= (cdr (assoc 0 (entget (cdr (assoc 330 (entget dynamicarrayblock)))))) "ACDBASSOCDEPENDENCY")) while ordinary dynamic block have (= (cdr (assoc 0 (entget (cdr (assoc 330 (entget dynamicblock)))))) "BLOCK_RECORD")), and you don't have dynamic arrays nested into dynamic arrays and you don't have dynamic blocks nested into dynamic blocks but only dynamic arrays of dynamic blocks and those dynamic blocks fulfill your criteria posted in your snippet, then this should return some values after counting those blocks...

 

(defun c:TEST ( / NAUGHTlist SS INC K FINALSS EN BLOCKNAME LASTBLOCKCHR ROOTBLOCKNAME IC BLKDEF sclX sclY ALERTFLAG MIRRLIST COUNTVAR SSAR INCAR )

  (vl-load-com)

  (setq NAUGHTlist '("aaa" "bbb" "ccc"));; <--- change to suit your reqirements
  (princ "\nSelect dynamic blocks for export...")
  (setq SS (ssget (list (cons 0 "INSERT")(cons 2 (strcat "`*U*," "###_*," "TGWSP-*")))))
  (setq INC 0 K 0)
  (setq FINALSS (ssadd));creates an empty SS
  (while (setq EN (ssname SS INC))
    (if (/= (cdr (assoc 0 (entget (cdr (assoc 330 (entget EN)))))) "ACDBASSOCDEPENDENCY");;if dynamic block is not dynamic array
      (progn
        (setq BLOCKNAME (vla-get-effectivename (vlax-ename->vla-object EN)))
     
        (setq LASTBLOCKCHR (substr BLOCKNAME (strlen BLOCKNAME) 1));;finds version suffix
        (if (wcmatch  LASTBLOCKCHR "#");;if block is original beta non-indexed (ends in a number)
          (setq ROOTBLOCKNAME BLOCKNAME);;set rootblockname=blockname to be caught
          (setq ROOTBLOCKNAME (substr BLOCKNAME 1 (- (strlen BLOCKNAME) 1)));;if it is a later version block - set rootblockname to be caught w/o version letter
        )
        (if (and (wcmatch (substr BLOCKNAME 1 4) "###_") (not (wcmatch BLOCKNAME "*EFWK*")) (not (vl-some '(lambda ( s ) (wcmatch ROOTBLOCKNAME s)) NAUGHTlist)))
          (progn (setq IC (substr BLOCKNAME 1 3))
            (ssadd EN FINALSS);add to the new SS, finalss
            (setq BLKDEF (vlax-ename->vla-object EN));check for, number and collect bogus mirrored block handles
            (setq sclX (vlax-get BLKDEF 'XScaleFactor))
            (setq sclY (vlax-get BLKDEF 'YScaleFactor))
            (if (or (minusp sclX) (minusp sclY)) ;find if either block scale factor is negative
              (progn
                (setq ALERTFLAG 1);set ALERTFLAG 1
                (if (= MIRRLIST nil);if no list exists, create one, if it does, append it
                  (setq MIRRLIST (list (vla-get-handle BLKDEF))
                        COUNTVAR 1);if... do this
                  (setq MIRRLIST (append MIRRLIST (list (vla-get-handle BLKDEF)))
                        COUNTVAR (+ 1 COUNTVAR));else
                )
              )
            )
          )
        ) 
      )
      (progn
        (setq K (1+ K))
        (command "_.EXPLODE" EN)
        (while (< 0 (getvar 'cmdactive))
          (command "")
        )
        (setq SSAR (ssget "_P"))
        (setq INCAR 0)
        (while (setq EN (ssname SSAR INCAR))
          (if (/= (cdr (assoc 0 (entget (cdr (assoc 330 (entget EN)))))) "ACDBASSOCDEPENDENCY");;if dynamic block is not dynamic array
            (progn
              (setq BLOCKNAME (vla-get-effectivename (vlax-ename->vla-object EN)))
           
              (setq LASTBLOCKCHR (substr BLOCKNAME (strlen BLOCKNAME) 1));;finds version suffix
              (if (wcmatch  LASTBLOCKCHR "#");;if block is original beta non-indexed (ends in a number)
                (setq ROOTBLOCKNAME BLOCKNAME);;set rootblockname=blockname to be caught
                (setq ROOTBLOCKNAME (substr BLOCKNAME 1 (- (strlen BLOCKNAME) 1)));;if it is a later version block - set rootblockname to be caught w/o version letter
              )
              (if (and (wcmatch (substr BLOCKNAME 1 4) "###_") (not (wcmatch BLOCKNAME "*EFWK*")) (not (vl-some '(lambda ( s ) (wcmatch ROOTBLOCKNAME s)) NAUGHTlist)))
                (progn (setq IC (substr BLOCKNAME 1 3))
                  (ssadd EN FINALSS);add to the new SS, finalss
                  (setq BLKDEF (vlax-ename->vla-object EN));check for, number and collect bogus mirrored block handles
                  (setq sclX (vlax-get BLKDEF 'XScaleFactor))
                  (setq sclY (vlax-get BLKDEF 'YScaleFactor))
                  (if (or (minusp sclX) (minusp sclY)) ;find if either block scale factor is negative
                    (progn
                      (setq ALERTFLAG 1);set ALERTFLAG 1
                      (if (= MIRRLIST nil);if no list exists, create one, if it does, append it
                        (setq MIRRLIST (list (vla-get-handle BLKDEF))
                              COUNTVAR 1);if... do this
                        (setq MIRRLIST (append MIRRLIST (list (vla-get-handle BLKDEF)))
                              COUNTVAR (+ 1 COUNTVAR));else
                      )
                    )
                  )
                )
              ) 
            )
          )
          (setq INCAR (1+ INCAR))
        )
        (command "_.UNDO" "1")
      )
    )
    (setq INC (1+ INC))
    ;;;...do processing of data on FINALSS...;;;
  )
  (prompt "\nTotal dynamic blocks : ") (princ (sslength FINALSS))
  (prompt "\nTotal dynamic array blocks : ") (princ k)
  (princ)
)

BTW. Only way I found to dive into dynamic arrays is to temporarily EXPLODE them, collect data and do UNDO to return them back to previous state...

 

HTH, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 3

rapidcad
Collaborator
Collaborator

Thanks for the insight Marko. The situation is dynamic arrays of dynamic blocks (without nested dynamic blocks within the dynamic blocks).

 

I wondered about the datatype and your experience really helps. I will not have time to work on this today, but later in the week, I'll try to test with this code, and I'll use the vlide editor to examine the data structure to attempt to make this work. Who knows, maybe what you coded will work right out of the box - I'll try that first. Thanks for sharing your experience.

 

Ron

ADN CAD Developer/Operator
0 Likes