Count and place circle to All Blocks by typing Attributes tag values

Count and place circle to All Blocks by typing Attributes tag values

nanja_c86
Enthusiast Enthusiast
1,196 Views
15 Replies
Message 1 of 16

Count and place circle to All Blocks by typing Attributes tag values

nanja_c86
Enthusiast
Enthusiast

Need to Count the number of blocks and place a circle to its insertion point and show alert message that this many circled placed.

the block name and Att tag will be same, but the att tag value will be different.

Need to place a circle for the block which has the att tag value which user inputs

especially i am looking to count and place circle if the tag value is blank.

Attached example dwg with blocks.

 

Block name: DA_AMPDATA

Tag name :  FWD_PAD

 

@Sea-Haven@DannyNL 

Please check and help me 

thank you in advance.

0 Likes
Accepted solutions (2)
1,197 Views
15 Replies
Replies (15)
Message 2 of 16

ВeekeeCZ
Consultant
Consultant

Thank you for not tagging me. 

0 Likes
Message 3 of 16

nanja_c86
Enthusiast
Enthusiast

@ВeekeeCZ 

i had asked a question on this Select All Blocks by typing Attributes tag post and their suggested me that create new post. So I created a new post and tagged who replied me there and who given solution to that post.

I know you had given some solutions earlier on my posts. Please check and give me the solution. 

Thank you.

0 Likes
Message 4 of 16

3wood
Advisor
Advisor
Accepted solution

You can try ALTEXT.

Enter 16 when it prompts 'Which attribute to be changed...'

Then use its Formula Example 16 in the website.

ALTEXT_FORMULA 16.gif

 

Message 5 of 16

nanja_c86
Enthusiast
Enthusiast
How do we get to know the tag number?
0 Likes
Message 6 of 16

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:

Thank you for not tagging me. 


Lol.png

0 Likes
Message 7 of 16

3wood
Advisor
Advisor

It's the sequence number in the Properties palette.

3wood_1-1656501028762.png

 

Message 8 of 16

Sea-Haven
Mentor
Mentor

