Copy & Paste Existing Hyperlink From One Object to Another

Copy & Paste Existing Hyperlink From One Object to Another

Anonymous
Not applicable
1,725 Views
6 Replies
Message 1 of 7

Copy & Paste Existing Hyperlink From One Object to Another

Anonymous
Not applicable

There is a PASTEASHYPERLINK command, but I can't find a "COPYHYPERLINK" command.

 

I know you can right-click an object with a hyperlink and choose Hyperlink and then choose copy hyperlink, but I want to put this in a Macro so I can;

Pick the object with the existing Hyperlink

and then

Pick the object that I want the Hyperlink attached to.

 

 - Hundreds of times

 

It would be useful to me, maybe others as well.

Thanks in advance for any help.

Dan

0 Likes
Accepted solutions (2)
1,726 Views
6 Replies
Replies (6)
Message 2 of 7

rkmcswain
Mentor
Mentor

You could use something like this to grab the URL from an object.

 

(setq sel (entsel))
(setq ent (car sel))
(setq obj (vlax-ename->vla-object ent))
(setq hyp (vlax-get obj "Hyperlinks"))
(vlax-for m hyp
  (princ (setq base (strcat "\n " (vlax-get m "URL"))))
)

...and then here is an example of writing a hyperlink to an object.  Just needs a bit of assembly 🙂

 

 

R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 3 of 7

Anonymous
Not applicable
RK, thank you for the assistance but I'm not sure exactly what to do with this. I saved it as a lisp file, loaded it and it runs and returns the location to where I want the hyperlink to go but it's not saved in memory to use with the PASTEASHYPERLINK command. I think you're really on the right track and I will keep trying to figure out what I can do with it. I definitely appreciate your assistance!
Dan
0 Likes
Message 4 of 7

rkmcswain
Mentor
Mentor
If I can find the time soon, I'll return and try and assemble something. (AU Docs are due this week!)

You need the part in the link I provided to take the hyperlink data, and write it to another entity.

Maybe someone else will come along and help out also.
R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 5 of 7

patrick_35
Collaborator
Collaborator
Accepted solution

Hi

 

For example

(defun c:chy(/ doc ent hyp new)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc)
  (while (setq ent (entsel "\nSelect object with hyperlinks : "))
    (setq hyp (vla-get-hyperlinks (vlax-ename->vla-object (car ent))))
    (if (zerop (vla-get-count hyp))
      (princ "\nNo hyperlinks on this object.")
      (while (setq ent (entsel "\nSelect object to paste hyperlinks : "))
	(setq ent (vla-get-hyperlinks (vlax-ename->vla-object (car ent))))
	(vlax-for lin hyp
	  (setq new (vla-add ent "Patrick_35"))
	  (mapcar '(lambda(x) (vlax-put new x (vlax-get lin x))) '(url urldescription urlnamedlocation))
	)
      )
    )
  )
  (vla-endundomark doc)
  (princ)
)

@+

0 Likes
Message 6 of 7

braudpat
Mentor
Mentor

 

Hello Patrick

 

1) Nice routine

For the users, please add the line : (vl-load-com)

 

2) Why copy the HyperLink to only ONE object !

For me, it would be better to copy to N objects !

 

Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 7 of 7

patrick_35
Collaborator
Collaborator
Accepted solution

Thank's Patrick


1) eternal forgot
2) you're right, I simplifies entries

 

(defun c:chy(/ doc ent hyp new sel)
  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc)
  (and (setq ent (entsel "\nSelect object with hyperlinks : "))
       (setq hyp (vla-get-hyperlinks (vlax-ename->vla-object (car ent))))
    (if (zerop (vla-get-count hyp))
      (princ "\nNo hyperlinks on this object")
      (progn
	(princ "\nSelect objects to paste hyperlinks : ")
	(and (ssget)
	  (progn
	    (vlax-for ent (setq sel (vla-get-activeselectionset doc))
	      (vlax-for lin hyp
		(setq new (vla-add (vla-get-hyperlinks ent) "Patrick_35"))
		(mapcar '(lambda(x) (vlax-put new x (vlax-get lin x))) '(url urldescription urlnamedlocation))
	      )
	    )
	    (vla-delete sel)
	  )
	)
      )
    )
  )
  (vla-endundomark doc)
  (princ)
)

 

Regards

 

@+