Lisp for adding hyperlink to text

Lisp for adding hyperlink to text

Anonymous
Not applicable
3,338 Views
7 Replies
Message 1 of 8

Lisp for adding hyperlink to text

Anonymous
Not applicable

I'm trying to write a lisp for selecting text in drawing and adding to the same text object a hyperlink with the text as part of it.

 

For exampel, the text wold be XXXX and the hyperlink C:/folder/XXXX.pdf

 

Anyone?

 

This would really make my day 🙂

 

 

0 Likes
Accepted solutions (1)
3,339 Views
7 Replies
Replies (7)
Message 2 of 8

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

I'm trying to write a lisp for selecting text in drawing and adding to the same text object a hyperlink with the text as part of it.

 

For exampel, the text wold be XXXX and the hyperlink C:/folder/XXXX.pdf

 

Anyone?

 

This would really make my day 🙂

 

 


As a demo...

(defun c:demo (/ sel text txt)
    (if (and (setq sel (entsel "\nSelect a Text: "))
             (setq text (entget (car sel)))
             (= (cdr (assoc 0 text)) "TEXT")
             (setq txt (cdr (assoc 1 text)))
        )
        (command "_.-HYPERLINK" "_I" "_O" sel "" (strcat "C:\\folder\\" txt ".pdf") "" "" "")
    )
    (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 3 of 8

Anonymous
Not applicable

It worked! Thank you!  Smiley Very Happy

 

Now I only have to figure out how to make this work for mulitple text-objects... 

 

0 Likes
Message 4 of 8

hmsilva
Mentor
Mentor

@Anonymous wrote:

It worked! Thank you!  Smiley Very Happy

 

Now I only have to figure out how to make this work for mulitple text-objects... 

 


You're welcome, emjo6RC8U
Glad I could help!

 

If you need some help for "make this work for mulitple text-objects", just asks...

 

EDITED:

(defun c:demo ( / ent i ss txt)
    (if (setq ss (ssget "_:L" '((0 . "TEXT"))))
        (repeat (setq i (sslength ss))
            (setq ent (ssname ss (setq i (1- i)))
                  txt (cdr (assoc 1 (entget ent)))
            )
            (command "_.-HYPERLINK" "_I" "_O" ent "" (strcat "C:\\folder\\" txt ".pdf") "" "" "")
        )
    )
    (princ)
)



Henrique

 

EESignature

0 Likes
Message 5 of 8

zachlampert
Participant
Participant

Could this be used to create a hyperlink for a text component in a label style? I have thousands of surveyed points that I have amended the point label style to generate the hyperlink path for but no way to activate the text component to be a hyperlink.

 

For example, I have a point with its surveyed information (northing, easting, attributes, etc.) from which I have created a text component that is the full path back to a corresponding photograph taken on a device other than the data collector. So,

 

                              POINT X Northing

                                            Easting

                                            Description

                                            Path

 

this is how my points display in C3D, where the 'Path' text component of my label style is the full path that needs to be hyperlinked. Can this lisp or a modified one accomplish this task for me, for all points in a given drawing? Just as a disclaimer, I know next to nothing about lisps but am willing to try!! 

 

Thanks

Zach Lampert

C3D 2017

0 Likes
Message 6 of 8

reb0265
Contributor
Contributor

So I just ran across this. and would love some help if yall are still on here... I feel my issue is in line with this solution.
I am attempting to write a code that searches a .dwg for a text string, then adds a hyperlink to that text string. The text strings/associated hyperlink pairs are in an excel file. So i have been trying to write a LISP program to do the following.

1. Select path to excel file with text/hyperlink pairs

2. Select path to directory with all the .dwg files to crawl through for the text strings
3. Select a color to change the text to (so you know what has been changed)

4. Run so that it crawls through each .dwg in the folder, finds the text string, and if it does find it, add a hyperlink from the excel file and change the color.

5. The extra would be if i had a dialog box pop up... havent been able to get it to do this.

 

I wrote this in python but my new job wont let me run python on my computer... and has stuck me with an older version of AutoCAD (2016) so it doesn't have integrated python. I tried to write it in LISP and and keep getting errors as I am not familiar with the syntax... even tried chatGPT for some help and it couldn't get it either. i think my issue is with the .dcl code I am attempting to write. 

Anyways if anyone has some advice I would love the help! I have to hyperlink about 3000 documents and I really don't want to do it manually!

0 Likes
Message 7 of 8

Sea-Haven
Mentor
Mentor

If your trying to read direct from excel you need to use "get application", the bad news is that LT 2024 lisp does not support the get application method. So are you reading a csv file instead ? I would say look into using Accoreconsole it allows you to modify a dwg without opening it. I dont think that is available either for LT 2024 sorry. So will need a big script use a lisp to make the script, scriptpro etc. Process a few dwgs at a time you will be surprised how fast you can open then run a lisp and close again.

0 Likes
Message 8 of 8

reb0265
Contributor
Contributor

Awesome! I will take a look at this, try some stuff and report back. I am using 2016 at the moment so the limitation of switching to LT hopefully won't be as bad.

If the CSV or excel piece is too difficult all I need is for it to pull through a database of text strings and associated hyperlinks, so I can make it whatever format is easies to deal with. It is just currently housed in an excel file. 

 

Could I maybe go at it from a different angle? My goal was to basically find and replace any text string found in that list with the same text but adding the hyperlink. Maybe you could modify the properties to add the hyperlink? Would a VBA script be easier to do this?

0 Likes