When you start drawing, those rectangles with colors are already there, and you have to fill in those small, vertical rectangles.
example: row 30: the non-hatched region (between the two green regions) requires a ballast every 1200 length units; while the red region on row 29 requires a ballast every 600 units.
Right?
What do those colored rectangles look like? Are those blocks? Is this hatch filled in manually or is there some button (visibility parameter) to change the color of the hatch? Do they contain an attribute with the spacing value ? ... Anything like that?
When i start drawing I only have the roof layout. I have to put the panels on the roof layout (the panels are blocks), and then colour it to our engineering standards. The hatched colouring is a block, so are the panels (each colour, red, blue green yellow have their own block and own layer). The small rectangles are ballasts and those are blocks as well. Each ballast block will have its own spacing which is dependent on the zone it is it (both front and rear block have different spacing). ex. yellow zone could have 800mm rear 950mm front, blue 1125mm front 1875mm rear.
I think this is about what you need.
Can you arrange your blocks to have the items I'm reading?
Or what exactly do you have; what do your blocks look like?
It works for 1 row (at a time); I expect each row to be horizontal (same y-point); you can always rotate everything later.
; load extra recources(vl-load-com)(defun ballast ( / blocks x_values sorted_indexes block spacing x_pointer lft rgt width_panel y_value) (princ "\nSelect the solar panel blocks (cross select)") (setq i 0 spacing 0.0 x_pointer 0.0 ;; x_pointer is like the needle of a turn table. We set it to the x of the left panel block, then it only increases untill we get to the right panel x_values (list) blocks (ssget ":N" ;; client makes a cross select (list (cons 0 "INSERT") ) ) ) ;; we read the y-value of the first panel (setq y_value (nth 2 (assoc 10 (entget (ssname blocks 0))) )) ;; we make an array (list) containing the x-value of the insert point (repeat (sslength blocks) (setq x_values (append x_values (list (cadr (assoc 10 (entget (ssname blocks i)))) ;; returns the insert point, x-value ))) (setq i (+ i 1)) ) ;; we sort this last list, from left to right. sorted_indexes contains the index (to be used in the "nth" and "ssname" function ) (setq sorted_indexes (vl-sort-i x_values (function (lambda (e1 e2) (< e1 e2))) )) ;; we set x_pointer to the x-value of the left panel (setq x_pointer (nth (nth 0 sorted_indexes) x_values)) ;; calculate the width of the panel (setq width_panel (- (nth (nth 1 sorted_indexes) x_values) (nth (nth 0 sorted_indexes) x_values) )) ;; we loop over sorted_indexes. (setq i 0) (repeat (length sorted_indexes) (setq block (VLAX-ENAME->VLA-OBJECT (ssname blocks (nth i sorted_indexes)))) ;; set left and right point of the panel (setq lft (nth (nth i sorted_indexes) x_values) rgt (+ lft width_panel) ) ;; we look for the "SPACING" attribute (foreach Attribute (vlax-invoke Block "GetAttributes") (if (= (vla-get-TagString Attribute) "SPACING") (progn (setq spacing (atof (vla-get-TextString Attribute))) ;; (while (< x_pointer rgt) (progn (AT:InsertBlock "ballast" (list x_pointer y_value) 1.0 1.0 0.0) (setq x_pointer (+ x_pointer spacing)) ) ) (princ "\n") ) ) ) (setq i (+ i 1)) ));;; Insert block into drawing;;; #Name - name of block;;; #InsPt - insert point;;; #XScale - block X scale;;; #YScale - block Y scale;;; #Rot - block rotation;;; Alan J. Thompson, 04.21.09(defun AT:InsertBlock (#Name #InsPt #XScale #YScale #Rot) (if (or (tblsearch "block" #Name) (findfile #Name) ) ;_ or (vla-insertblock ((if (eq (getvar "cvport") 1) vla-get-paperspace vla-get-modelspace ) ;_ if (vla-get-ActiveDocument (vlax-get-acad-object) ) ;_ vla-get-ActiveDocument ) (vlax-3d-point #InsPt) #Name #XScale #YScale #XScale #Rot ) ;_ vla-insert-block ) ;_ if) ;_ defun;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(defun c:ballast ( / ) (ballast) (princ))
This is exactly what I was thinking of. Im glad it is possible. It works great in your test drawing which you have provided however in my drawings I am unable to make it work. Maybe i am using incorrect blocks, or attributes? I have attached a sample layout with blocks I would typically use.
I made a change to the block name in the routine and it worked just like it did in your test. That being said, there is still one issue. The panels have a row of ballast blocks in the rear and the front. Both of which have different spacings. Is there a way to have two sets of attributes per panel?