Add links by VBA

Hi!

I am trying to create a script to add links to PDFs. For an example 2000 borehole elements that I want to add a link to.

I have recorded doing it manually and then cleaned up the code. My problem is it stops during the scipt...

Sub LinkToElement()

'Script scans elements

'For each element find a value in a excelfile PDF path etc

'Fix/sort the found values so that I can add it in the "CadInputQueue.SendKeyin Links Add Element ID ""Test.dgn"" 12345" below. Do not show that in the example below. Keep it simple :)

Part 1 

Dim modalHandler As New Macro1ModalHandler
    AddModalDialogEventsHandler modalHandler

     CadInputQueue.SendKeyin "Links Add Element ID ""Test.dgn"" 12345"

RemoveModalDialogEventsHandler modalHandler

CommandState.StartDefaultCommand

End Sub

The CadInputqueue tells what element that should have the link.

Part 2

Implements IModalDialogEvents
Private Sub IModalDialogEvents_OnDialogClosed(ByVal DialogBoxName As String, ByVal DialogResult As MsdDialogBoxResult)

End Sub

Private Sub IModalDialogEvents_OnDialogOpened(ByVal DialogBoxName As String, DialogResult As MsdDialogBoxResult)

    If DialogBoxName = "Create Links" Then

        DialogResult = msdDialogBoxResultCancel

    End If  ' Create Links

End Sub

My Macro1ModalHandler never continues when the "Create Links" toolbox open. Even if I only add DialogResult = msdDialogBoxResultCancel as a test in the Macro1ModalHandler it doesen't work. So it seems like the "Creat Links" box is in some kind of a modalmode and it stops the script from continuing.

Part 1 works if i choose the PDF manually. Then it adds the link on the element perfectly. It is my Macro1ModalHandler that I have trouble with...

Is there a work around?

Is there a keyin that directly add a link? Something like: Links Add Element ID ""Test.dgn"" 12345 C:\Users\*****\Desktop\PDF\T636.PDF

I only want to create link to a file. Not KeyIn or URL.

Thanks!

Parents
  • HI Björn,

    if you will search for this topic, you will receive quite a lot of results, which demonstrates this topic is not very simple, because key-ins are not published.

    In my opinon the simplest solution is to add elements to selection set (you can use any proper method) and to use key-in

    ELEMENT CREATE LINK FILE <file>

    It will attach specified file to all selected elements.

    You should be aware of:

    • It attaches the same set of files to all selected elements.
    • If spaces exist in the file path, the path has to be enclosed in quotations: ELEMENT CREATE LINK FILE "C:\my folder\my file.pdf"
    • It's possible to attach more files at once: ELEMENT CREATE LINK FILE "C:\my folder 1\my file 1.pdf" "D:\my folder 2\my file 2.pdf"

    With regards,

      Jan

Reply
  • HI Björn,

    if you will search for this topic, you will receive quite a lot of results, which demonstrates this topic is not very simple, because key-ins are not published.

    In my opinon the simplest solution is to add elements to selection set (you can use any proper method) and to use key-in

    ELEMENT CREATE LINK FILE <file>

    It will attach specified file to all selected elements.

    You should be aware of:

    • It attaches the same set of files to all selected elements.
    • If spaces exist in the file path, the path has to be enclosed in quotations: ELEMENT CREATE LINK FILE "C:\my folder\my file.pdf"
    • It's possible to attach more files at once: ELEMENT CREATE LINK FILE "C:\my folder 1\my file 1.pdf" "D:\my folder 2\my file 2.pdf"

    With regards,

      Jan

Children