TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ahazen on June 16, 2015, 11:34:30 AM

Title: Batch hyperlinking based on attribute names in blocks
Post by: ahazen on June 16, 2015, 11:34:30 AM
I have hyperlinks to attach with names like 360-001.html or www.website.com/360-001. I was wondering if I could get help automating the hyperlinking process for these blocks. So block with attribute "001" would automatically be hyperlinked with www.website.com/360-001 when the command is run.
Title: Re: Batch hyperlinking based on attribute names in blocks
Post by: ronjonp on June 16, 2015, 11:36:59 AM
Is the attribute TAG named "001" or is that the value for the attribute? .. BTW .. welcome to TheSwamp  :)
HERE (http://www.theswamp.org/index.php?topic=47538.msg525340#msg525340)'s a thread you can reference for adding a URL to an object.
Title: Re: Batch hyperlinking based on attribute names in blocks
Post by: ahazen on June 16, 2015, 11:48:44 AM
Thanks for the welcome! I hope to learn  :lol:. The TAG is 001. In this specific situation the attribute value is 360. I want to utilize the tag.
Title: Re: Batch hyperlinking based on attribute names in blocks
Post by: ahazen on June 16, 2015, 11:55:51 AM
Wait. I meant I want the Value for the attribute. Sorry, I flipped those mentally. The tag is 360 and the value is 001.
Title: Re: Batch hyperlinking based on attribute names in blocks
Post by: ronjonp on June 16, 2015, 12:02:57 PM
Give this a try:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:puturl (/ _ss2l tag val)
  2.   (defun _ss2l (ss / n result)
  3.     (if (= (type ss) 'pickset)
  4.       (repeat (setq n (sslength ss)) (setq result (cons (ssname ss (setq n (1- n))) result)))
  5.     )
  6.   )
  7.   (setq tag "360")
  8.   (regapp "PE_URL")
  9.   (foreach ename (_ss2l (ssget ":L" '((0 . "insert") (66 . 1))))
  10.     (if
  11.       (and
  12.         (vl-some '(lambda (x) (and (= tag (vla-get-tagstring x)) (setq val (vla-get-textstring x))))
  13.                  (vlax-invoke (vlax-ename->vla-object ename) 'getattributes)
  14.         )
  15.         (setq val (strcat "www.website.com/" tag "-" val))
  16.       )
  17.        (entmod (append (entget ename)
  18.                        (list (list -3
  19.                                    (list "PE_URL"
  20.                                          (cons 1000 val)
  21.                                          '(1002 . "{")
  22.                                          (cons 1000 val)
  23.                                          '(1002 . "{")
  24.                                          '(1071 . 0)
  25.                                          '(1002 . "}")
  26.                                          '(1002 . "}")
  27.                                    )
  28.                              )
  29.                        )
  30.                )
  31.        )
  32.     )
  33.   )
  34.   (princ)
  35. )
Title: Re: Batch hyperlinking based on attribute names in blocks
Post by: ahazen on June 16, 2015, 12:16:34 PM
That is working, I'll make some edits and get back to you, but that gave me the parts I was missing!

Thanks, that's a positive first impression to the forum!
Title: Re: Batch hyperlinking based on attribute names in blocks
Post by: ronjonp on June 16, 2015, 12:25:40 PM
Glad to help :)
Title: Re: Batch hyperlinking based on attribute names in blocks
Post by: Lee Mac on June 16, 2015, 12:56:15 PM
Another, using ActiveX:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:batchurl ( / h i o s v )
  2.      (if (setq s (ssget "_:L" '((0 . "INSERT") (66 . 1))))
  3.          (repeat (setq i (sslength s))
  4.              (if (setq o (vlax-ename->vla-object (ssname s (setq i (1- i))))
  5.                        h (vla-get-hyperlinks o)
  6.                        v (vl-some '(lambda ( x ) (if (= "360" (vla-get-tagstring x)) (vla-get-textstring x))) (vlax-invoke o 'getattributes))
  7.                  )
  8.                  (if (zerop (vla-get-count h)) (vla-add h (strcat "www.website.com/360-" v)))
  9.              )
  10.          )
  11.      )
  12.      (princ)
  13. )

The above will only add a new hyperlink if the block has no existing hyperlinks to avoid duplication.
Title: Re: Batch hyperlinking based on attribute names in blocks
Post by: roy_043 on June 16, 2015, 01:16:49 PM
@ ronjonp:
You are using entmod twice. I think the first call is not necessary.
Title: Re: Batch hyperlinking based on attribute names in blocks
Post by: ronjonp on June 16, 2015, 01:30:31 PM
@ ronjonp:
You are using entmod twice. I think the first call is not necessary.


Ahh yes .. that carried over from the other thread referenced to keep an existing hyperlink but change the text shown. Updated above.
Title: Re: Batch hyperlinking based on attribute names in blocks
Post by: roy_043 on June 17, 2015, 06:36:11 AM
Ahh yes .. that carried over from the other thread referenced to keep an existing hyperlink but change the text shown. Updated above.
I don't know the thread you are referring to. But whenever you write new Xdata for an aplication all the old data is automatically removed. You cannot update a single item or append data. So I think that in the 'other thread' there is then also a superfluous call to entmod. :wink:
Title: Re: Batch hyperlinking based on attribute names in blocks
Post by: ronjonp on June 17, 2015, 08:36:25 AM
Ahh yes .. that carried over from the other thread referenced to keep an existing hyperlink but change the text shown. Updated above.
I don't know the thread you are referring to. But whenever you write new Xdata for an aplication all the old data is automatically removed. You cannot update a single item or append data. So I think that in the 'other thread' there is then also a superfluous call to entmod. ;)

You are correct it is superfluous. I'll try to be better in the future  :P  We also need to check that PE_URL is registered before writing xdata ( updated in code above ) .