Jump to content

Recommended Posts

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

 

cell_4F3.png

Format_F.dwg

Edited by Nikon
Posted (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 by BIGAL
  • Thanks 1
Posted
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?..

Posted

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

 

 

 

  • Thanks 1
Posted
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...

Posted

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

  • Thanks 1
Posted (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

 

excele-all-att.png

 

excele1.png

Edited by Nikon
Posted

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)

 

  • Like 1
Posted (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 by Nikon
Posted (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?

cell_7F3.png

Or

cell_4F3.png

Edited by Nikon
Posted

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)

 

  • Like 1
Posted (edited)

Mr. @marko_ribar

Thank you very much!::! Now the attributes are arranged in order!::!

 

cell_4F3-1.png

Edited by Nikon
Posted (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

Image 1.png

Edited by Nikon
Posted

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)

 

  • Thanks 1
Posted (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?

CELL_7F3.png

Edited by Nikon
Posted (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 by BIGAL
  • Thanks 1
Posted
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...

  • Nikon changed the title to Change the code so that it extract only one attribute without a tag

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