Plant count using Multileaders

Plant count using Multileaders

brendon_butler
Enthusiast Enthusiast
443 Views
3 Replies
Message 1 of 4

Plant count using Multileaders

brendon_butler
Enthusiast
Enthusiast
Hi all,
I discovered this routine (below) that was created in 2017 for a very similar reason we need it for in our office.
However, it doesn't seem to work with our plant naming / numbering format, it seems.
I have attached a real example of a DWG containing various multileaders with various plant types and plant yield numbers that I would love for it to work as the author wrote it for the other person.
A Gif from the author is also attached showing the routine working for better clarity.

;;Ranjit Singh
;;7/10/17
(defun c:somefunc (/ colwid dat lst numcols numrows rowht) (setq lst (mapcar '(lambda (x) (cons (cdadr x) (cdar x))) (mapcar '(lambda (x) (cdr (vl-remove-if-not '(lambda (x) (= 302 (car x))) (entget x)))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "MULTILEADER")))))))) dat (acad_strlsort (unique (mapcar 'car lst))) numrows (+ 1 (length dat)) numcols 2 rowht (* 0.12 (getvar 'cannoscalevalue)) colwid 1) (tblfill (vla-addtable (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point (cdr (cons (initget 7) (getpoint "\nSelect Table Insertion point: ")))) (+ 1 numrows) numcols rowht colwid) (cons (cons "PLANT ID" dat) (list (cons "PLANT COUNT" (mapcar '(lambda (x) (count x lst)) dat))))) (princ)) (defun tblfill (tblobj data / ind tab) (setq tab -1) (mapcar '(lambda (x) (setq ind 1 tab (1+ tab)) (mapcar '(lambda (x) (vla-setcellvaluefromtext tblobj ind tab x 0) (setq ind (1+ ind))) x)) data)) (defun unique (x) (unique2 x ())) (defun unique2 (x y) (cond ((null x) y) (t (unique2 (vl-remove (car x) x) (cons (car x) y))))) (defun count (x y) (rtos (apply '+ (mapcar 'read (mapcar 'cdr (vl-remove-if-not '(lambda (z) (= x (car z))) y)))) 2 0))
0 Likes
Accepted solutions (1)
444 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant
Accepted solution

You need to adjust the size of it, it's pretty small.

 

 

(vl-load-com)

(defun c:PlantCount ( / tblfill s v p n l i)
  
  (defun tblfill  (tblobj data / ind tab) ;; by ;;Ranjit Singh
    (setq tab -1)
    (mapcar '(lambda (x) (setq ind 1
			       tab (1+ tab))
	       (mapcar '(lambda (x) (vla-setcellvaluefromtext tblobj ind tab x 0) (setq ind (1+ ind))) x))
	    data))
  
  (if (setq s (ssget '((0 . "MULTILEADER"))))
    (repeat (setq i (sslength s))
      (setq v (cdr (assoc 304 (entget (ssname s (setq i (1- i))))))
	    p (substr v (+ 2 (vl-string-search " " v)))
	    n (atoi v)
	    l (if (setq a (assoc p l))
		(subst (cons p (+ (cdr a) n)) a l)
		(cons (cons p n) l)))))
  (if (setq l (vl-sort l '(lambda (e1 e2) (< (car e1) (car e2)))))
    (tblfill (vla-addtable (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
	       (vlax-3d-point (cdr (cons (initget 7) (getpoint "\nSelect Table Insertion point: "))))
	       (+ (length l) 2)
	       2 
	       (getvar 'textsize) ; row hight
	       1)  ; col width
	     (list (cons "PLANT ID" (mapcar 'car l))
		   (cons "PLANT COUNT" (mapcar 'cdr l)))))
  (princ)
  )
0 Likes
Message 3 of 4

brendon_butler
Enthusiast
Enthusiast

That's brilliant. Thank you!
Is there a way to make the table larger and the cell size adjust to text size? Let's say a text size of 10.

0 Likes
Message 4 of 4

Sea-Haven
Mentor
Mentor

Simplest way is make a table style that is what you want then in the code you can set the table style. You should keep the table styles in a template dwt so is available for any project. Google make table style.

0 Likes