Author Topic: Hyper-linked files re-visited  (Read 5106 times)

0 Members and 1 Guest are viewing this topic.

krampaul82

  • Guest
Hyper-linked files re-visited
« on: June 24, 2009, 02:52:30 PM »
Code: [Select]
'---------------------------------------------------------------------------------------
' Module    : Module_get_hyperlink_cut_sheets
' DateTime  : 5/01/2009 13:21
' Author    : Mark
' Purpose   : The Program will sort through the current drawings model space blocks
'           : and find any associated hyperlinks to a PDF Cut Sheet and move that cut
'           : sheet to the PATH v:\Current_Project\Cut Sheets\ Directory.
'---------------------------------------------------------------------------------------


Option Explicit

Public Sub Gartner_Get_Hyperlink_Main()
    Dim objBlock As AcadBlockReference
    Dim objEnt As AcadEntity
    Dim colHyps As AcadHyperlinks
    Dim fso As FileSystemObject
    
    
    Set fso = New FileSystemObject
    
    If Len(Dir(ThisDrawing.Path & "\Cut Sheets\*.pdf")) <> 0 Then
    ' Checks to see if there are any PDFs in CURRENT_Project\Cut Sheets\
        fso.DeleteFile ThisDrawing.Path & "\Cut Sheets\*.pdf", True
        ' If there are, delete them
    End If
    
    For Each objEnt In ThisDrawing.ModelSpace
        If TypeOf objEnt Is AcadBlockReference Then
            Set objBlock = objEnt
            Set colHyps = objBlock.Hyperlinks
            On Error Resume Next
            ' In case we encounter any blocks that DON'T have hyperlinks
            fso.CopyFile colHyps.Item(0).URL, ThisDrawing.Path & "\Cut Sheets\*.pdf", True
           ' The TRUE option will automatically overwrite any existing files with the same name
        End If
    Next objEnt
    
    Set fso = Nothing
