Populate and increment Attributes in a dynamic block based off of parameters

Populate and increment Attributes in a dynamic block based off of parameters

bull504
Enthusiast Enthusiast
926 Views
15 Replies
Message 1 of 16

Populate and increment Attributes in a dynamic block based off of parameters

bull504
Enthusiast
Enthusiast

Hello Forums, 

 

I am trying to put together a Lisp that will fill in and increment a dynamic block attribute. The problem I am running into is that these tags are based off of 3 other parameters (height, width, and type). What I want the Lisp to do is create a selection set, compare these 3 parameters, and fill in the tag attribute. If the 3 parameters of one block are equal to that of another in the selection, both of those blocks should have the same tag and it should increment. I just don't know how to translate this into code (I've gotten as far as a selection set) and am hoping someone can point me into the right direction. 

 

I've attached an example file showing a before/after of what I'm trying to do.

 

Thanks

0 Likes
Accepted solutions (2)
927 Views
15 Replies
Replies (15)
Message 2 of 16

pbejse
Mentor
Mentor

The order or "GL1"  for A, B and C is confusing, why is C the biggest size  then A then D and B?

A = 36x36

B = 24x36

C = 36x48

D = 24x48

 

Also what Width and Height? is it  "DLO HEIGHT" or  "GLASS HEIGHT"? 

 

0 Likes
Message 3 of 16

bull504
Enthusiast
Enthusiast
So normally I would fill out tags manually working left to right starting at the bottom, always starting with A, then incrementing a new tag whenever the size changes. Any block with the 3 parameters equal would have the same tag. The largest block (36x48 in this example) just so happens to fall on C, just how I typical read the elevation.

Glass height is what I'm working with, not DLO height. I should've clarified that.
0 Likes
Message 4 of 16

Sea-Haven
Mentor
Mentor

If you pull the 3 values from all the blocks and make a list can then do a find the common sizes, you then go back and label the blocks as A B etc its a little hard to explain but you compare the common size list to master list. Will try to find time. Need Lee-mac dynamic block.lsp for GET props. ((glasstype dlo-width dlo-height)......)

 

I use these functions by Gile

; Make a count of common items 
; By AlanH Aug 2021
(vl-load-com)
; By Gile
(defun my-count (a L)
  (cond
   ((null L) 0)
   ((equal a (car L)) (+ 1 (my-count a (cdr L))))
   (t (my-count a (cdr L))))
)

; By Gile
(defun remove_doubles (lst)
  (if lst
    (cons (car lst) (remove_doubles (vl-remove (car lst) lst)))
  )
)

 ps I have a draw window frames send me a PM if want more info.

 

 

0 Likes
Message 5 of 16

ВeekeeCZ
Consultant
Consultant

You should also clarify whether the type is given by GLASSTYPE att value or by Visibility state. Or... don't you want to fill up the type att too by the vis states?

0 Likes
Message 6 of 16

bull504
Enthusiast
Enthusiast

Type is given by GLASSTYPE attribute. Visibility is just for adding a hatch and/or leaders, and no, that attribute could be 1 type or 12 depending on the job, its never consistent and never follows a pattern. I'd rather keep that as a simple attribute.

0 Likes
Message 7 of 16

ВeekeeCZ
Consultant
Consultant

Possibly like this.

 

(vl-load-com)

