vernonlee Posted January 7, 2015 Share Posted January 7, 2015 In the drawing, there are door tags block with text attribute eg, 1-1, 1-2 ..... In excel, i have a column of door tags with text corresponding to the text in the drawing eg, 1-1 , 1-2...... In this excel i have highlighted or filter certain door tags eg, 2-55, 2-89 How best to highlight this corresponding doors in the drawing by way of lisp or scripts? I am open to try different methods. Thanks Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 7, 2015 Share Posted January 7, 2015 If you can upload a sample drawing including the target attributed block with the excel file , I would write a program for you in one go to save time . Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 8, 2015 Author Share Posted January 8, 2015 If you can upload a sample drawing including the target attributed block with the excel file , I would write a program for you in one go to save time . Thanks bro. Will do it during my lunch & post it as soon as i can. Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 8, 2015 Author Share Posted January 8, 2015 Attached is the drawing & excel file as requested. Thanks DOOR TAG.dwg DOOR TAG.xls Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 8, 2015 Share Posted January 8, 2015 Firstly save as your Excel file to csv format to be able to select it with the following program cause the other Excel formats are not supported with getfiled function . Secondly try the program and let me know (defun c:test (/ ss s f o ex x) ;; Tharwat 08.01.2014 ;; (cond ((not (setq ss (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 410 (getvar 'CTAB))) ) ) ) (alert "No Attributed Blocks found in drawing !!") ) ((and (setq f (getfiled "Select Excel file :" (getvar 'DWGPREFIX) "csv" 16 ) ) (setq o (open f "r")) ) (read-line o) (while (setq x (read-line o)) (setq l (cons (if (setq ex (vl-string-search ";" x ) ) (substr x 1 ex ) x ) l ) ) ) (close o) (setq s (ssadd)) (repeat (setq i (sslength ss)) (mapcar '(lambda (a) (if (member (vla-get-textstring a) l) (ssadd sn s) ) ) (vlax-invoke (vlax-ename->vla-object (setq sn (ssname ss (setq i (1- i)))) ) 'getattributes ) ) ) ) ) (sssetfirst nil s) (princ) ) Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 8, 2015 Author Share Posted January 8, 2015 Did as instructed. 1. Saved excel as CSV 2. Open the drawing. 3. Load test.lsp 3. Ran test (selected the CSV file) Command: (LOAD "D:/test.lsp") C:TEST Command: TEST Command: Command: '_.zoom _e Nothing happened though. Firstly save as your Excel file to csv format to be able to select it with the following program cause the other Excel formats are not supported with getfiled function . Secondly try the program and let me know (defun c:test (/ ss s f o ex x) ;; Tharwat 08.01.2014 ;; (cond ((not (setq ss (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 410 (getvar 'CTAB))) ) ) ) (alert "No Attributed Blocks found in drawing !!") ) ((and (setq f (getfiled "Select Excel file :" (getvar 'DWGPREFIX) "csv" 16 ) ) (setq o (open f "r")) ) (read-line o) (while (setq x (read-line o)) (setq l (cons (if (setq ex (vl-string-search ";" x ) ) (substr x 1 ex ) x ) l ) ) ) (close o) (setq s (ssadd)) (repeat (setq i (sslength ss)) (mapcar '(lambda (a) (if (member (vla-get-textstring a) l) (ssadd sn s) ) ) (vlax-invoke (vlax-ename->vla-object (setq sn (ssname ss (setq i (1- i)))) ) 'getattributes ) ) ) ) ) (sssetfirst nil s) (princ) ) Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 8, 2015 Author Share Posted January 8, 2015 (edited) I just realised when saved as CSV, all the colours are gone & the door text changed to date format. Edited January 8, 2015 by vernonlee Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 9, 2015 Author Share Posted January 9, 2015 Hi Tharwat As Pmed, i await your revised code. Thanks Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 10, 2015 Share Posted January 10, 2015 (edited) Hi Tharwat As Pmed, i await your revised code. Thanks Hi . Try the modified program that should work with txt file format and here I uploaded the txt file for your kind test (defun c:test (/ ss s f o ex x l i sn) ;; Tharwat 08.01.2014 ;; (cond ((not (setq ss (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 410 (getvar 'CTAB))) ) ) ) (alert "No Attributed Blocks found in drawing !!") ) ((and (setq f (getfiled "Select Excel file :" (getvar 'DWGPREFIX) "txt" 16 ) ) (setq o (open f "r")) ) (read-line o) (while (setq x (read-line o)) (setq l (cons x l ) ) ) (close o) (setq s (ssadd)) (repeat (setq i (sslength ss)) (mapcar '(lambda (a) (if (member (vla-get-textstring a) l) (ssadd sn s) ) ) (vlax-invoke (vlax-ename->vla-object (setq sn (ssname ss (setq i (1- i)))) ) 'getattributes ) ) ) ) ) (sssetfirst nil s) (princ) ) Door tags.txt Edited January 12, 2015 by Tharwat Variable localized Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 12, 2015 Author Share Posted January 12, 2015 Thanks Tharwat. I have tested it. Generally it select all the tags that is reflected in your uploaded TXT file. However, i notice that if i repeat the command with with a TXT file that contain a different set of tags, it will still select the tags base on the first TXT. I than close & reopen the drawing file and did the command but base on the 2nd TXT file, it did only select the specific tags. I then repeat the command base on your uploaded TXT file & it selected the tags as per your uploaded TXT file. Hope you could solve it. Hi . Try the modified program that should work with txt file format and here I uploaded the txt file for your kind test (defun c:test (/ ss s f o ex x) ;; Tharwat 08.01.2014 ;; (cond ((not (setq ss (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 410 (getvar 'CTAB))) ) ) ) (alert "No Attributed Blocks found in drawing !!") ) ((and (setq f (getfiled "Select Excel file :" (getvar 'DWGPREFIX) "txt" 16 ) ) (setq o (open f "r")) ) (read-line o) (while (setq x (read-line o)) (setq l (cons x l ) ) ) (close o) (setq s (ssadd)) (repeat (setq i (sslength ss)) (mapcar '(lambda (a) (if (member (vla-get-textstring a) l) (ssadd sn s) ) ) (vlax-invoke (vlax-ename->vla-object (setq sn (ssname ss (setq i (1- i)))) ) 'getattributes ) ) ) ) ) (sssetfirst nil s) (princ) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 12, 2015 Share Posted January 12, 2015 I am sorry , one variable is not localized which is the most important one . Replace this part or add the variable ( l ) as shown below . (defun c:test (/ ss s f o ex x [color=red][b]l[/b][/color] ) Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 12, 2015 Author Share Posted January 12, 2015 Thanks Tharwat. It now works correctly. Just wanted to clarify the following:- 1) which part of the lisp code do i include the 1st line for the TXT file? ( I could not figure it out looking at the code ) 2) Is there a limit to how many lines it will lookup to? Thanks I am sorry , one variable is not localized which is the most important one . Replace this part or add the variable ( l ) as shown below . (defun c:test (/ ss s f o ex x [color=red][b]l[/b][/color] ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 12, 2015 Share Posted January 12, 2015 Thanks Tharwat. It now works correctly. Just wanted to clarify the following:- 1) which part of the lisp code do i include the 1st line for the TXT file? ( I could not figure it out looking at the code ) 2) Is there a limit to how many lines it will lookup to? Thanks I modified the program and you can jump to it from HERE 2) Is there a limit to how many lines it will lookup to? No limitation , it is open . Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 13, 2015 Author Share Posted January 13, 2015 Hi Tharwat, The modified lisp still will not select tag from the first line of the TXT. I modified the program and you can jump to it from HERE No limitation , it is open . Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 13, 2015 Share Posted January 13, 2015 I tried the program with the txt file that I have attached earlier and it works as expected , but if you are using another drawing or another txt file , that is a thing that I can not judge on . Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 13, 2015 Author Share Posted January 13, 2015 Hi Tharwat. I used the same drawing. The TXT file is also the same as per what you uploaded. I just delete the first line "THIS IS THE DOOR TAG THAT TALLY WITH THE DRAWINGS" & "1-1" become the first line. but when i ran it, 1-1 on the drawing is not selected. I tried the program with the txt file that I have attached earlier and it works as expected , but if you are using another drawing or another txt file , that is a thing that I can not judge on . Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 13, 2015 Share Posted January 13, 2015 I just delete the first line "THIS IS THE DOOR TAG THAT TALLY WITH THE DRAWINGS" & "1-1" become the first line. but when i ran it, 1-1 on the drawing is not selected. If so , just delete the following part from the program . (read-line o) Quote Link to comment Share on other sites More sharing options...
vernonlee Posted January 13, 2015 Author Share Posted January 13, 2015 If so , just delete the following part from the program . (read-line o) Great. That did the trick. Thanks bro. 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.