Jump to content

select duplicate attribute and create link with lines.


Recommended Posts

Posted

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-find-a-duplicate-attribute-value/td-p/10690981

 

I found this script very good. I'd like help changing it.

 

I use a block with the name HDV1_CONVERT:

Attrubutes: TAG1F, ASSYCODE, DESC2

 

I would like to find blocks with duplicate attributes (TAG1F), except for the block that has the ATTIBUTE (ASSYCODE) value "EXCEPT"

 

 

             

Duplicated_ATTRIBUTES.lsp

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • jr.roberto.santos

    11

  • ronjonp

    7

  • SLW210

    2

  • mhupp

    1

Posted (edited)

 

(defun c:fctag (/ _ipt a ssdup ss i ev attval a b fc_coll)
  (defun _ipt (e) (cdr (assoc 10 (entget e))))
  (if (setq ssdup (ssadd)
	    ss	  (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 410 (getvar 'ctab))))
      )
    (progn
      (repeat (setq i (sslength ss))
	(setq ev (ssname ss (setq i (1- i))))
	(setq attval (mapcar '(lambda (at) (list (vla-get-tagstring at) (vla-get-textstring at)))
			     (vlax-invoke (vlax-ename->vla-object ev) 'getattributes)
		     )
	)
	;; RJP - CHANGED TAGSTRING AND CHECK FOR 'EXCEPT' VALUE
	(if (and (setq f (assoc "TAG1F" attval))
		 (setq a (assoc "ASSYCODE" attval))
		 (/= "EXCEPT" (strcase (cadr a)))
	    )
	  (setq fc_coll (cons (list f ev) fc_coll))
	)
      )
      (while (or b (setq a (car fc_coll)))
	(if (setq b (vl-some '(lambda (c)
				(if (equal (car a) (car c))
				  c
				)
			      )
			     (cdr fc_coll)
		    )
	    )
	  (progn
	    (entmakex (list (cons 0 "LINE") (cons 10 (_ipt (cadr a))) (cons 11 (_ipt (cadr b)))))
	    (ssadd (cadr a) ssdup)
	    (ssadd (cadr b) ssdup)
	    (setq fc_coll (vl-remove b fc_coll)
		  b	  a
	    )
	  )
	  (setq fc_coll (cdr fc_coll))
	)
      )
      (sssetfirst nil ssdup)
    )
  )
  (princ)
)

 

Edited by ronjonp
Posted (edited)

Hi ronjonp,

 

Thanks for the quick reply.

So far I haven't found the expected result.

Follow the attached DWG file for best understanding.

 

image.png.d638cae19a39b08b8bcc81cada4bc1b4.png

 

EXCEPT.dwg

Edited by jr.roberto.santos
Posted (edited)

@jr.roberto.santos

All those blocks 'ASSYCODE' values are EXCLUDE not EXCEPT .. that's why it does not work. I updated the code above so try again .. if you change that one block's attribute to 'EXCEPT' it works..

image.png.81fb29ca44251375ca3472282add3c87.png

2022-04-20_07-08-34.thumb.gif.b21031f44bbacd629485d2d709104724.gif

Edited by ronjonp
  • Agree 1
Posted

ronjonp,


Thank you very much for your attention, I'm probably making some mistake.  

I'll try again.  

A question, is it possible to add one more argument?  EX.  if the Attribute “DESC2” is blank (“”) do not match.

Posted

@ronjonp

Thank you very much

 

I ran the tests and it worked very well. I really appreciate the support.

 

 

;; RJP - CHANGED TAGSTRING AND CHECK FOR 'EXCLUDE' VALUE
    (if (and (setq f (assoc "TAG1F" attval))
         (setq a (assoc "ASSYCODE" attval))
         (/= "EXCLUDE" (strcase (cadr a)))
         
         
         (setq a (assoc "DESC2" attval))
         (/= "" (strcase (cadr a)))
        )
      (setq fc_coll (cons (list f ev) fc_coll))
    )

 

Posted

Reference for STEP_1:  https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/selecting-a-block-by-its-attribute-value/td-p/2195298

Reference for STEP_2  https://www.theswamp.org/index.php?topic=12813.135

 

Hello everyone,

 

I'm using this script to select duplicate attribute values.

It works great for the "TAG1F" attribute.

I would like to do the same procedure for other attribute.

For example:

 

Select duplicate values in the "DESC2" attribute and ignore the blank values ("") 

 

Best regards

 

;$$$$$$$$$$$$$$$$$$$$$$$
;STEP_1

(defun c:SEL_worklineX (/ att elst TAG_NAME val ss1 ss2 n ent)
(and
(setq att (car (nentsel "\nSelect source attribute: ")))
(setq elst (entget att))
(setq TAG_NAME (cdr (assoc 2 elst))
val (cdr (assoc 1 elst))
ss2 (ssadd)
)
(setq ss1 (ssget "_X"
(list '(0 . "INSERT")
(assoc 2 (entget (cdr (assoc 330 elst))))
)
)
)
(repeat (setq n (sslength ss1))
(setq ent (ssname ss1 (setq n (1- n)))
att (entnext ent)
)
(while (= (cdr (assoc 0 (setq elst (entget att)))) "ATTRIB")
(if (and (= (cdr (assoc 2 elst)) TAG_NAME)
(= (cdr (assoc 1 elst)) val)
)
(ssadd ent ss2)
)
(setq att (entnext att))
)
)
(sssetfirst nil ss2)
)

(vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "worklineX_Y5P9_STEP_2\r")

(princ)
)

;$$$$$$$$$$$$$$$$$$$$$$$
;STEP_2

(defun c:worklineX_Y5P9_STEP_2 (/ CreateList _grAngle adoc Plines obj cnt ent ObjectPointList
           PtAngleList Xpoint gr NewLine
           )
           
        (if (not (tblsearch "layer" "WorklineX_Layer")) (command "-LAYER" "_N" "WorklineX_Layer"""))
        (vl-cmdf "._Layer" "Color" 3 "WorklineX_Layer" "")
        (command "-LAYER" "set" "WorklineX_Layer""")
        (command "LAYLOCKFADECTL""0")
        
;$$$$$$$$$$$$$$$$$$$$$$$    
           
;;;    pBe April 2011        ;;;
  (vl-load-com)
  (defun CreateList (p) (setq ObjectPointList (cons (cdr p) ObjectPointList)))
;;;        Alanjt        ;;;
  (defun _grAngle (a b) (grdraw (trans a 0 1) (cadr gr) 1 -1) (angle a b))
;;;                  ;;;
  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
   (if (setq Plines (ssget "_P" (list '(0 . "INSERT") '(66 . 1) (cons 2 "HDV1_CONVERT"))))
   
    (progn
      (repeat (setq cnt (sslength Plines))
        (setq obj (ssname Plines (setq cnt (1- cnt)))
              ent (entget obj))
        (mapcar
          'CreateList
          (vl-remove-if-not '(lambda (x) (= (car x) 10)) ent)
          )
        (ssdel obj Plines)
        )
      (if ObjectPointList
        (progn
;;;        Alanjt        ;;;
          (while (eq 5 (car (setq gr (grread T 15 0))))
            (setq Xpoint (trans (cadr gr) 1 0))
            (redraw)
            (foreach pts ObjectPointList (_grAngle pts Xpoint))
            )
;;;                          ;;;
          (redraw)
          (foreach
             itm ObjectPointList
            (setq
              NewLine
               (vla-addline
                 (vlax-get (vla-get-activelayout adoc) 'Block)
                 (vlax-3d-point Xpoint)
                 (vlax-3d-point itm)
                 )
              )
            )
          )
        )
      )
    )
    
    (vl-cmdf "._Layer" "Ltype" "HIDDEN" "WorklineX_Layer" "")
    (vl-cmdf "_.-layer" "_lw" "0.30" "WorklineX_Layer" "")
    (setq selL (ssget "_X" '((8 . "WorklineX_Layer"))))
    (command "_.draworder" selL "" "_Back")
    (command "._setbylayer" (ssget "X" '((8 . "WorklineX_Layer"))) "" "YES" "YES")
            
  (princ)
  )

 

 

 

 

image.png.d7379e0daf04dc96ed6f9e236263a7e4.png

 

 

Select_Duplicate_attr.dwg

Posted

Prob should continue this in the other post. issue/request are almost the same and @ronjonp's lisp could be modified.

 

@SLW210

  • jr.roberto.santos changed the title to select duplicate attribute and create link with lines.
Posted

@mhuppThanks for the feedback, I'm not sure if it's the same idea.  I appreciate if you can help.

 

Posted (edited)

@ronjonpCould you help me?

 

Edited by jr.roberto.santos
Posted

I merged your threads since they are pretty much the same.

  • Like 1
Posted (edited)
20 hours ago, jr.roberto.santos said:

@ronjonpCould you help me?

 

I'm not sure I follow what you want. Your example image and the drawing don't match for 'duplicate' DESC2 values in TAG_D.

 

 

Also ... why are you using completely different code?

 

image.png

Edited by ronjonp
Posted (edited)

@ronjonpThe code is different, I had created a new topic to avoid confusion.  in this case I can select duplicate tags (TAG1F) and I would like to change the code to select duplicate values in the attribute (DESC2) /= “” except blank values.

Edited by jr.roberto.santos
Posted (edited)
17 minutes ago, jr.roberto.santos said:

@ronjonpThe code is different, I had created a new topic to avoid confusion.  in this case I can select duplicate tags (TAG1F) and I would like to change the code to select duplicate values in the attribute (DESC2) /= “” except blank values.

Just change the logic in this portion of the code you and I modified.

(and (setq f (assoc "DESC2" attval)) (/= "" (cadr f)))

 

Edited by ronjonp
Posted

@ronjonpThanks for the reply, I got this result, but as the attached video the idea is a selection by duplicate groups. one group per click. 

Posted (edited)
4 hours ago, jr.roberto.santos said:

@ronjonpThanks for the reply, I got this result, but as the attached video the idea is a selection by duplicate groups. one group per click. 

Sorry, you're going to have to figure this out for yourself.

Edited by ronjonp
Posted

@ronjonpThank you very much for the support, you have already helped me a lot.

Posted
On 4/23/2022 at 12:26 AM, jr.roberto.santos said:

@ronjonpThank you very much for the support, you have already helped me a lot.

🍻

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...