Jump to content

Recommended Posts

Posted

Hi guys,

 

I'm a new member as you can see, but i've been coming here for many years to find information about lisp. I've done a thread search and haven't located a solution to my issue. I am self taught, so there is only so far i can go without getting the experts involved.

 

My question (i think) is very similar to this thread http://www.cadtutor.net/forum/showthread.php?31762-Need-help-extracting-attribute-values-in-Lisp

 

What i need to do is:

1. Extract two attribute values (Tags are "DRGNO" "DRGREV") from an inserted block (Block name "DRG_SHEET.dwg").

2. Build a string in the Command Line using those 2 values.

 

It seems very simple, i just haven't fully wrapped my head around the list manipulation tools in AutoLISP.

 

Any help would be greatly appreciated.

 

Thanks, Scott.

Posted (edited)

I've found some verry usefull routines for attribute-reading and manipulating at Lee Macs website: http://www.lee-mac.com/attributefunctions.html

 

So the following code ist just a wrapper for one of those, hope it helps.

 

(defun c:DRG_SHEET
      (/ block blockname idx ss1 tag1str tag2str tag1 tag2 value)
 (vl-load-com)

 (command "_undo" "begin")        ; set undo-mark

 (setq blockname "DRG_SHEET")
 (setq tag1 "DRGREV")
 (setq tag2 "DRGNO")
 (setq SS1 nil)
 (setq idx 0)

 (command "._zoom" "_e")            ; zoom to extends, make sure ssget-X will work

 (setq SS1 (ssget "X" (list '(0 . "INSERT") (cons 2 blockname))))
                   ; select all blocks "DRG_SHEET"
 (princ "\nSelected blocks: ")
 (princ (itoa (sslength SS1)))        ; information only

 (if (= ss1 nil)
   (progn
     (princ "\nNo blocks found, exiting.")
     (exit)
   )                    ; progn
 )                    ; if

 (repeat (sslength ss1)
   (princ "\nIndex: ")
   (princ idx)                ; debug only

   (setq block (vlax-ename->vla-object (ssname ss1 idx)))
                   ; get VLA-Objektname 
   (setq tag1str (LM:vl-GetAttributeValue block tag1))
   (setq tag2str (LM:vl-GetAttributeValue block tag2))
                   ; call Lee Mac's subroutine

   (setq value    (strcat    tag1str
           "here you may add something like <-> "
           tag2str
       )
   )                    ; if you don't want a separator, delete "here...
                   ; concatenate both string
   (princ value)            ; print to console

   (setq idx (1+ idx))            ; set loop-index 1+
 )                    ; repeat
 (command "_undo" "end")        ; set undo-mark
 (princ)                ; force clean exit
)                    ; defun


;;; SUB-Routine
;;; http://www.lee-mac.com/attributefunctions.html
(defun LM:vl-GetAttributeValue (block tag)
 (setq tag (strcase tag))
 (vl-some
   (function
     (lambda (attrib)
   (if (eq tag (strcase (vla-get-Tagstring attrib)))
     (vla-get-TextString attrib)
   )
     )
   )
   (vlax-invoke block 'GetAttributes)
 )
)                    ; end sub

(c:DRG_SHEET)                ; autorun

regards

Wolfgang

Edited by wkplan

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