jr.roberto.santos Posted April 19, 2022 Share Posted April 19, 2022 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 Quote Link to comment Share on other sites More sharing options...
ronjonp Posted April 19, 2022 Share Posted April 19, 2022 (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 April 20, 2022 by ronjonp Quote Link to comment Share on other sites More sharing options...
jr.roberto.santos Posted April 19, 2022 Author Share Posted April 19, 2022 (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. EXCEPT.dwg Edited April 19, 2022 by jr.roberto.santos Quote Link to comment Share on other sites More sharing options...
ronjonp Posted April 20, 2022 Share Posted April 20, 2022 (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.. Edited April 20, 2022 by ronjonp 1 Quote Link to comment Share on other sites More sharing options...
jr.roberto.santos Posted April 20, 2022 Author Share Posted April 20, 2022 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. Quote Link to comment Share on other sites More sharing options...
jr.roberto.santos Posted April 20, 2022 Author Share Posted April 20, 2022 @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)) ) Quote Link to comment Share on other sites More sharing options...
jr.roberto.santos Posted April 21, 2022 Author Share Posted April 21, 2022 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) ) Select_duplicated_TAG1F.avi Select_Duplicate_attr.dwg Quote Link to comment Share on other sites More sharing options...
ronjonp Posted April 21, 2022 Share Posted April 21, 2022 (edited) @jr.roberto.santos Glad to see you figured out the DESC2 part! Edited April 21, 2022 by ronjonp Quote Link to comment Share on other sites More sharing options...
mhupp Posted April 21, 2022 Share Posted April 21, 2022 Prob should continue this in the other post. issue/request are almost the same and @ronjonp's lisp could be modified. @SLW210 Quote Link to comment Share on other sites More sharing options...
SLW210 Posted April 21, 2022 Share Posted April 21, 2022 Please use code tags. 1 Quote Link to comment Share on other sites More sharing options...
jr.roberto.santos Posted April 22, 2022 Author Share Posted April 22, 2022 @mhuppThanks for the feedback, I'm not sure if it's the same idea. I appreciate if you can help. Quote Link to comment Share on other sites More sharing options...
jr.roberto.santos Posted April 22, 2022 Author Share Posted April 22, 2022 (edited) @ronjonpCould you help me? Edited April 22, 2022 by jr.roberto.santos Quote Link to comment Share on other sites More sharing options...
SLW210 Posted April 22, 2022 Share Posted April 22, 2022 I merged your threads since they are pretty much the same. 1 Quote Link to comment Share on other sites More sharing options...
ronjonp Posted April 22, 2022 Share Posted April 22, 2022 (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? Edited April 22, 2022 by ronjonp Quote Link to comment Share on other sites More sharing options...
jr.roberto.santos Posted April 22, 2022 Author Share Posted April 22, 2022 (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 April 22, 2022 by jr.roberto.santos Quote Link to comment Share on other sites More sharing options...
ronjonp Posted April 22, 2022 Share Posted April 22, 2022 (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 April 22, 2022 by ronjonp Quote Link to comment Share on other sites More sharing options...
jr.roberto.santos Posted April 22, 2022 Author Share Posted April 22, 2022 @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. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted April 23, 2022 Share Posted April 23, 2022 (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 April 23, 2022 by ronjonp Quote Link to comment Share on other sites More sharing options...
jr.roberto.santos Posted April 23, 2022 Author Share Posted April 23, 2022 @ronjonpThank you very much for the support, you have already helped me a lot. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted April 24, 2022 Share Posted April 24, 2022 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.