autocad lisp for hiperlink

autocad lisp for hiperlink

Anonymous
Not applicable
2,357 Views
9 Replies
Message 1 of 10

autocad lisp for hiperlink

Anonymous
Not applicable

hello,

 

i need a lisp that can give the object which selected hiperlink for data extraction. i would like to do choose object and choose the text or mtext then the text become a hiperlink for the object. if it is possible please help me. 

0 Likes
Accepted solutions (2)
2,358 Views
9 Replies
Replies (9)
Message 2 of 10

pbejse
Mentor
Mentor

@Anonymous wrote:

hello,

 

i need a lisp that can give the object which selected hiperlink for data extraction. i would like to do choose object and choose the text or mtext then the text become a hiperlink for the object. if it is possible please help me. 


object as an external file? say a pdf 

 

(Defun c:demo  (/ target text)
      (if (and (setq target
                          (getfiled
                                "Select object for hyperlink" "" "pdf" 16))
               (setq text (car  (entsel
                                      "\nSelect object to assign hyperlink")))
               )
            (command "_.-HYPERLINK" "_I" "_O" text "" target "" "")
            )
      )

HTH

 

 

0 Likes
Message 3 of 10

Anonymous
Not applicable

thanks for your answer but i meant that i have a object in autocad also have a text in autocad when i give command by the lisp firstly i will choose the object then i will choose the text or mtext after i will finish command 

 

when i look to properties of the object i have to see in the hiperlink windows text to display must be equal with the text or mtext that had been chosen.

0 Likes
Message 4 of 10

pbejse
Mentor
Mentor

@Anonymous wrote:

thanks for your answer but i meant that i have a object in autocad also have a text in autocad when i give command by the lisp firstly i will choose the object then i will choose the text or mtext after i will finish command 

 

when i look to properties of the object i have to see in the hiperlink windows text to display must be equal with the text or mtext that had been chosen.


Hyperlink in Autocad or Fields in Autocad

 

Please confirm which one are you referring to.

 

0 Likes
Message 5 of 10

Anonymous
Not applicable

 i put some pics i would like to that

0 Likes
Message 6 of 10

DannyNL
Advisor
Advisor
Accepted solution

Please try this piece of code.

Be aware it will only work for Text and not MText. And it is also possible to create multiple hyperlinks on one object, while the properties will only show you the first one. So not 100% complete and foolproof, but it is a start Smiley Happy

 

(defun c:AddTextAsHyperlink (/ ATAH_TextObject ATAH_HyperlinkObject ATAH_TextString)
   (setq ATAH_HyperlinkObject (car (entsel "\nSelect object for hyperlink: ")))
   (if
      (and
         ATAH_HyperlinkObject
         (setq ATAH_TextObject (car (entsel "\nSelect Text: ")))
         (= (vla-get-ObjectName (setq ATAH_TextObject (vlax-ename->vla-object ATAH_TextObject))) "AcDbText")
      )
      (progn
         (setq ATAH_HyperlinkObject (vlax-ename->vla-object ATAH_HyperlinkObject))         
         (vla-Add (vla-get-Hyperlinks ATAH_HyperlinkObject) (setq ATAH_TextString (vla-get-TextString ATAH_TextObject)))
         (princ (strcat "\n ** Hyperlink with text '" ATAH_TextString "' created."))
      )
      (princ "\n ** Error no text or target object selected!")
   )
   (princ)
)

 

Message 7 of 10

Anonymous
Not applicable

thank you so much it is really working 🙂

 

also i am thinking about another option can we do that ; for excample when i choose a tex like sa-1 and assign a line pline etc. after when i choose and other line, pline etc. can it assign a text to hiperlink as sa-2, for another sa-3, and next sa-4..... ?

0 Likes
Message 8 of 10

DannyNL
Advisor
Advisor
Accepted solution

That's not too complicated to add, so here it goes.

I'm using a VBScript.RegExp to check and extract the number at the end of the selected text. Only when the text ends with a number, you will get the option to select additional objects to add a hyperlink to with each an increment of 1.

 

(defun c:AddTextAsHyperlink (/ ATAH_TextObject ATAH_HyperlinkObject ATAH_TextString ATAH_SequenceNumber ATAH_BaseText ATAH_SequenceNumber)
   (setq ATAH_HyperlinkObject (car (entsel "\nSelect object for hyperlink: ")))
   (if
      (and
         ATAH_HyperlinkObject
         (setq ATAH_TextObject (car (entsel "\nSelect Text: ")))
         (= (vla-get-ObjectName (setq ATAH_TextObject (vlax-ename->vla-object ATAH_TextObject))) "AcDbText")
      )
      (progn
         (setq ATAH_HyperlinkObject (vlax-ename->vla-object ATAH_HyperlinkObject))         
         (vla-Add (vla-get-Hyperlinks ATAH_HyperlinkObject) (setq ATAH_TextString (vla-get-TextString ATAH_TextObject)))
         (princ (strcat "\n ** Hyperlink with text '" ATAH_TextString "' created."))
         (if
            (setq ATAH_SequenceNumber (RegEx "\\d+$" ATAH_TextString))
            (progn
               (setq ATAH_BaseText (substr ATAH_TextString 1 (vl-string-search ATAH_SequenceNumber ATAH_TextString)))
               (while
                  (setq ATAH_HyperlinkObject (car (entsel "\nSelect next object for incremental hyperlink <ENTER to exit>: ")))
                     (setq ATAH_HyperlinkObject (vlax-ename->vla-object ATAH_HyperlinkObject))         
                     (vla-Add (vla-get-Hyperlinks ATAH_HyperlinkObject) (setq ATAH_TextString (strcat ATAH_BaseText (setq ATAH_SequenceNumber (itoa (1+ (atoi ATAH_SequenceNumber)))))))
                     (princ (strcat "\n ** Hyperlink with text '" ATAH_TextString "' created."))
               )
            )
         )               
      )
      (princ "\n ** Error no text or target object selected!")
   )
   (princ)
)

(defun RegEx (RE_Pattern RE_SearchString / RE_RegExObject RE_Result RE_Return)
   (if
      (and
         (= (type RE_SearchString) 'STR)
         (= (type RE_Pattern)      'STR)
      )
      (progn
         (setq RE_RegExObject (vlax-get-or-create-object "VBScript.RegExp"))
         (vlax-put-property RE_RegExObject 'Pattern RE_Pattern)
         (setq RE_Result (vl-catch-all-apply 'vlax-invoke-method (list RE_RegExObject 'Execute RE_SearchString)))
         (if
            (and
               (not (vl-catch-all-error-p RE_Result))
               (> (vla-get-Count RE_Result) 0)
            )      
            (setq RE_Return (vla-get-Value (vlax-get-property RE_Result 'Item 0)))      
         )
         (vlax-release-object RE_RegExObject)
      )
   )
   RE_Return
)

 

Message 9 of 10

Anonymous
Not applicable

İT İS WONDERFULL THAT İS WHAT I WANT, i am so happy i will give hiperlink to object and when i extract them i will not mix . i owe you a dinner my friend if you visit turkey, be sure about that you will have wonderfull dinner like the this lsp 🙂

Message 10 of 10

DannyNL
Advisor
Advisor

Thanks and no problem. Glad I could help Smiley Happy