Author Topic: Add Layer Description to 'Text to Display' of a Hyperlink...  (Read 5533 times)

0 Members and 1 Guest are viewing this topic.

dortega4269

  • Guest
Add Layer Description to 'Text to Display' of a Hyperlink...
« on: August 01, 2014, 11:57:43 AM »
I'm not even sure if this is possible, let alone, where to start...

I'm trying to add a Hyperlink to a block using the 'Layer Description' as the 'Text to Display' portion of the Hyperlink.  Ultimately, I'd like to have this done once I add the block to a specific layer using LISP

Example:
Inserted block (Casework) would be placed on layer 'CW-18-BC  B3' and the hyperlink 'Text to Display' would retrieve the layer description for layer 'CW-18-BC  B3', which is 'Casework: 18in - Base Cabinet - (11in & 18in)'

As always, anyone with an idea to help lead me into the right direction would be greatly appreciated.

CadTutor:
http://www.cadtutor.net/forum/showthread.php?87972-Add-Layer-Description-to-Text-to-Dislpay-of-a-Hyperlink...&p=603657&viewfull=1#post603657

AUGI:
http://forums.augi.com/showthread.php?156967-Add-Layer-Description-to-Text-to-Display-of-a-Hyperlink&p=1272989#post1272989

End Result:
Hovering over block would provide Layer Description.
« Last Edit: August 01, 2014, 01:04:45 PM by dortega4269 »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Add Layer Description to 'Text to Display' of a Hyperlink...
« Reply #1 on: August 01, 2014, 12:13:49 PM »
Welcome to the Swamp.

Looks like a Field in the Hyperlink should be able to do that.
I never use hyperlinks so give it a little time for users to see this post.

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Add Layer Description to 'Text to Display' of a Hyperlink...
« Reply #2 on: August 01, 2014, 12:50:09 PM »
Heres a quick one. Welcome to TheSwamp :)

