Author Topic: Hyperlink (VBA) problems..  (Read 2367 times)

0 Members and 1 Guest are viewing this topic.

hardwired

  • Guest
Hyperlink (VBA) problems..
« on: February 08, 2008, 09:44:13 AM »
Hi,

Have a hyperlink problem....the program i'm currently doing will take user text etc and insert a pre-made modelspace marker block in modelspace to indicate where the chosen layout is pointing to - it also should add a hyperlink to the chosen layout (to the marker block) so the user can jump to that layout..

It all works fine, just the hyperlink part, which i have now got to work sort of. After checking the hyperlink editor, the path, url and text to display all look like they should whenever you manually add a hyperlink to a layout - even on the Target or View of this Drawing page, its highlighting the correct layout, but instead of jumping to the layout, it will open up a Windows Explorer window to the drawing path directory..

If I open up the hyperlink editor, as i said it all looks fine, and for some reason if i click ok, then trying the link out again works this time, but only if i do that, otherwise it just opens up explorer..


Below is an extract of the program code. Can someone look at what could be wrong or let me know why the link won't 100% work..


Code: [Select]
Option Explicit
Dim response As Integer  'Yes/No..
Dim layoutX, layoutY As AcadLayout  'Acad Layout..
Dim layoutZ As String
Dim blockX As AcadBlockReference 'Inserted block..
Dim blockPoint As Variant ' Pick point for block insert..
Dim attribZ As Variant ' Attributes for inserted block..
Dim countx As Integer 'Counter for getting attributes..
Dim EntX As AcadEntity 'Acad Object (Block search for dblclick listbox)..
Dim Hyp As AcadHyperlink 'Add hyperlink to block..
Dim HypS As AcadHyperlinks 'Hyperlinks collection for block..

'********************************************
'************** INSERT BLOCK ****************
'********************************************
Private Sub insertmarkerBTN_Click()

' Check if all information is present..
If DetDesc1TXT.Text = "" Then
    MsgBox "Please enter the main Detail title..", vbExclamation, "ModelSpace Detail Marker.."
    Exit Sub
End If
' Check if all information is present..
If drawnumTXT.Text = "" Then
    MsgBox "Please enter the main Drawing Number (or select it from the list)..", vbExclamation, "ModelSpace Detail Marker.."
    Exit Sub
End If

ModelDetailRefFRM.Hide

ThisDrawing.ActiveSpace = acModelSpace

'Get pick point..
'Error Test for GetPoint method..
On Error Resume Next
TryAgainX:
blockPoint = ThisDrawing.Utility.GetPoint(, vbCr & "Pick the insertion point for the Detail Reference Marker.. ")

ErrHndlrX:
    If Err.Number <> 0 Then
        Err.Clear
        GoTo TryAgainX
    End If
    On Error GoTo ErrHndlrX

'Insert block..
    Set blockX = ThisDrawing.ModelSpace.InsertBlock(blockPoint, "X:\AbiCAD Blocks\General\Detail Reference - MSpace.dwg", 1#, 1#, 1#, 0)
    blockX.Layer = "X-Notes"

' Get and edit attributes..
attribZ = blockX.GetAttributes ' Get Block attributes..
' Loop through attributes..
For countx = LBound(attribZ) To UBound(attribZ)
    Select Case attribZ(countx).TagString
    Case "DRAWING_NUMBER"
        attribZ(countx).TextString = drawnumTXT.Text
    Case "DETAIL_NUMBER"
        attribZ(countx).TextString = detnumTXT.Text
    Case "DETAIL_DESC_1"
        attribZ(countx).TextString = DetDesc1TXT.Text
    Case "DETAIL_DESC_2"
        attribZ(countx).TextString = DetDesc2TXT.Text
    End Select
Next countx

[color=red]' Add the Hyperlink to the block to link back to the Layout..
Set HypS = blockX.Hyperlinks
' Add a new Hyperlink complete with all properties
Set Hyp = HypS.Add(LayoutLIST.Text)
Hyp.URL = "#," & layoutZ
Hyp.URLNamedLocation = "," & layoutZ[/color]
blockX.Update

ModelDetailRefFRM.Show
End Sub
'********************************************
'************** INSERT BLOCK ****************
'********************************************


Any ideas?

Cheers,

Paul
basepointdesignzltd..
P4 3.0Ghz / 2GB RAM..
XP Pro SP2..
Sapphire X1950 512MB Dual-DVi Graphics Card..
AutoCAD 2008.. 

Bryco

  • Water Moccasin
  • Posts: 1853
Re: Hyperlink (VBA) problems..
« Reply #1 on: February 08, 2008, 10:32:02 AM »
I haven't messed with hyperlinks, but it sure looks like you could do what you want with xdata.
Then use the doubleclick event to
1) Check for blockref
2) Check for the xdata
If so do the layout thang.

hardwired

  • Guest
Re: Hyperlink (VBA) problems..
« Reply #2 on: February 08, 2008, 10:55:24 AM »
Hi,

I don't want the user to really have to double-click the block to get it to work though, i just want it to insert the block (complete with hyperlink) - no messing..

It just seems to be missing some vital finisher to the code, as if you right click the block and open the hyperlink editor, then click ok without touching anything, the link will then work. Thats why i added the BlockX.Update code to see if that would ready the block..