End Sub
This code is not working, Matt W has helped me thus far but has seemed to have lost interest.... is it the way that I attach a hyperlink?
(done thru the block editor) any help would be greatly appreciated!  I do not have a good enough grasp of VBA to know where this is failing...
  :-(
« Last Edit: June 24, 2009, 04:24:27 PM by CmdrDuh »

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Hyper-linked files re-visited
« Reply #1 on: June 24, 2009, 03:43:33 PM »
This code is not working, Matt W has helped me thus far but has seemed to have lost interest.... is it the way that I attach a hyperlink?
Trying to throw me under the bus, huh?   :wink:

And yes, it appears that it won't read the hyperlink when you attach it in the block editor.


Change this line...
Code: [Select]
fso.CopyFile colHyps.Item(0).URL, ThisDrawing.Path & "\Cut Sheets\*.pdf", True
...to this.
Code: [Select]
fso.CopyFile colHyps.Item(0).URL, ThisDrawing.Path & "\Cut Sheets\", True
« Last Edit: June 24, 2009, 03:46:36 PM by Matt W »
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

krampaul82

  • Guest
Re: Hyper-linked files re-visited
« Reply #2 on: June 24, 2009, 04:24:40 PM »
Matt,
Please do not think i was taking a shot at you and throwing you under the bus, Just assumed you were tired of my ignorance and was on to bigger and better things.
next question, I have over 500 blocks with hyperlinks attached through the block editor Arggghhh...  :x is there a way to automate the hyper link process without having to go through and re-attach a hyper-link through properties for each and every one?
Mark


David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Hyper-linked files re-visited
« Reply #3 on: June 24, 2009, 04:25:14 PM »
I added code tags to your post to make it more readable
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Hyper-linked files re-visited
« Reply #4 on: June 24, 2009, 04:50:14 PM »
...is there a way to automate the hyper link process without having to go through and re-attach a hyper-link through properties for each and every one?
Possibly, but not that I'm aware of.   :|
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

krampaul82

  • Guest
Re: Hyper-linked files re-visited
« Reply #5 on: June 24, 2009, 04:58:49 PM »
...is there a way to automate the hyper link process without having to go through and re-attach a hyper-link through properties for each and every one?
Possibly, but not that I'm aware of.   :|

Matt
Thank You for your time.  It does not generate a cut sheet attaching it through properties either.  This would of been a HUGE time saver! Sigh... :|
Mark

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Hyper-linked files re-visited
« Reply #6 on: June 25, 2009, 08:20:10 AM »
...is there a way to automate the hyper link process without having to go through and re-attach a hyper-link through properties for each and every one?
Possibly, but not that I'm aware of.   :|

Matt
Thank You for your time.  It does not generate a cut sheet attaching it through properties either.  This would of been a HUGE time saver! Sigh... :|
Mark

It does for me.

Try commenting out this line "On Error Resume Next" --- put the apostrophe (') in front of the line and see if/where it stops.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

krampaul82

  • Guest
Re: Hyper-linked files re-visited
« Reply #7 on: July 01, 2009, 12:43:18 PM »
It Stops here...

fso.CopyFile colHyps.Item(0).URL, ThisDrawing.Path & "\Cut Sheets\", True

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Hyper-linked files re-visited
« Reply #8 on: July 01, 2009, 02:32:35 PM »
Does the path exist?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

krampaul82

  • Guest
Re: Hyper-linked files re-visited
« Reply #9 on: July 02, 2009, 04:15:09 PM »
Yes. The current working.dwg is in a Directory that contains a Directory called Cut Sheets.

Glenn R

  • Guest
Re: Hyper-linked files re-visited
« Reply #10 on: July 06, 2009, 04:44:32 PM »
Do have you write access to the directory?

n.yuan

  • Bull Frog
  • Posts: 348
Re: Hyper-linked files re-visited
« Reply #11 on: July 08, 2009, 02:58:13 PM »
I see the obvious code errors, especially the error where your code breaks. See comments between lines of your code:

'---------------------------------------------------------------------------------------
' Module    : Module_get_hyperlink_cut_sheets
' DateTime  : 5/01/2009 13:21
' Author    : Mark
' Purpose   : The Program will sort through the current drawings model space blocks
'           : and find any associated hyperlinks to a PDF Cut Sheet and move that cut
'           : sheet to the PATH v:\Current_Project\Cut Sheets\ Directory.
'---------------------------------------------------------------------------------------


Option Explicit

Public Sub Gartner_Get_Hyperlink_Main()
    Dim objBlock As AcadBlockReference
    Dim objEnt As AcadEntity
    Dim colHyps As AcadHyperlinks
    Dim fso As FileSystemObject
   
   
    Set fso = New FileSystemObject
   

''Following "If...Then...End If" does not do what you intended (to delete all PDF file in a folder)
''The reason is you did not pass a valid file name to fso.DeleteFile() method: there is no file that can be
''named as "*.pdf". fso.DeleteFile() only delete one file at a time. It does not delete all files by accepting
''a wildcard file name pattern like *.pdf. You need to use repeatedly call Dir(path & "\*.pdf") to obtain each
''PDF file name and delete it one by one.


    If Len(Dir(ThisDrawing.Path & "\Cut Sheets\*.pdf")) <> 0 Then
    ' Checks to see if there are any PDFs in CURRENT_Project\Cut Sheets\
        fso.DeleteFile ThisDrawing.Path & "\Cut Sheets\*.pdf", True
        ' If there are, delete them
    End If
   
    For Each objEnt In ThisDrawing.ModelSpace
        If TypeOf objEnt Is AcadBlockReference Then
            Set objBlock = objEnt
            Set colHyps = objBlock.Hyperlinks

''This is typical worng use of "On Error Resume", which hide the error from you
''Since you did not make sure in code that you would definitely get an valid file name
''from the hyperlink's Url. Since the fso.Copy file could fail (and it did), you should handle
''possible error

            On Error Resume Next

            ' In case we encounter any blocks that DON'T have hyperlinks


''Assume you did get a valid file name froom the Url (you may add "Debug.Print colHyps.Item(0).URL"
''To verify you do have a good file name always) here, the second parameter passed to fso.FileCopy()
''method is definitely wrong: you cannot name the destination file as *.pdf. That is "*" is not allowed in
"file name. I guess what you really want to do is to just make a copy of the source file into the
''...\Cut Sheets\" folder with the same file name. So, you have to parse out the file name from the
''URL string and use it as destination file name with new folder path


            fso.CopyFile colHyps.Item(0).URL, ThisDrawing.Path & "\Cut Sheets\*.pdf", True
           ' The TRUE option will automatically overwrite any existing files with the same name
        End If
    Next objEnt
   
    Set fso = Nothing
End Sub


Another issue: it is strongly recommended you donot use FileSystemObject from MS Scripting Runtime. For simple file copy/delete, VB/A has built-in methods: FileCopy() and Kill(). Addiing unnecessary dependncy to your program is bad thing to do, not to mention there are different version of Scripting runtimes, depending on Windows OS versions, which may cause trouble to your program, especially the trouble is really easily avoidable.