Jump to content

Recommended Posts

Posted

I have compiled the following LISP. While there is currently only one block listed at the top, there are 15 more to go there for other borders that we use.

 

(defun c:AD (/ TodayDate str) 
(vl-load-com)                                        ;;; Do not forget to add

 (setq blocks
  '(
     "BORDER (ABOVENET) -BRC"
   )
 )
 
 (setq str
   (cond
     (
       (eq ""
         (setq str
           (getstring t
             (strcat "\nDate to be Placed <"
               (setq today (menucmd "m=$(edtime,$(getvar,DATE),MO/DD/YY)")) ">: "
             )
           )
         )
       )
       today
     )
     ( str )
   )
 )
 
  (AttribChng blocks "DATE" str)
 
  (princ "\n ----------------------------------------------")
  (princ (strcat "\n --------- Adjust Date - Version " ADTVerNum " ---------"))
  (princ (strcat "\n ---------------- Date: " str " --------------"))
  (princ "\n ----------------------------------------------")
  (princ)
  )

(defun AttribChng (blk tag val / ss)
 (vl-load-com)
 (mapcar (function set) '(blk tag)
         (mapcar (function strcase) (list blk tag)))

 (setq *doc (cond (*doc) ((vla-get-ActiveDocument
                            (vlax-get-acad-object)))))

 (if (ssget "_X" (list '(0 . "INSERT") (cons 2 blocks) '(66 . 1)))
   (progn
     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet *doc))

       (foreach att (vlax-invoke obj 'GetAttributes)

         (if (eq (strcase (vla-get-TagString att)) tag)
           (vla-put-TextString att val))))

     (vla-delete ss))

   (princ "\n** No Blocks Found **"))

 (princ))

 

However, I am getting an error of:

 

bad argument type: stringp ("BORDER (ABOVENET) -BRC")

 

And I'm not quite sure how to fix it.

 

Thanks.

Posted

try this:

  (setq blocks    (eval
    '(
     "BORDER (ABOVENET) -BRC"
    )
  )
) 

 

The AutoLisp interpreter is looking at this point for a string but what it is receiving is a list. Do you need to quote the variable blocks? Or could you just write

 

(setq blocks "BORDER (ABOVENET) -BRC")

Posted

With the first code I got a bad function error. The second one works, but I'd need to find a way for this to work for a list of 16 possible borders. Currently we are using a custom field but if anyone goes into the block editor and adjusts the value there, (which has been our procedure for some time), it negates the LISP program.

Posted

I think the problem lies within the dotted pair that you are trying to construct.

(cons 2 blocks)

Here you going to have to pass a single block name. I don't believe you can give a list of names. Try integrating an OR filter when constructing the selection set.. The way I understand what you are trying to accomplish is to filter those blocks out of the selection set that are not in your list of blocks.

(-4 . "<or") (2 . "BLOCK_NAME_01") (2 . "BLOCK_NAME_02") (2 . "BLOCK_NAME_03") (2 . "BLOCK_NAME_15") (-4 . "or>")

Posted

The problem is because the subfunction you took from here, was only intended for use with a single block.

 

Try this instead:

 

(defun c:AD ( / blocks str today ) (vl-load-com) 

 (setq blocks
  '(
     "BORDER (ABOVENET) -BRC"
   )
 )
 
 (setq str
   (cond
     (
       (eq ""
         (setq str
           (getstring t
             (strcat "\nDate to be Placed <"
               (setq today (menucmd "m=$(edtime,$(getvar,DATE),MO/DD/YY)")) ">: "
             )
           )
         )
       )
       today
     )
     ( str )
   )
 )
 
 (ChangeAttribValue blocks "DATE" str)

 (princ "\n ----------------------------------------------")
 (princ (strcat "\n --------- Adjust Date - Version " ADTVerNum " ---------"))
 (princ (strcat "\n ---------------- Date: " str " --------------"))
 (princ "\n ----------------------------------------------")
 (princ)
)


(defun ChangeAttribValue ( blocklist tag value / ss i e l )
 ;; Example By Lee Mac

 (setq tag       (strcase tag)
       value     (cons 1 value)
       blocklist (mapcar 'strcase blocklist)
       blocklist (apply 'strcat (cons (car blocklist) (mapcar '(lambda ( x ) (strcat "," x)) (cdr blocklist))))
 )
 (if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blocklist) '(66 . 1))))
   (repeat (setq i (sslength ss))
     (setq e (ssname ss (setq i (1- i))))
     (while
       (eq "ATTRIB"
         (cdr (assoc 0 (setq l (entget (setq e (entnext e))))))
       )
       (if (eq tag (strcase (cdr (assoc 2 l))))
         (entupd
           (cdr
             (assoc -1
               (entmod (subst value (assoc 1 l) l))
             )
           )
         )
       )
     )
   )
 )
 (princ)
)

Posted

So... it works, but this block is embedded within another, because our borders have dynamic visibilities where we use that block for both 24x36 and 11x17 sizes. With it being embedded, it didn't change. It only changes if it is on the outermost block in the drawing.

 

The name of the external block is "BORDER (Abovenet)" if that means anything.

Posted

Since it is nested you'll have to dig through the block definition and change the attributes values - such a change would be reflected throughout all inserts.

Posted

How exactly do you do that? I'm just not sure what you mean.

Posted

Either cycle through the objects in the relevant Block Object in the Block Collection using the vlax-for function, and use a conditional to test for Attribute objects; or alternatively use entnext to cycle through the entities in the Block Definition which can be acquired using the tblobjname function, and again, use a conditional to test for Attrib Entities and proceed to modify the values.

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