adding hyperlink to block

adding hyperlink to block

mohandis2
Advocate Advocate
944 Views
7 Replies
Message 1 of 8

adding hyperlink to block

mohandis2
Advocate
Advocate

I manually add layout hyperlink to callout block so when I ctr-click the block, it activate the layout (example F01).

I'm trying to automate that using VBA,

Now I could make a SelectionSet of my target callout blocks and get it's attribute that matches the layout name,

I'm looking for a code to add hyperlink.

Does anyone have such a thing?

Thanks.  

0 Likes
Accepted solutions (1)
945 Views
7 Replies
Replies (7)
Message 2 of 8

Ed__Jobe
Mentor
Mentor

How about this sub? adds hyperlinks to selected text. Search this forum for GetSS_TextFilter.

 

Note that an entity has a Hyperlinks collection, i.e. you can add more than one hyperlink for users to choose from when adding hyperlinks programmatically. When you use the user interface, you can only add one link.

 


Sub SetHyperlinks()
    Dim s1 As AcadSelectionSet
    Dim txt As AcadText
    Dim hyp As AcadHyperlink
    Dim str As String
    Set s1 = GetSS_TextFilter
    For Each txt In s1
        For Each hyp In txt.Hyperlinks
            hyp.Delete
        Next hyp
        str = txt.TextString
        Set hyp = txt.Hyperlinks.Add(str)
        If Len(str) = 4 Then
            hyp.URL = Left(str, 1) & "\" & str & "_csil4800.pdf?target=_blank"
        Else
            hyp.URL = Left(str, 1) & "\" & str & "_csil1600.pdf?target=_blank"
        End If
        hyp.URLDescription = str
    Next txt

End Sub

 

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 8

mohandis2
Advocate
Advocate

this is Autodesk Hyperlink code example that I'm modifying to fit my needs

I want to ctr-click on the created circle and the hyperlink to activate "Layout1", but it does not work

Can you help please?

 

Moderator edit: Please post your code in a code window.

Sub Example_HyperLinks()
' This example creates a Circle object in model space and
' adds a new Hyperlink to its Hyperlink collection

Dim Hyperlinks As AcadHyperlinks
Dim Hyperlink As AcadHyperlink
Dim circleObj As AcadCircle
Dim centerPoint(0 To 2) As Double
Dim radius As Double
Dim HLList As String

' Define the Circle object
centerPoint(0) = 0: centerPoint(1) = 0: centerPoint(2) = 0
radius = 5#

' Create the Circle object in model space
Set circleObj = ThisDrawing.ModelSpace.AddCircle(centerPoint, radius)

ThisDrawing.Application.ZoomAll

' Get reference to the Circle's Hyperlinks collection
Set Hyperlinks = circleObj.Hyperlinks

'-------------------------------
'This is original Autodesk code
'-------------------------------

' ' Add a new Hyperlink complete with all properties
' Set Hyperlink = Hyperlinks.Add("AutoDesk")
' Hyperlink.URL = "www.autodesk.com"
' Hyperlink.URLDescription = "Autodesk Main Site"
' Hyperlink.URLNamedLocation = "MY_LOCATION"
'
' ' Read and display a list of existing Hyperlinks and
' ' their properties for this object
' For Each Hyperlink In Hyperlinks
' HLList = HLList & "____________________________________" & vbCrLf ' Separator
' HLList = HLList & "URL: " & Hyperlink.URL & vbCrLf
' HLList = HLList & "URL Description: " & Hyperlink.URLDescription & vbCrLf
' HLList = HLList & "URL Named Location: " & Hyperlink.URLNamedLocation & vbCrLf
' Next
'
' MsgBox "The circle has " & Hyperlinks.Count & " Hyperlink: " & vbCrLf & HLList

'-------------------------
'This is my modified code
'-------------------------

' Add a new Hyperlink complete with all properties
Set Hyperlink = Hyperlinks.Add("Layout1")
Hyperlink.URL = "#,Layout1"
Hyperlink.URLDescription = ",Layout1"
Hyperlink.URLNamedLocation = ",Layout1"

End Sub

 

0 Likes
Message 4 of 8

Ed__Jobe
Mentor
Mentor

I don't know how many times people say "It doesn't work" without any other info. What doesn't work? You must have some information that would help solve "the problem". The hyperlink doesn't get added? Is the url correct?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 8

mohandis2
Advocate
Advocate

the hyperlink added correctly, but instead of activating "Layou1", it opens the windows file browser

0 Likes
Message 6 of 8

mohandis2
Advocate
Advocate
But when I open the hyperlink dialogue box and close it right away without any change, the hyperlink works great.
0 Likes
Message 7 of 8

Ed__Jobe
Mentor
Mentor
Accepted solution

Enter HYPERLINK at the command line and select an entity. Now click on the left side>View of this drawing. >then select a view and hit Enter. This adds a hyperlink to your entity. Now run the attached code to inspect the hyperlink properties. This is how you need to format the properties when you add one by code. For a view hyperlink, the URL property should be blank. Since you put "#,Layout1", its trying to open a file called Layout1.

 

 

Sub ListHyperlinks()
    Dim s1 As AcadSelectionSet
    Set s1 = AddSelectionSet("listHyperlinks")  'search this forum for this function.
    Dim ent As AcadEntity
    s1.SelectOnScreen
    Set ent = s1(0)
    ThisDrawing.Utility.Prompt "URL: " & ent.Hyperlinks(0).URL & vbCrLf
    ThisDrawing.Utility.Prompt "URLDescription: " & ent.Hyperlinks(0).URLDescription & vbCrLf
    ThisDrawing.Utility.Prompt "URLNamedLocation: " & ent.Hyperlinks(0).URLNamedLocation & vbCrLf
End Sub

 

Also, if you save a named view in your drawing, you can use that instead of a layout.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 8 of 8

mohandis2
Advocate
Advocate

"the URL property should be blank"

that what solved my problem,

Thanks.

 

0 Likes