Nikon Posted August 31 Posted August 31 (edited) I need to select blocks with the same names but with different attributes /tag: cell_4 F3/ (the name of the drawing) and get a list of only these attributes without a tag. for example: Name of the drawing1 Name of the drawing2 Name of the drawing3 ;; Lee Mac / February 21, 2010 (defun c:BlockOut (/ *error* lst2str FILE IATT IBLK INFO OFILE SS) (vl-load-com) (defun *error* (msg) (and ofile (close ofile)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (defun lst2str (lst del) (if (cdr lst) (strcat (car lst) del (lst2str (cdr lst) del)) (car lst))) (if (and (ssget '((0 . "INSERT"))) (setq file (getfiled "Output File" "" "csv" 1))) (progn (vlax-for obj (setq ss (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object)))) (setq iBlk (list (if (vlax-property-available-p obj 'EffectiveName) (vla-get-EffectiveName obj) (vla-get-Name obj)) (vla-get-Handle obj))) (if (eq :vlax-true (vla-get-HasAttributes obj)) (foreach att (vlax-invoke obj 'GetAttributes) (setq iAtt (cons (list (vla-get-TagString att) (vla-get-Handle att) (vla-get-TextString att)) iAtt)))) (setq Info (cons (cons iBlk iAtt) Info) iBlk nil iAtt nil)) (vla-delete ss) (setq ofile (open file "w")) (foreach b Info (write-line (lst2str (car b) ",") ofile) (foreach a (cdr b) (write-line (lst2str a ",") ofile)) (write-line "" ofile)) (setq ofile (close ofile)))) (princ)) Format_F.dwg Edited September 10 by Nikon Quote
BIGAL Posted August 31 Posted August 31 (edited) Look into fields in an attribute, you can have dwg name as a field. So just set up your Title blocks correctly, I would put them in a separate layout for each one. Save in a dwt then ready to go for every project. %<\AcVar Filename \f "%fn2">% Edited August 31 by BIGAL 1 Quote
Nikon Posted September 1 Author Posted September 1 7 hours ago, BIGAL said: Look into fields in an attribute, you can have dwg name as a field. So just set up your Title blocks correctly, I would put them in a separate layout for each one. Save in a dwt then ready to go for every project. Mr. BIGAL, thanks for your reply, but I don't understand how the file .dwt to extract attributes will help me. I work in the Model Space, then I use lisp to create Layouts, then I need to extract the attributes with the name of the drawing. It's a bit long by standard methods, you need to make settings, uncheck unnecessary objects... I would like to use lisp for this. Lisp Lee is well suited for this task, but I just don't need all the attributes and tags, but only one attribute without a tag. Maybe I'm asking for something very difficult?.. Quote
BIGAL Posted September 1 Posted September 1 I guess I approach the task in a different way I make rectangs that are the MView area at desired scale, matching a title block. Then make layouts to suit using Layout copy, so there is one layout to start with that has the title block in paperspace in the layout. This includes making rectangs on an angle. Something like this. (foreach att (vlax-invoke obj 'GetAttributes) (if (= (vlax-get att 'tagstring) "cell_4F3") (write-line (vlax-get att 'textstring) ofile) ) ) 1 Quote
Nikon Posted September 2 Author Posted September 2 7 hours ago, BIGAL said: I guess I approach the task in a different way I make rectangs that are the MView area at desired scale, matching a title block. Then make layouts to suit using Layout copy, so there is one layout to start with that has the title block in paperspace in the layout. This includes making rectangs on an angle. Something like this. (foreach att (vlax-invoke obj 'GetAttributes) (if (= (vlax-get att 'tagstring) "cell_4F3") (write-line (vlax-get att 'textstring) ofile) ) ) Mr. BIGAL, thanks, I have no problem creating layouts. I have 30-50 sheets with frames in the form of dynamic blocks (block name: format_F) with attributes. I want to select the blocks in the drawing and get the names of the sheets (tag: cell_4F3) to a .csv file or .txt or .doc. I do not know if this part of the code is suitable for my task... Quote
BIGAL Posted September 2 Posted September 2 Ok I understand what your trying to do, I was getting confused by you using the words drawing 1, when you mean "layout 1". So a dwg will be 30+ etc layouts each with 1 title block, the name of the title block will be one of the 3 in the dwg format_f. Watch this space may get a chance later today. Here is a freebie for you makes a drawing index based on 2 attributes. You will need to change to suit your dwg. Yes tested on 88 layouts. (setq bname "DA1DRTXT") ; title block name (setq tag2 "DRG_NO") ;attribute tag name (setq tag3 "WORKS_DESCRIPTION") ;attribute tag name Dwgindex.lsp 1 Quote
Nikon Posted September 3 Author Posted September 3 (edited) 12 hours ago, BIGAL said: Ok I understand what your trying to do, I was getting confused by you using the words drawing 1, when you mean "layout 1". Mr. BIGAL, Thank you for your participation. Sorry for my English... I don't mean the layout. Let's assume that there are no layouts. I'm in the model space. I use lisp Lee Mac "BlockOut" and I get the file Microsoft Office Excel (.csv) with tags and attributes. BUT I only want to get the attributes: Name of the drawing1 Name of the drawing2 Name of the drawing3 Edited September 3 by Nikon Quote
BIGAL Posted September 4 Posted September 4 Hopefully this is what you want. (defun c:test ( / lst obj atts att file ofile) (setq file (getfiled "Output File" "" "csv" 1)) (setq ofile (open file "w")) (setq ss (ssget '((0 . "INSERT")))) (repeat (setq x (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1))))) (setq atts (vlax-invoke obj 'Getattributes)) (foreach att atts (if (= (vlax-get att 'tagstring) "CELL_4F3") (write-line (vlax-get att 'textstring) ofile) ) ) ) (close ofile) (princ) ) (c:test) 1 Quote
Nikon Posted September 4 Author Posted September 4 (edited) 6 hours ago, BIGAL said: (defun c:test ( / lst obj atts att file ofile) (setq file (getfiled "Output File" "" "csv" 1)) (setq ofile (open file "w")) (setq ss (ssget '((0 . "INSERT")))) (repeat (setq x (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1))))) (setq atts (vlax-invoke obj 'Getattributes)) (foreach att atts (if (= (vlax-get att 'tagstring) "CELL_4F3") (write-line (vlax-get att 'textstring) ofile) ) ) ) (close ofile) (princ) ) (c:test) Mr. @BIGAL This is what I need!!! Thanks a lot!!! If it's not too difficult, is it possible to add changes to the code so that the attribute values are displayed in order from top to bottom? Edited September 4 by Nikon Quote
Nikon Posted September 6 Author Posted September 6 (edited) On 9/4/2024 at 3:06 AM, BIGAL said: (defun c:test ( / lst obj atts att file ofile) (setq file (getfiled "Output File" "" "csv" 1)) (setq ofile (open file "w")) (setq ss (ssget '((0 . "INSERT")))) (repeat (setq x (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1))))) (setq atts (vlax-invoke obj 'Getattributes)) (foreach att atts (if (= (vlax-get att 'tagstring) "CELL_4F3") (write-line (vlax-get att 'textstring) ofile) ) ) ) (close ofile) (princ) ) (c:test) Is it possible to add a second attribute CELL_7F3 (sheet number) to this code, since the attributes are not displayed in the order of the sheets, so that the rows can be easily moved in Excel later... Or will the attributes be arranged in Excel in order from top to bottom? Or Edited September 6 by Nikon Quote
marko_ribar Posted September 6 Posted September 6 Maybe just this - (acad_strlsort) : (defun c:test ( / lst obj atts att file ofile) (setq file (getfiled "Output File" "" "csv" 1)) (setq ofile (open file "w")) (setq ss (ssget '((0 . "INSERT")))) (repeat (setq x (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1))))) (setq atts (vlax-invoke obj 'Getattributes)) (foreach att atts (if (= (vlax-get att 'tagstring) "CELL_4F3") (setq lst (cons (vlax-get att 'textstring) lst)) ) ) ) (foreach x (acad_strlsort lst) (write-line x ofile) ) (close ofile) (princ) ) (c:test) 1 Quote
Nikon Posted September 6 Author Posted September 6 (edited) Mr. @marko_ribar Thank you very much!::! Now the attributes are arranged in order!::! Edited September 6 by Nikon Quote
Nikon Posted September 7 Author Posted September 7 (edited) 11 hours ago, marko_ribar said: (defun c:test ( / lst obj atts att file ofile) (setq file (getfiled "Output File" "" "csv" 1)) (setq ofile (open file "w")) (setq ss (ssget '((0 . "INSERT")))) (repeat (setq x (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1))))) (setq atts (vlax-invoke obj 'Getattributes)) (foreach att atts (if (= (vlax-get att 'tagstring) "CELL_4F3") (setq lst (cons (vlax-get att 'textstring) lst)) ) ) ) (foreach x (acad_strlsort lst) (write-line x ofile) ) (close ofile) (princ) ) (c:test) This code works (attributes are saved in Excel in order), only if there are numbers 1, 2, 3 in the name of the drawing... The numbers 1, 2, 3, 4 in the name of the drawing have been added for ease of testing. This is not the case in real projects. And the attributes are saved in Excel in random order... I want to highlight the blocks from top to bottom on the Y axis and get the attributes in that order. Is it possible to do this? Thanks! format_F1.dwg Edited September 7 by Nikon Quote
BIGAL Posted September 7 Posted September 7 Try this (defun c:test ( / obj atts att file ofile) (defun BubbleSort (lstItems / blnFlag item1 item2 lstItems2) (setq item1 (car lstItems)) (foreach item2 (cdr lstItems) (if (<= item1 item2) (setq lstItems2 (cons item1 lstItems2) item1 item2 ) (setq lstItems2 (cons item2 lstItems2) blnFlag T ) ) ) (if blnFlag (BubbleSort (reverse (cons item1 lstItems2))) (reverse (cons item1 lstItems2)) ) ) (setq file (getfiled "Output File" "" "csv" 1)) (setq ofile (open file "w")) (setq ss (ssget '((0 . "INSERT")))) (setq lst '()) (repeat (setq x (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1))))) (setq atts (vlax-invoke obj 'Getattributes)) (foreach att atts (if (= (vlax-get att 'tagstring) "CELL_4F3") (setq lst (cons (vlax-get att 'textstring) lst)) ) ) ) (setq lst (BubbleSort lst)) (foreach val lst (write-line val ofile) ) (close ofile) (princ) ) (c:test) 1 Quote
Nikon Posted September 8 Author Posted September 8 (edited) Mr. @BIGAL thank you, unfortunately the attributes are arranged in a random order. in Excel Name of the drawing1 Name of the drawing2 Name of the drawing3 Name of the drawing4 And in the drawing they are arranged like this (from top to bottom): Name of the drawing3 Name of the drawing2 Name of the drawing4 Name of the drawing1 in Excel The first drawing The fourth drawing The second drawing The third drawing And in the drawing they are arranged like this (from top to bottom): The first drawing The second drawing The third drawing The fourth drawing In the real project, the attributes are again arranged in random order... Perhaps it would be easier to add a second attribute CELL_7F3 (sheet number) and arrange the attributes (CELL_4 F3 and CELL_7F3) in order by these numbers? Edited September 8 by Nikon Quote
BIGAL Posted September 9 Posted September 9 (edited) The easiest answer is to use layouts then you process in layout order. As part of making layouts you draw a rectang at desired scale around objects then layouts are made automatically based on the rectang. Each layout has the title block at 1:1 scale ie true size like A2 but the mview reflects the objects at desired scale. Remove the line (setq lst (BubbleSort lst)) from the code. when asked to select titles pick them one at a time in the order you want and it should work. The issue with do in view order is what about using horizontal titles, a grid of titles, random placement of titles. Yes adding a extra attribute is one way around the problem. But for me use layouts. You will not look back. Edited September 9 by BIGAL 1 Quote
Nikon Posted September 9 Author Posted September 9 6 hours ago, BIGAL said: The easiest answer is to use layouts then you process in layout order. As part of making layouts you draw a rectang at desired scale around objects then layouts are made automatically based on the rectang. Each layout has the title block at 1:1 scale ie true size like A2 but the mview reflects the objects at desired scale. Remove the line (setq lst (BubbleSort lst)) from the code. when asked to select titles pick them one at a time in the order you want and it should work. )) from the code. when asked to select titles pick them one at a time in the order you want and it should work. The issue with do in view order is what about using horizontal titles, a grid of titles, random placement of titles. Yes adding a extra attribute is one way around the problem. But for me use layouts. You will not look back. Mr. @BIGAL Thank you sincerely! "Remove the line (setq lst (BubbleSort lst))" - this action helped! And I will definitely take your advice... Quote
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.