All the internal help, online information and books just tell you how to add web-based urls, not layouts on the drawing..

Any ideas?

Bryco

  • Water Moccasin
  • Posts: 1853
Re: Hyperlink (VBA) problems..
« Reply #3 on: February 09, 2008, 12:24:05 PM »
While the help is lame on urls it does mention
Quote
If you specify a named view to jump to in an AutoCAD drawing, AutoCAD restores that view when the hyperlink is opened
So instead of using the layout, I made a paperspace view (I didn't realise there was such a thing) of each layout.
Since the view for "layout2" is called "2" the following code took me directly to the layout2
Set HypS = blockX.Hyperlinks
Set Hyp = HypS.Add(ThisDrawing.Name)
Hyp.URLNamedLocation = "2"

hardwired

  • Guest
Re: Hyperlink (VBA) problems..
« Reply #4 on: February 09, 2008, 07:12:11 PM »
Hi,

Thats great, thanks. That clears a few things up at least - will test it when i'm back at work..

Quick question(s) though? How are the layouts numbered? Are they numbered sequentially in the order that you create them or the left to right order that they're in in tab format the bottom of the screen? And how can i code it properly to find out the layout paperspace view reference numbers?

Thanks again, that has shed a bit more light on the subject..
 

Bryco

  • Water Moccasin
  • Posts: 1853
Re: Hyperlink (VBA) problems..
« Reply #5 on: February 10, 2008, 11:09:13 AM »
layouts have a taborder property that reflects the actual tab order.
However at run time you will have to check all the layouts for a view anyway.
If you use the layout.name  for the the view, there shouldn't be a problem.

hardwired

  • Guest
Re: Hyperlink (VBA) problems..
« Reply #6 on: February 11, 2008, 06:07:12 AM »
Hi,

Tried the TabOrder property, even checking layouts etc at run-time, and it still won't work - using the code you showed......

Code: [Select]
Set HypS = blockX.Hyperlinks
Set Hyp = HypS.Add(ThisDrawing.Name)
Hyp.URLNamedLocation = "2"

.......it was further away than my code, ie: the path field and url weren't properly filled in and the target address did not point to the layout. You said it worked for you but why not for me?

Bryco

  • Water Moccasin
  • Posts: 1853
Re: Hyperlink (VBA) problems..
« Reply #7 on: February 11, 2008, 09:28:03 AM »
Here is the code I used
Code: [Select]
Private Sub insertmarkerBTN_Click()

Dim blockX As AcadBlockReference 'Inserted block..
Dim blockPoint As Variant ' Pick point for block insert..
Dim HypS As AcadHyperlinks 'Hyperlinks collection for block..
Dim Hyp As AcadHyperlink

ThisDrawing.ActiveSpace = acModelSpace
blockPoint = ThisDrawing.Utility.GetPoint(, vbCr & "Pick the insertion point for the Detail Reference Marker.. ")
Set blockX = ThisDrawing.ModelSpace.InsertBlock(blockPoint, "ScaledFrame", 1#, 1#, 1#, 0)

Set HypS = blockX.Hyperlinks
Set Hyp = HypS.Add(ThisDrawing.Name)
Hyp.URLNamedLocation = "2"

Dim V As AcadView
Dim L As AcadLayout
Dim i As Integer
For Each L In ThisDrawing.Layouts
    If Not UCase(L.Name) = "MODEL" Then
        i = i + 1
        ThisDrawing.ActiveLayout = L
        Set V = ThisDrawing.Views.Add(i)
        V.LayoutId = L.ObjectID
    End If
Next

End Sub
And the  hyperlink in the drawing kicks you into layout2
Added-It seems you have to run the code once for the hyperlink to get the correct thisdrawing.name
« Last Edit: February 11, 2008, 09:34:10 AM by Bryco »

hardwired

  • Guest
Re: Hyperlink (VBA) problems..
« Reply #8 on: February 20, 2008, 05:13:54 AM »
Hi,

Thanks again Bryco. For me though, that code won't work. It does insert the block and add a hyperlink - but:
A: The hyperlink won't work ('Hyperlink Destination not recognised' or something like that) and...
B: It jumps straight to layout2, which i don't want it to - just a hyperlink set in the block which the user can use at a later stage..

Its frustrating, because my program is 99.999999% there, just can't issue it as it won't work 100%. It adds the hyperlink and all looks like it should, but it opens up a Windows Explorer to the drawing path. You go into the Hyperlink editor and everything seems fine, click ok and mysteriously the link workes after that - so why won't it work without opening up the editor and having to OK it?

Cheers,

Paul
basepointdesignzltd..
P4 3.0Ghz / 2GB RAM..
XP Pro SP2..
Sapphire X1950 512MB Dual-DVi Graphics Card..
AutoCAD 2008.. 

Bryco

  • Water Moccasin
  • Posts: 1853
Re: Hyperlink (VBA) problems..
« Reply #9 on: February 20, 2008, 10:00:49 AM »
The reason it jumps to layout 2
Code: [Select]
Since the view for "layout2" is called "2" the following code took me directly to the layout2
It worked for me and there is enough info in there for you to extrapolate that code to work for you.
I don't  think this method is going to give you a 100%, it's a bit dicey.
The xdata method and a rightclick or doubleclick event is probably better.