Jump to content

Extract an attribute from all blocks in a drawing


AldLuj28

Recommended Posts

Hi there.. im new in the forum and in coding in AutoLisp... so im looking for a form in which i can extract a specific attribute from all blocks that are in a DWG and then this list write it in a txt file :unsure:

Link to comment
Share on other sites

Yeah im aware of it im trying to do something like this:

 

(defun C:AELD (/ objBlock strValue)
(setq AllBlocks (ssget "X" (list (cons 0 "INSERT"))))

(repeat (sslength AllBlocks)
 (setq objBlock (vlax-ename->vla-object (CDR (CAR (entget (ssname AllBlocks))))))
 (foreach objAttribute (vlax-invoke objBlock "getattributes")

(if (= (strcase (vla-get-tagstring objAttribute));
     (strcase "DeviceID"))

  (progn
    (setq strValue (vla-get-textstring objAttribute))
  )
)    
   )
(princ strValue)
 )
)

 

but it throws me an error : too few arguments

Edited by rkmcswain
added [CODE] tags
Link to comment
Share on other sites

Things like this ?

 

(defun c:Test (/ ss sn i e)
 ;; Tharwat 18.06.2015 ;;
 (if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (while (/= (cdr (assoc 0 (setq e (entget sn)))) "SEQEND")
       (if (not (eq (cdr (assoc 1 e)) nil))
         (print (cdr (assoc 1 e)))
       )
       (setq sn (entnext sn))
     )

   )
 )
 (princ)
)

Link to comment
Share on other sites

Yeah something like that but i want that all the blocks are selected automacally.. cause i need a specific attribute from all blocks

Link to comment
Share on other sites

Ok, but if i want to ... find only the attribute named "DevicedID1" that is part from all the blocks, what i need to add.. and one thing more to write this string in a text i can use (setq fil(open "file" "w")?

Link to comment
Share on other sites

Try this ...

 

(defun c:Test (/ ss fl on sn i e)
 ;; Tharwat 18.06.2015 ;;
 (if (and (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1))))
          (setq fl (getfiled "Specify name of txt file"
                             (getvar 'dwgprefix)
                             "txt"
                             1
                   )
          )
          (setq on (open fl "w"))
     )
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (while (/= (cdr (assoc 0 (setq e (entget sn)))) "SEQEND")
       (if (and (eq (cdr (assoc 0 e)) "ATTRIB")
                (eq (strcase (cdr (assoc 2 e))) "DEVICEDID1")
           )
         (write-line (cdr (assoc 1 e)) on)
       )
       (setq sn (entnext sn))
     )
   )
 )
 (if on
   (close on)
 )
 (princ)
)

Link to comment
Share on other sites

Thanks ..finally i made it work... i changed some stuff ... and the result its this totally functional :

 

(defun c: PROMISE (/ ss fl on sn i e)

(if (and (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1))))

(setq on (open "C:\\Temp\\Emblemas.txt" "w"))

)

(repeat (setq i (sslength ss))

(setq sn (ssname ss (setq i (1- i))))

(while (/= (cdr (assoc 0 (setq e (entget sn)))) "SEQEND")

(if (not (eq (cdr (assoc 1 e)) nil))

 

(if(not(eq (cdr (assoc 1 e)) ""))

(princ (strcat "," (cdr (assoc 1 e))) on)

)

)

(setq sn (entnext sn))

)

)

)

(if on

(close on)

)

(princ)

)

 

 

Again thanks a lot for the help :D

Edited by AldLuj28
Link to comment
Share on other sites

Ok, but if i want to ... find only the attribute named "DevicedID1" that is part from all the blocks, what i need to add.. and one thing more to write this string in a text i can use (setq fil(open "file" "w")?

 

Thanks ..finally i made it work... i changed some stuff ... and the result its this totally functional :

 

Firstly , what you have modified is not matching or following what you have asked in your previous post .

 

Secondly , it is a very bad idea to remove the author name from my codes or anyone's codes/ works.

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