(defun c:GlassTagging ( / LM:getdynpropvalue s i e o l u)
  
  (defun LM:getdynpropvalue ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
	     (vlax-invoke blk 'getdynamicblockproperties)))
  
  ; ------------------------------------------------------------------------------------------------
  
  (if (setq s (ssget '((0 . "INSERT") (2 . "Glass2.0,`*U*"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (setq o (vlax-ename->vla-object e))
      (if (= "Glass2.0" (vla-get-effectivename o))
	(setq l (cons (list (strcat (getpropertyvalue e "GLASSTYPE")
				    "-"
				    (vl-princ-to-string (LM:getdynpropvalue o "GLASS HEIGHT"))
				    "-"
				    (vl-princ-to-string  (LM:getdynpropvalue o "GLASS WIDTH")))
			    e
			    (getpropertyvalue e "Position/X")
			    (getpropertyvalue e "Position/Y"))
		      l)))))
  
  (setq l (vl-sort l '(lambda (e1 e2) (< (rtos (caddr e1) 2 0) (rtos (caddr e2) 2 0))))) ; by x
  (setq l (vl-sort l '(lambda (e1 e2) (< (rtos (last e1) 2 0) (rtos (last e2) 2 0)))))   ; by y
  
  (foreach e l
    (setpropertyvalue
      (cadr e)
      "GLASSMARK"
      (chr (+ 65 (cond ((vl-position (car e) u))
		       ((1- (length (setq u (append u (list (car e))))))))))))
  (princ)
  )
0 Likes
Message 8 of 16

ВeekeeCZ
Consultant
Consultant
Accepted solution

One more version - just thought I'll try it without Lee's "must have". 

 

(defun c:GlassTagging ( / s i e l u)
  
  (if (setq s (ssget '((0 . "INSERT") (2 . "Glass2.0,`*U*"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (if (= "Glass2.0" (getpropertyvalue e "BlockTableRecord/Name"))
	(setq l (cons (list (strcat (getpropertyvalue e "GLASSTYPE")
				    "-" (vl-princ-to-string (getpropertyvalue e "AcDbDynBlockPropertyGLASS HEIGHT"))
				    "-" (vl-princ-to-string (getpropertyvalue e "AcDbDynBlockPropertyGLASS WIDTH")))
			    e
			    (getpropertyvalue e "Position/X")
			    (getpropertyvalue e "Position/Y"))
		      l)))))
  
  (setq l (vl-sort l '(lambda (a b) (< (rtos (caddr a) 2 0) (rtos (caddr b) 2 0))))) ; by x
  (setq l (vl-sort l '(lambda (a b) (< (rtos (last a) 2 0) (rtos (last b) 2 0)))))   ; by y
  
  (foreach e l
    (setpropertyvalue (cadr e) "GLASSMARK" (chr (+ 65 (cond ((vl-position (car e) u))
							    ((1- (length (setq u (append u (list (car e))))))))))))
  (princ)
  )

 

Message 9 of 16

bull504
Enthusiast
Enthusiast

This is perfect! I was just trying out your previous post and it worked but the output was coming out a bit off. Even outputted an @ at first lol, but this is exactly what I was trying to do.

 

Thank you

0 Likes
Message 10 of 16

ВeekeeCZ
Consultant
Consultant

I know, it has been already fixed. 

The issue was in part that is the same in both routines. Both works now.

Sorry about that.

 

Message 11 of 16

bull504
Enthusiast
Enthusiast
1 last question, if I have more than 26 blocks, it starts labeling them as [,\,],~...etc.. Is there a way to get it to output AA,AB,AC,AD,...etc. after it reaches passed Z?
0 Likes
Message 12 of 16

Sea-Haven
Mentor
Mentor
getpropertyvalue

This does not work in Bricscad V20. Not sure V22. 

0 Likes
Message 13 of 16

Sea-Haven
Mentor
Mentor

If you google there is a few posts about Z now AA AB AC etc I think Kent did something.

0 Likes
Message 14 of 16

ВeekeeCZ
Consultant
Consultant
Accepted solution

@bull504 wrote:
1 last question, if I have more than 26 blocks, it starts labeling them as [,\,],~...etc.. Is there a way to get it to output AA,AB,AC,AD,...etc. after it reaches passed Z?

A-ZZ range acceptable.

 

(defun c:GlassTagging ( / s i e l u n)
  
  (if (setq s (ssget '((0 . "INSERT") (2 . "Glass2.0,`*U*"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (if (= "Glass2.0" (getpropertyvalue e "BlockTableRecord/Name"))
	(setq l (cons (list (strcat (getpropertyvalue e "GLASSTYPE")
				    "-" (vl-princ-to-string (getpropertyvalue e "AcDbDynBlockPropertyGLASS HEIGHT"))
				    "-" (vl-princ-to-string (getpropertyvalue e "AcDbDynBlockPropertyGLASS WIDTH")))
			    e
			    (getpropertyvalue e "Position/X")
			    (getpropertyvalue e "Position/Y"))
		      l)))))
  
  (setq l (vl-sort l '(lambda (e1 e2) (< (fix (caddr e1)) (fix (caddr e2)))))) ; by x
  (setq l (vl-sort l '(lambda (e1 e2) (< (fix (last e1)) (fix (last e2))))))   ; by y
  
  (foreach e l
    (setpropertyvalue (cadr e) "GLASSMARK" (strcat (cond ((not (setq n (cond ((vl-position (car e) u))
									     ((1- (length (setq u (append u (list (car e)))))))))))
							 ((= 0 (fix (/ n 26)))
							  "")
							 ((chr (+ 64 (fix (/ n 26))))))
						   (chr (+ 65 (rem n 26))))))
  (princ)
  )

 

Message 15 of 16

bull504
Enthusiast
Enthusiast
Excellent, thanks again
0 Likes
Message 16 of 16

Sea-Haven
Mentor
Mentor

Check your PM re curtain walls.

0 Likes