Jump to content

Recommended Posts

Posted

Here is an example of an array that needs to be worked on and I need an easy way to count the number of rows and columns. For example, I have 3 rows and 20 columns and I need to be able to select for multiple arrays.

 

 

 

 

 image.thumb.png.64f2186b9bbcf8402f0712c8d428a7f9.png

Posted

For example, if 10 arrays with different row and column counts are used and I select all the arrays, I need to know the individual row and column count of all 10 arrays.

Posted (edited)
  (if (setq sel (ssget "_:L"))
    (progn
      (setq lst '())
      (repeat (setq inc (sslength sel))
        (setq ent (ssname sel (setq inc (1- inc))))
        (if
          (eq (getpropertyvalue ent "ClassName") "AcDbAssociativeRectangularArray")
          (progn
            (setq col (getpropertyvalue ent "Items")
                  rws (getpropertyvalue ent "RowsWithExpression")
                  tot (list (col rws))
                  lst (append tot lst)
            )
          )
        )
      )
      (princ lst)
    )
  )

 

Something like this?

 

Edited by mrharris78
Posted

Try this as a starting point, found it by Googling.

 

; big thanks to KGA for source code 
; Google will find code with error checking

(defun c:wow ( / enm elst x lst)
(setq enm (car (entsel "\nPick array ")))
(setq elst (entget enm))
(setq elst (cdr (member '(102 . "{ACAD_REACTORS") elst)))
(setq elst (entget (cdr (assoc 330 elst))))
(setq elst (entget (cdr (assoc 330 elst))))
(setq x 0 lst '())
(repeat (length elst)
  (if (= (cdr (nth (setq x (1+ x)) elst)) "Items")
   (setq lst (cons (cdr (nth (+ x 3) elst)) lst))
  )
  (if (= (cdr (nth (setq x (1+ x)) elst)) "Rows")
   (setq lst (cons (cdr (nth (+ x 3) elst)) lst))
  )
)
(alert (strcat (rtos (car lst) 2 0) " Columns " (rtos (cadr lst) 2 0) " Rows"))
(princ)
)

 

Posted

@BIGAL Thanks  but not work for this code  below the image shows up after the WOw comment 

image.png.e027e14c666295599b004ccde429a1d3.png

Posted

@mrharris78 Thanks, as per the code just show only the total count array number  

Posted (edited)
(defun c:arraycountdemo ( / doc hgt sel clx rwx spc inc ent col rws pnt ret  )

(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

(setq hgt 25) ;_*** Required Text Height ***

(prompt "\nSelect Rectangular Arrays: ")

(if (and hgt (setq sel (ssget "_:L")))
  (progn
    (setq clx '() rwx '())
    (setq spc (vlax-get doc (if (= 1 (getvar 'cvport)) 'paperSpace 'modelSpace)))
    (repeat (setq inc (sslength sel))
      (setq ent (ssname sel (setq inc (1- inc))))
      (if
	(eq (getpropertyvalue ent "ClassName")
	    "AcDbAssociativeRectangularArray"
	)
	 (progn
	   (setq col (getpropertyvalue ent "Items")
		 rws (getpropertyvalue ent "RowsWithExpression")
		 pnt (list (getpropertyvalue ent "Base/X")(getpropertyvalue ent "Base/Y")(getpropertyvalue ent "Base/Z"))
		 clx (append clx (list col))
		 rwx (append rwx (list rws))
	   )
	   (vla-AddText spc (strcat (itoa rws) " Rows & " (itoa col) " Columns") (vlax-3d-point pnt) hgt)
	 )
      )
    )
    (alert (setq ret (strcat "\nTotal Rows: "
			     (itoa (apply '+ rwx))
			     "\nTotal Columns: "
			     (itoa (apply '+ clx))
		     )
	   )
    )
  )
)

  (princ)

)

 

Edited by mrharris78
Posted

@mrharris78 Amazing code, but I need the results to look like the image 01 below. According to your code, the selection array should show up as image 02 below.

 

image 01

image.thumb.png.16c0bbca67c58f514fd471afea305c8a.png

Image 02

image.png.1d26a9148a5d2a2d6f4fa3336516ee32.png

Posted

Tamim, I have updated code above - not tested and no error checking.

  • Thanks 1
Posted

Mrharris, Thanks for your support now worked 

Posted

@mrharris78 FWIW you could narrow down your selection set with a filter like so:
 

(setq sel (ssget "_:L" '((0 . "INSERT") (2 . "`*U*"))))

 

Posted
10 hours ago, ronjonp said:

@mrharris78 FWIW you could narrow down your selection set with a filter like so:
 

(setq sel (ssget "_:L" '((0 . "INSERT") (2 . "`*U*"))))

 

Thank you @ronjonp very interesting! 👍

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...