Code: [Select]
(defun c:puturl (/ _ss2l d e el)
  (defun _ss2l (ss / n result)
    (if (= (type ss) 'pickset)
      (repeat (setq n (sslength ss)) (setq result (cons (ssname ss (setq n (1- n))) result)))
    )
  )
  (foreach ename (_ss2l (ssget ":L"))
    (if (and (setq e (tblobjname "layer" (cdr (assoc 8 (entget ename)))))
     (setq el (entget e '("*")))
     (/= "" (setq d (cdr (last (assoc "AcAecLayerStandard" (cdr (assoc -3 el)))))))
)
      (progn (setq el (cadar (cdr (assoc -3 (entget ename '("PE_URL"))))))
     (entmod (list (cons -1 ename) (list -3 (list "PE_URL"))))
     (entmod (append (entget ename)
     (list (list -3
(list "PE_URL"
       (if el
el
(cons 1000 d)
       )
       '(1002 . "{")
       (cons 1000 d)
       '(1002 . "{")
       '(1071 . 0)
       '(1002 . "}")
       '(1002 . "}")
)
   )
     )
     )
     )
      )
    )
  )
  (princ)
)
« Last Edit: August 01, 2014, 03:31:28 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dortega4269

  • Guest
Re: Add Layer Description to 'Text to Display' of a Hyperlink...
« Reply #3 on: August 01, 2014, 01:16:56 PM »
Welcome to the Swamp.
Heres a quick one. Welcome to TheSwamp :)

Thank you for the greetings cab & ronjonp , I feel very Welcomed already.

ronjonp,
Your routine works great.  Could you make an option to overwrite layer description if a hyperlink already exists?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Add Layer Description to 'Text to Display' of a Hyperlink...
« Reply #4 on: August 01, 2014, 02:51:28 PM »
Welcome to the Swamp.
Heres a quick one. Welcome to TheSwamp :)

Thank you for the greetings cab & ronjonp , I feel very Welcomed already.

ronjonp,
Your routine works great.  Could you make an option to overwrite layer description if a hyperlink already exists?


I've updated the code above. Give it a test.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dortega4269

  • Guest
Re: Add Layer Description to 'Text to Display' of a Hyperlink...
« Reply #5 on: August 01, 2014, 03:11:39 PM »
I've updated the code above. Give it a test.

Very close, but not quite.  It overwrites the hyperlink and the hyperlink description.  I want to keep the hyperlink and overwrite the hyperlink description only.  Do you think this is attainable?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Add Layer Description to 'Text to Display' of a Hyperlink...
« Reply #6 on: August 01, 2014, 03:32:05 PM »
I've updated the code again. Let me know how it goes.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dortega4269

  • Guest
Re: Add Layer Description to 'Text to Display' of a Hyperlink...
« Reply #7 on: August 01, 2014, 03:55:48 PM »
I've updated the code again. Let me know how it goes.

Wow, it works perfectly, your a genius ronjonp!  Thanks for your help, I greatly appreciate your help.  :-)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Add Layer Description to 'Text to Display' of a Hyperlink...
« Reply #8 on: August 01, 2014, 04:04:23 PM »
Glad to help  8)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ReSiN

  • Mosquito
  • Posts: 1
Re: Add Layer Description to 'Text to Display' of a Hyperlink...
« Reply #9 on: March 06, 2017, 07:35:29 PM »
Hi ronjonp

I know this is a few years old now but is this supposed to work for any object?  Whenever I try your lisp I get:

Command: PUTURL

Select objects: 1 found

Select objects:  ; error: bad DXF group: (-3 ("PE_URL" (1000) (1002 . "{") (1000) (1002 . "{") (1071 . 0) (1002 . "}") (1002 . "}")))

Am I doing something wrong?

If possible could you expand this to have two options (or two different lisp files):
1) add the layer name to the hyperlink description only
2) add the layer name to both hyperlink and hyperlink description, with a defined relative path prefix and file extension suffix to the hyperlink (e.g. .data\layer name.nwd)

To further clarify I'm using Civil 3D 2015 and am trying to do this with different objects, blocks, mpolygons, etc.

Thanks
Paul
« Last Edit: March 06, 2017, 07:59:35 PM by ReSiN »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Add Layer Description to 'Text to Display' of a Hyperlink...
« Reply #10 on: March 07, 2017, 05:12:26 AM »
The error you receive points to the fact that a layer does not have a description. Ronjonp's code does not check this.
Code: [Select]
(defun c:puturl (/ _ss2l d e el)
  (defun _ss2l (ss / n result)
    (if (= (type ss) 'pickset)
      (repeat (setq n (sslength ss)) (setq result (cons (ssname ss (setq n (1- n))) result)))
    )
  )
  (regapp "PE_URL")
  (foreach ename (_ss2l (ssget ":L"))
    (if (and (setq e (tblobjname "layer" (cdr (assoc 8 (entget ename)))))
             (setq el (entget e '("*")))
             (setq d (cdr (last (assoc "AcAecLayerStandard" (cdr (assoc -3 el))))))
             (/= "" d)
        )
      (progn (setq el (cadar (cdr (assoc -3 (entget ename '("PE_URL"))))))
             (entmod (list (cons -1 ename) (list -3 (list "PE_URL"))))
             (entmod (append (entget ename)
                             (list (list -3
                                         (list "PE_URL"
                                               (if el
                                                 el
                                                 (cons 1000 d)
                                               )
                                               '(1002 . "{")
                                               (cons 1000 d)
                                               '(1002 . "{")
                                               '(1071 . 0)
                                               '(1002 . "}")
                                               '(1002 . "}")
                                         )
                                   )
                             )
                     )
             )
      )
    )
  )
  (princ)
)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Add Layer Description to 'Text to Display' of a Hyperlink...
« Reply #11 on: March 07, 2017, 09:24:16 AM »
Hi ronjonp
...
If possible could you expand this to have two options (or two different lisp files):
1) add the layer name to the hyperlink description only
2) add the layer name to both hyperlink and hyperlink description, with a defined relative path prefix and file extension suffix to the hyperlink (e.g. .data\layer name.nwd)
...
Thanks
Paul
Give this a try .. welcome to TheSwamp :)

Code - Auto/Visual Lisp: [Select]
  1. (defun puturl (path / _ss2l ln)
  2.   ;; RJP - 2017-03-07
  3.   (defun _ss2l (ss / n result)
  4.     (if (= (type ss) 'pickset)
  5.       (repeat (setq n (sslength ss)) (setq result (cons (ssname ss (setq n (1- n))) result)))
  6.     )
  7.   )
  8.   (regapp "PE_URL")
  9.   (foreach ename (_ss2l (ssget ":L"))
  10.     ;; Get layer name
  11.     (setq ln (cdr (assoc 8 (entget ename))))
  12.     ;; Remove existing hyperlink data
  13.     (entmod (list (cons -1 ename) (list -3 (list "PE_URL"))))
  14.     ;; Add new hyperlink data
  15.     (entmod (append (entget ename)
  16.                     (list (list -3
  17.                                 (list "PE_URL"
  18.                                       (cons 1000
  19.                                             (if path
  20.                                               (strcat path "" ln ".nwd")
  21.                                               ""
  22.                                             )
  23.                                       )
  24.                                       '(1002 . "{")
  25.                                       (cons 1000 ln)
  26.                                       '(1002 . "{")
  27.                                       '(1071 . 0)
  28.                                       '(1002 . "}")
  29.                                       '(1002 . "}")
  30.                                 )
  31.                           )
  32.                     )
  33.             )
  34.     )
  35.   )
  36.   ;; Clean exit
  37.   (princ)
  38. )
  39. ;; Create LayerName description and path to <relative>\LayerName\.nwd
  40. (defun c:urlpath nil (puturl ".\\MyPath\\"))
  41. ;; Create layername description and empty path
  42. (defun c:urlnopath nil (puturl nil))
« Last Edit: March 07, 2017, 09:38:59 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Add Layer Description to 'Text to Display' of a Hyperlink...
« Reply #12 on: March 07, 2017, 09:50:21 AM »
@ronjonp: AFAIK it is not necessary to remove existing Xdata before attaching new data.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Add Layer Description to 'Text to Display' of a Hyperlink...
« Reply #13 on: March 07, 2017, 09:57:33 AM »
@ronjonp: AFAIK it is not necessary to remove existing Xdata before attaching new data.
It appears so! Thanks.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC