Jump to content

I need an Autocad LISP for Listing Beam Sizes


Recommended Posts

Posted

Hello all,

 

My first post is an emergency call for help :( I have an AutoCAD drawing about beams of a structure. I need the names and sizes of those beams as an Excel list.

 

Both the name and sizes (width and depth) of the beam are written in Text form, in two different layers. Lines of the beam are on another layer

 

Sizes (width and depth) are written on the beam. Height should be read from the project with DIM command since the beam consists of only two lines.

 

A screenshot of the dwg can be found in the attachment. All the layers you need are coloured purple.

 

Basicly, LISP should be able to get the name and write it in Excel column1, dimensions to column 2 and 3 (or only column 2, I can manage to seperate it ) and length of these two lines above and below these texts and write it in another column.

 

Do you know any LISPs that can do what I need?

 

Thanks!

Beams.jpg

Posted

You have a problem yes all the text can be written yes the line length can be written but the two are non relational.

 

But all is not lost 2 methods you can find the text and look for an object nearby in this case a line on a layer. You can though get a wrong answer depending on where you place the text, a hint here is in the middle not at a corner. The other way a little more complicated is make the length and width a block with a field that is the length of the desired line. Oh a 3rd is use xdata which links the line to some data.

 

So do a bit of google help about blocks and fields. You can turn off attributes in the block so you dont see those values but you can retrieve them.

Block

width

height

name invisible field reads other text

length invisible field reads line length

 

I have to go now but some one else may jump in with a block for you.

Posted (edited)

Have a look at this. The next step would be a lisp to re-associate new Text and lines just copy lines text and block for now.

new block.dwg

Edited by BIGAL
Posted (edited)

This is written to match your request but can be easily changed to suit other block updates.

; This updates a block with 4 attributes 
; Just insert block with 4 attributes 1st 
; insert block or copy etc
; by Alan H June 2017

(defun c:blk4 ( / len t1 t2 obj desc x att )
(vl-load-com)
(while (/=  (vlax-property-available-p (setq obj (vlax-ename->vla-object (car (entsel "Select Block")))) 'Hasattributes) T)
(alert "You have not picked a block object ")
)

(setq att (vlax-invoke obj 'getattributes))

(while (/=  (vlax-property-available-p (setq len (vlax-ename->vla-object (car (entsel "\nSelect Line: ")))) 'length) T)
(alert "You have not picked a P/line object ")
)

(while (/=  (vlax-property-available-p (setq t1   (vlax-ename->vla-object (car (entsel "\nSelect Text 1: ")))) 'Textstring) T)
(alert "You have not picked a text object ")
)

(while (/=  (vlax-property-available-p (setq t2   (vlax-ename->vla-object (car (entsel "\nSelect Text 2: ")))) 'Textstring) T)
(alert "You have not picked a text object ")
)

(while (/=  (vlax-property-available-p (setq desc (vlax-ename->vla-object (car (entsel "\nSelect Description : ")))) 'Textstring) T)
(alert "You have not picked a text object ")
)

(setq atlength (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-Objectid len)) ">%).Length>%"))
(setq att1     (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-Objectid t1)) ">%).TextString>%"))
(setq att2     (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-Objectid t2)) ">%).TextString>%"))
(setq atdesc   (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-Objectid desc)) ">%).TextString>%"))

; this is for 1st 4 attributes starts at 0 not 1 tested on block with 16 attributes.

(vla-put-textstring (nth 0 att) atlength)
(vla-put-textstring (nth 1 att) atdesc)
(vla-put-textstring (nth 2 att) att1)
(vla-put-textstring (nth 3 att) att2)

(command "regen")
(princ)
) ; defun
(c:blk4)

Edited by BIGAL
Posted

Interesting suggestion BIGAL, this may be a more handy version:

 

; http://www.cadtutor.net/forum/showthread.php?100975-I-need-an-Autocad-LISP-for-Listing-Beam-Sizes
; Simple field attributes - original concept by BIGAL
(defun C:test ( / e )
 (and (or (setq e (car (entsel "\nSelect attributed block: "))) (prompt "\nInvalid selection."))
   (vl-every '(lambda (x) (member x (entget e))) '((0 . "INSERT") (66 . 1)))
   (progn
     (foreach att (vlax-invoke (vlax-ename->vla-object e) 'GetAttributes)
       (and (vlax-write-enabled-p att)
         (setq e (car (nentsel (strcat "\nSelect object for \"" (vla-get-TagString att) "\" attribute: "))))
         (vl-some 
           '(lambda (x) 
             (if (vlax-property-available-p (vlax-ename->vla-object e) x)
               (vla-put-TextString att 
                 (strcat "%<\\AcObjProp Object(%<\\_ObjId " 
                   (itoa (vla-get-ObjectId (vlax-ename->vla-object e)))
                   ">%)." x ">%"
                 ); strcat 
               ); vla-put-TextString
             ); if 
           ); lambda 
           '("Length" "TextString") ; "Area" could be added, list is sorted by priority
         ); vl-some
       ); and 
     ); foreach
     (vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
   ); progn
 ); and
 (princ)
); defun 

Posted (edited)

Hi Grr I did look at using nentsel but that meant more picks rather than just populating the 4 values required. I was aware also about checking property but did mention that it expected the user to pick correct objects. Version 2 now has property check.

 

The one change I would make is to not use foreach but rather directly edit the attribute its either a VL item or count will have some time today to look more into this method. Turned out to be a list.

 

Code above has been changed to directly update the correct attribute without using foreach testing.

 

The code is usable on any block so long as for this test it has 4 attributes or more.

Edited by BIGAL

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