Jump to content

HELP:Advise on how to highlight text attribute in drawings base on text in excel file


vernonlee

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

I just realised when saved as CSV, all the colours are gone & the door text changed to date format. :(

Edited by vernonlee
Link to comment
Share on other sites

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 by Tharwat
Variable localized
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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] )

Link to comment
Share on other sites

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 :oops:)

 

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] )

Link to comment
Share on other sites

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 :oops:)

 

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 .

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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 .
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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