Author Topic: Batch hyperlinking based on attribute names in blocks  (Read 3882 times)

0 Members and 1 Guest are viewing this topic.

ahazen

  • Guest
Batch hyperlinking based on attribute names in blocks
« 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.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Batch hyperlinking based on attribute names in blocks
« Reply #1 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's a thread you can reference for adding a URL to an object.
« Last Edit: June 16, 2015, 11:44:03 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ahazen

  • Guest
Re: Batch hyperlinking based on attribute names in blocks
« Reply #2 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.

ahazen

  • Guest
Re: Batch hyperlinking based on attribute names in blocks
« Reply #3 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.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Batch hyperlinking based on attribute names in blocks
« Reply #4 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. )
« Last Edit: June 17, 2015, 08:37:03 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ahazen

  • Guest
Re: Batch hyperlinking based on attribute names in blocks
« Reply #5 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!

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Batch hyperlinking based on attribute names in blocks
« Reply #6 on: June 16, 2015, 12:25:40 PM »
Glad to help :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Batch hyperlinking based on attribute names in blocks
« Reply #7 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.
« Last Edit: June 16, 2015, 01:02:19 PM by Lee Mac »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Batch hyperlinking based on attribute names in blocks
« Reply #8 on: June 16, 2015, 01:16:49 PM »
@ ronjonp:
You are using entmod twice. I think the first call is not necessary.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Batch hyperlinking based on attribute names in blocks
« Reply #9 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.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Batch hyperlinking based on attribute names in blocks
« Reply #10 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:

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Batch hyperlinking based on attribute names in blocks
« Reply #11 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 ) .

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC