Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Update hyperlink based on field text.

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
Jonathan.Gray68UQW
1452 Views, 14 Replies

Update hyperlink based on field text.

Hey all!

I am looking for some help with how to get a hyperlink to match a "field" text in a drawing. The "field" that I have is one that points to a drawings location and name and what I want is for the hyperlink to match the "field" text. 

Please look at the video found here https://imgur.com/a/5cOyKkR for an example. In the video you will see that I have the drawing location as a "field" in my title block, and to make the hyperlink match this text/location I have to copy the text from the "field" and paste it into the hyperlink box.

My desire is, that the hyperlink gets updated to match the "field" entry because currently doing the whole copy paste thing is very repetitive for each new drawing or if the drawing gets moved to a new folder.  I understand if I have to issue a lisp command or something for this updating of the hyperlink to occur, it would be fantastic if that the hyperlink would get updated automatically anytime the text in the "field" changes which of course occurs if the drawing file is moved or renamed. But anything is better than coping and pasting that text.... 🙂

 

14 REPLIES 14
Message 2 of 15

If I'm understanding the problem, give this a try:

(defun c:foo (/ s str)
  ;; RJP » 2019-08-07
  (cond	((setq s (ssget "_X" '((0 . "mtext,text") (1 . "https*"))))
	 (regapp "PE_URL")
	 (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (entmod (append (entget x)
			   (list (list -3
				       (list "PE_URL"
					     (cons 1000 (setq str (cdr (assoc 1 (entget x)))))
					     '(1002 . "{")
					     (cons 1000 str)
					     '(1002 . "{")
					     '(1071 . 1)
					     '(1002 . "}")
					     '(1002 . "}")
				       )
				 )
			   )
		   )
	   )
	 )
	)
  )
  (princ)
)

*Edit .. to filter mapped paths you'll need to change the text filter to this"

(setq s (ssget "_X" '((0 . "mtext,text") (1 . "[A-Z]\:*"))))
Message 3 of 15

Hey! Thanks for taking the time to try to help me. Please see the attached drawing. In this drawing I need the hyperlink to match the drawing file path field,  I currently have the hyperlink set to "xxxxxx" as a place holder. 
I tried to run your lisp but I couldn't get it to really do anything for me, probably something I did wrong :(. 

Message 4 of 15

Try this:

(defun updatefield (/ s str)
  ;; RJP » 2019-08-07
  (cond	((setq s (ssget "_X" '((0 . "mtext,text") (1 . "@:\*.dwg*"))))
	 (regapp "PE_URL")
	 (setq str (strcat (getvar 'dwgprefix) (getvar 'dwgname)))
	 (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (entmod (append (entget x)
			   (list (list -3
				       (list "PE_URL"
					     (cons 1000 str)
					     '(1002 . "{")
					     (cons 1000 str)
					     '(1002 . "{")
					     '(1071 . 1)
					     '(1002 . "}")
					     '(1002 . "}")
				       )
				 )
			   )
		   )
	   )
	 )
	)
  )
  (princ)
)
;; Update on drawing open
(updatefield)
;; COMMAND REACTOR
(or *fieldpathreactor*
    (setq *fieldpathreactor* (vlr-command-reactor nil '((:vlr-commandwillstart . strtcmd))))
)
;; Update on publish or print
(defun strtcmd (calling-reactor strtcmdinfo)
  (and (wcmatch (car strtcmdinfo) "*PLOT*,*PUBLISH*") (updatefield))
  (princ)
)

Curious as to why you hyperlink to the current directory?

Message 5 of 15

This is perfect!!!!

 

We make PDF's of all of our drawings to share with the engineers in house to review. If they want to make a change on the drawing themselves instead of browsing to the file themselves by looking at the info along the side of the drawing they can now just click on that piece of text in the PDF thanks to you, 🙂 ,  and the drawing will open up for them automatically in Autocad. 

 

I do have one last question, is there a way to get this lisp you created for me to run every time that somebody issues the plot/publish command?  I ask this because if somebody saves the drawing in a new place the "field" autoupdates with the drawings new location and I would want the hyperlink to update as well.  I can add it to my "Startup Suite" but I don't know how to trigger it to run every time another command is issued. 

Message 6 of 15

I updated the code above to use a command reactor .. give it a go!

Message 7 of 15

This is perfection! HONESTLY, THANK YOU 🙂

Message 8 of 15


@Jonathan.Gray68UQW wrote:

This is perfection! HONESTLY, THANK YOU 🙂


Glad to help 🙂

Message 9 of 15

Not sure if you use XREFS in paperspace, but this will assign hyperlinks to all of them 🙂

(defun c:xrefhyperlinks (/ s path)
  ;; RJP » 2019-08-07
  (cond	((setq s (ssget "_X" '((0 . "insert") (410 . "~Model")(2 . "~`*U*"))))
	 (regapp "PE_URL")
	 (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (if (setq path
		      (findfile (cdr (assoc 1 (entget (tblobjname "block" (cdr (assoc 2 (entget x))))))))
	       )
	     (entmod (append (entget x)
			     (list (list -3
					 (list "PE_URL"
					       (cons 1000 path)
					       '(1002 . "{")
					       (cons 1000 path)
					       '(1002 . "{")
					       '(1071 . 1)
					       '(1002 . "}")
					       '(1002 . "}")
					 )
				   )
			     )
		     )
	     )
	   )
	 )
	)
  )
  (princ)
)
Message 10 of 15

Hey!  I have been using this code for a while now and love it! 

But I have one request, could you make it so that it updates on regen instead of plots or publishes?

I ask this because if you publish and don't publish in the background it does something crazy and makes the hyperlink go to a location on my C drive instead of the files actual location on a server. So my thoughts were, I believe Autocad always regens right before it publishes, and if it does in fact do this, the lisp should capture a good file location and not a bad one to a location on my C drive. 

Message 11 of 15

Why would it go to a path on your C drive? That seems quite odd.

 

You can try this version below to regen after the hyperlink is set.

(defun updatefield (/ s str)
  ;; RJP » 2019-08-07
  (cond	((setq s (ssget "_X" '((0 . "mtext,text") (1 . "@:\*.dwg*"))))
	 (regapp "PE_URL")
	 (setq str (strcat (getvar 'dwgprefix) (getvar 'dwgname)))
	 (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (entmod (append (entget x)
			   (list (list -3
				       (list "PE_URL"
					     (cons 1000 str)
					     '(1002 . "{")
					     (cons 1000 str)
					     '(1002 . "{")
					     '(1071 . 1)
					     '(1002 . "}")
					     '(1002 . "}")
				       )
				 )
			   )
		   )
	   )
	 )
	 (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acAllViewports)
	)
  )
  (princ)
)
;; Update on drawing open
(updatefield)
;; COMMAND REACTOR
(or *fieldpathreactor*
    (setq *fieldpathreactor* (vlr-command-reactor nil '((:vlr-commandwillstart . strtcmd))))
)
;; Update on publish or print
(defun strtcmd (calling-reactor strtcmdinfo)
  (and (wcmatch (car strtcmdinfo) "*PLOT*,*PUBLISH*") (updatefield))
  (princ)
)
Message 12 of 15

Hey! Yes, it is a really odd problem. The hyperlink gets screwed up if I publish and "do not run in the background". If I publish and "do run in the background" the hyperlinks are good and match the field path. I ran your updated code and still had the same problem. Do you have any ideas on how to fix this?  The folder they hyperlink gets pointed to is a temp folder on my c drive named "Ac_publishxxxx".

 

Edit: I meant to say I ran the updated code and still get the same error. 

 

 

Message 13 of 15

I cannot replicate that behavior? I tried publish in foreground and background and the path / hyperlink stayed intact. Not sure if this part of the problem but what is your DEMANDLOAD set to?

Message 14 of 15

Hey!  DEMANDLOAD is set to 3 for me. I just noticed something and wanted to share it, if you look at the file path across the top of the screen in the video link autocad actually changes where my file is at when that I use the publish command... this is crazy.. follow my mouse and you will see that it starts on the "H:" drive (where it should stay) then after I publish the file path changes to a temp folder on my "C:" drive. 

 

https://imgur.com/a/i9jL7mm

 

 

Message 15 of 15

Give this a try .. will not update if the path is on C drive.

(defun updatefield (/ s str)
  ;; RJP » 2019-08-07
  (cond	((and (/= "C" (strcase (substr (getvar 'dwgprefix) 1 1)))
	      (setq s (ssget "_X" '((0 . "mtext,text") (1 . "@:\*.dwg*"))))
	 )
	 (regapp "PE_URL")
	 (setq str (strcat (getvar 'dwgprefix) (getvar 'dwgname)))
	 (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (entmod (append (entget x)
			   (list (list -3
				       (list "PE_URL"
					     (cons 1000 str)
					     '(1002 . "{")
					     (cons 1000 str)
					     '(1002 . "{")
					     '(1071 . 1)
					     '(1002 . "}")
					     '(1002 . "}")
				       )
				 )
			   )
		   )
	   )
	 )
	)
  )
  (princ)
)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report