I posted previously use nentsel pick attribute use its insertion point to then get block name so make a SSGET with correct filters will try to find. Pretty sure a (cons 330 was used.

0 Likes
Message 9 of 16

nanja_c86
Enthusiast
Enthusiast

@3wood wrote:

It's the sequence number in the Properties palette.

3wood_1-1656501028762.png

 


Thank you for the info.

0 Likes
Message 10 of 16

nanja_c86
Enthusiast
Enthusiast

@Sea-Haven wrote:

I posted previously use nentsel pick attribute use its insertion point to then get block name so make a SSGET with correct filters will try to find. Pretty sure a (cons 330 was used.


@Sea-Haven 

Can you please post the lisp for this?

 

0 Likes
Message 11 of 16

Sea-Haven
Mentor
Mentor

Here is one way

 

(setq ent (entget (car (nentsel "\nPick attribute"))))
(setq pt (cdr (assoc 10 ent))) ; insert point of attribute
(setq tagname (cdr (assoc 2 ent)))
(setq tagstr (cdr (assoc 1 ent)))

(setq ss (ssget pt (list (cons 0 "Insert"))))
(setq blkname (cdr (assoc 2 (entget (ssname ss 0)))))
0 Likes
Message 12 of 16

nanja_c86
Enthusiast
Enthusiast

 


@Sea-Haven wrote:

Here is one way

 

 

 

(setq ent (entget (car (nentsel "\nPick attribute"))))
(setq pt (cdr (assoc 10 ent))) ; insert point of attribute
(setq tagname (cdr (assoc 2 ent)))
(setq tagstr (cdr (assoc 1 ent)))

(setq ss (ssget pt (list (cons 0 "Insert"))))
(setq blkname (cdr (assoc 2 (entget (ssname ss 0)))))

 

 


@Sea-Haven 

I am not sure how o use this. 

 

Below lisp is doing the job for me.

This was written by @DannyNL on this post .

 except placing the circles and counting them and showing alert message.

Looking forward to someone to edit to my requirement.

 

(defun c:fpad_count (/ SB_FindAtt SB_FindVal SB_Selection SB_FoundSel SB_Count SB_BlkEnt)
;(setq SB_FindAtt (getstring "\nAttribute Tag : "))
(setq SB_FindAtt "FWD_PAD")
(setq SB_FindVal (getstring "\nAttribute Value: "))
(if
(setq SB_Selection (ssget "_X" '((0 . "INSERT") (2 . "DA_AMPDATA") (66 . 1))))
(progn
(setq SB_FoundSel (ssadd))
(setq SB_Count 0)
(repeat (sslength SB_Selection)
(setq SB_BlkEnt (ssname SB_Selection SB_Count))
(if
(FindAtt (vlax-ename->vla-object SB_BlkEnt) SB_FindAtt SB_FindVal)
(ssadd SB_BlkEnt SB_FoundSel)
)
(setq SB_Count (1+ SB_Count))
)
(if
(> (sslength SB_FoundSel) 0)
(sssetfirst nil SB_FoundSel)
)
)
)
(princ)
)

(defun FindAtt (FA_BlkObject FA_AttTag FA_AttVal / FA_Attributes FA_Return)
(if
(and
(= (type FA_BlkObject) 'VLA-OBJECT)
(= (vla-get-ObjectName FA_BlkObject) "AcDbBlockReference")
(= (vla-get-HasAttributes FA_BlkObject) :vlax-true)
(= (type FA_AttTag) 'STR)
(= (type FA_AttVal) 'STR)
)
(progn
(setq FA_Attributes (vlax-safearray->list (vlax-variant-value (vla-GetAttributes FA_BlkObject))))
(foreach FA_Item FA_Attributes
(if
(and
(= (strcase (vla-get-TagString FA_Item)) (strcase FA_AttTag))
(= (strcase (vla-get-TextString FA_Item)) (strcase FA_AttVal))
)
(setq FA_Return T)
)
)
)
)
FA_Return
)

 

 

Thank you.

0 Likes
Message 13 of 16

pbejse
Mentor
Mentor
Accepted solution
(Defun c:gqbe_dprou ( /  _TheBox aTag cDia aVal ss i eName aTagValue box ipt n)
(defun _TheBox (lst of)
	(list
		(list (- (caar lst) of) (- (cadar lst) of))
		(list (+ (caadr lst) of) (- (cadar lst) of))
		(list (+ (caadr lst) of) (+ (cadadr lst) of))
		(list (- (caar lst) of) (+ (cadadr lst) of))
	       )
  )
  
(setq aTag "FWD_PAD" cDia 10.00)
  
(if
  (and
    (setq aVal (getstring "\nAttribute Value: "))
    (setq ss  (ssget "X" '((0 . "INSERT") (2 . "DA_AMPDATA") (66 . 1))
		 )
	  )
    )
  (repeat (setq i (sslength ss))
    (setq eName (vlax-ename->vla-object (ssname ss (setq i (1- i))))
	  ipt (vlax-get eName "InsertionPoint"))
	    (and
	      (setq aTagValue (vl-some '(lambda (at)
				(if (and
				      (eq aTag (vla-get-tagstring at))
				      (eq (strcase aVal)(strcase (vla-get-textstring at))))
				  	(mapcar '(lambda (p)(Vlax-get at p))
				  		'("InsertionPoint" "StyleName"  "Height"))
				  		)
					)				
		   			(vlax-invoke eName 'GetAttributes)
				     )
		  )
	     	(setq box (textbox (mapcar 'cons '(1 7 40) (Cons (if (eq aVal "") "X" aVal) (cdr aTagValue)))))      
		(setq box
			(_TheBox
			  (list
			    (car aTagValue)
			    (mapcar '+ (car aTagValue) (mapcar '- (Cadr box) (Car box)))
			  )
			  1.0
			)
		      )      
		(entmakex (append (list (cons 0 "LWPOLYLINE")
	                          (cons 100 "AcDbEntity")
	                          (cons 100 "AcDbPolyline")
	                          (cons 90 (length box))
	                          (cons 70 1))
	                    (mapcar (function (lambda (p) (cons 10 p))) box)))
	      
		(entmakex (list (cons 0 "CIRCLE")
	                  (cons 10 ipt)
	                  (cons 40 cDia))
		  )
	      (setq n (if (null n) 1 (1+ n)))
	    )
	  )
  )
  (if n (alert (strcat (itoa n) " Circles placed")))
  (princ)
      )
Message 14 of 16

nanja_c86
Enthusiast
Enthusiast

@pbejse wrote:

 

 

 

 

@pbejse 

🤗THANKS for your routine, this is exactly I was looking for.

I added some for my requirement as below on entmakex function

(entmakex (append (list (cons 0 "LWPOLYLINE") ;to place rec to att ins point
(cons 8 "circles");layer
(cons 62 2);color
(cons 370 50);lineweight
(cons 100 "AcDbEntity")
(cons 100 "AcDbPolyline")
(cons 90 (length box))
(cons 70 1))
(mapcar (function (lambda (p) (cons 10 p))) box)))

(entmakex (list (cons 0 "CIRCLE");entity type
(cons 8 "circles");layer
(cons 62 2);color
(cons 370 50);lineweight
(cons 10 ipt);insertion point
(cons 40 cDia));diameter

 

 

Thanks,

Nanja

0 Likes
Message 15 of 16

Sea-Haven
Mentor
Mentor

pbe has provided an excellent answer in a more global sense maybe look at this.

 

(setq aTag "FWD_PAD" cDia 10.00)

(setq ent (entget (car (nentsel "\nPick attribute"))))
(setq pt (cdr (assoc 10 ent))) ; insert point of attribute
(setq atag (cdr (assoc 2 ent)) cDia 10.00)

(setq ss  (ssget "X" '((0 . "INSERT") (2 . "DA_AMPDATA") (66 . 1))

(setq ss (ssget pt (list (cons 0 "Insert"))))
(setq blkname (cdr (assoc 2 (entget (ssname ss 0)))))
(setq ss  (ssget "X" '((0 . "INSERT") (cons 2 blkname) (66 . 1))

 

 

Message 16 of 16

nanja_c86
Enthusiast
Enthusiast

@Sea-Haven wrote:

pbe has provided an excellent answer in a more global sense maybe look at this.

 

 

 

 

 

@Sea-Haven

Thanks for suggestion.

Your suggestion is also good.

But we cant use the nentsel to pick the attribute, if the attribute tag value is blank.

So user input is woks fine for me.

 

 

 

 


 

0 Likes