OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > Code Critique

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 15-06-2007, 19:37
Jeff Harrison
Guest
 
Posts: n/a
Default update all external linked bitmaps in entire document

Hi All,

I tried recording a macro to do this - nothing useful appears, and this has always been the case when recording macros FME. :-(

Then I looked through Os's Code to Re-import linked bitmaps at 100%, and added UpdateLink instead of Import. This didn't work... plus there's extra stuff I don't need here to simply update all links in entire document.

Next , I tried using the "code tag pair" in 3 ways, none work for me. All are shown here. What do I really need to type?

Code:
Sub loadSourceBitmap()
   Dim sr As ShapeRange, sh As Shape, lsr As New ShapeRange, errs$, cnt&, d11#, d12#, d21#, d22#, tx#, ty#
   On Error Resume Next
   Set sr = ActiveSelection.Shapes.FindShapes(, cdrBitmapShape)
   If sr.Count = 0 Then Set sr = ActivePage.FindShapes(, cdrBitmapShape)
   If sr.Count = 0 Then MsgBox "No images " + IIf(ActiveShape Is Nothing, "on this page", "in selection"): Exit Sub
   For Each sh In sr
      If sh.Bitmap.LinkFileName <> "" Then lsr.Add sh
      Next
   If lsr.Count = 0 Then MsgBox "No linked images " + IIf(ActiveShape Is Nothing, "on this page", "in selection"): Exit Sub
   ActiveDocument.BeginCommandGroup "Import fullres images"
   For Each sh In lsr
      Err.Clear: FileSystem.GetAttr sh.Bitmap.LinkFileName
      If Err.Number Then
         errs = errs + sh.Bitmap.LinkFileName + vbCr
      Else
         cnt = ActiveLayer.Shapes.Count
         ActiveLayer.UpdateLink sh.Bitmap.LinkFileName
         If cnt <> ActiveLayer.Shapes.Count Then
            ActiveShape.SetPosition sh.PositionX, sh.PositionY
            sh.GetMatrix d11, d12, d21, d22, tx, ty
            ActiveShape.SetMatrix d11, d12, d21, d22, tx, ty
         End If
      End If
   Next
   ActiveDocument.EndCommandGroup
   End Sub

Last edited by shelbym; 15-06-2007 at 22:09. Reason: Fixed Code Tag
Reply With Quote
  #2  
Old 15-06-2007, 22:10
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Code Tag

I fixed the code tag for you. You can find examples here:

http://forum.oberonplace.com/misc.php?do=bbcode

Hope that helps now to look at your code,

Shelby
Reply With Quote
  #3  
Old 15-06-2007, 22:59
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Not 100% sure

I am still not 100% sure what you are trying to do, but here what I have. Basically it just updates the link so you have the current version, then breaks the link bringing in the full res version into the document.

Code:
Sub LoadSourceBitmaps()
    Dim s As Shape
    Dim sr As ShapeRange
    
    Set sr = ActiveSelection.Shapes.FindShapes(, cdrBitmapShape)
    If sr.Count = 0 Then Set sr = ActivePage.FindShapes(, cdrBitmapShape)
    If sr.Count = 0 Then MsgBox "No images " + IIf(ActiveShape Is Nothing, "on this page", "in selection"): Exit Sub
    
    For Each s In sr
        If s.Bitmap.ExternallyLinked = True Then
            s.Bitmap.UpdateLink
            s.Bitmap.ResolveLink
        End If
    Next s
End Sub
Reply With Quote
  #4  
Old 16-06-2007, 00:12
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Well getting close

OK if you ask me this should do what you want. Only problem is it doesn't. At least on my pc. (I need to check service packs and will let you know what version I am running)

The problem is the s.Bitmap.ExternalLinkTime report the incorrect time. If have edited the bitmap today and linked it, it is actually in the future. Odd. More to come as I do some digging.

Code:
Sub FixOutdatedLinkedBitmaps()
    Dim s As Shape
    Dim sr As ShapeRange
    Dim p As Page
    
    'Find all outdated linked bitmaps
    For Each p In ActiveDocument.Pages
        p.Activate
        Set sr = p.Shapes.FindShapes(, cdrBitmapShape, True)
        For Each s In sr
            If s.Bitmap.ExternallyLinked = True Then
                If DateDiff("s", FileDateTime(s.Bitmap.LinkFileName), s.Bitmap.ExternalLinkTime) <> 0 Then
                    s.Bitmap.UpdateLink
                End If
            End If
        Next s
    Next p
End Sub
Reply With Quote
  #5  
Old 16-06-2007, 03:18
Jeff Harrison
Guest
 
Posts: n/a
Default This works OK

Hi Shelby,

Thanks for your time :-) I was was getting frustrated.

the code below works OK for me after some small mods.

I took out the date stuff since there is already some native code in Draw that seems to compare between the preview bitmap and the real one.

The reason I put that concept in my email to you was because there might be a way for Draw to "auto-check" for changes once in a while. No worries, if not, the macro works well as is. Might freak people out if Draw is going off on a tangent every five minutes updating through a timer.

I add the optimization thing. Hopefully in right places.

I couldn't find the refresh link list function in VBA to put in at the end of the processing though. So the list still shows wrong thumbnails after processing, but Draw's page is good. (until refresh list is pressed)

Code:
Sub FixOutdatedLinkedBitmaps()
    Dim s As Shape
    Dim sr As ShapeRange
    Dim p As Page
    
    'Find all outdated linked bitmaps
    For Each p In ActiveDocument.Pages
        p.Activate
        Set sr = p.Shapes.FindShapes(, cdrBitmapShape, True)
        For Each s In sr
            If s.Bitmap.ExternallyLinked = True Then
                    s.Bitmap.UpdateLink
            End If
            Optimization = True
        Next s
    Next p
    Optimization = False
End Sub
Attached Images
 

Last edited by Jeff Harrison; 16-06-2007 at 03:29.
Reply With Quote
  #6  
Old 16-06-2007, 09:29
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Well at least we are close...

Well hopefully we have gotten close. I don't know why the thumbnail bitmaps don't refresh, and you are right I don't see a call for it. Anyway here is what my final code would look like.

Code:
Sub FixOutdatedLinkedBitmaps()
    Dim s As Shape
    Dim sr As ShapeRange
    Dim p As Page

    Optimization = True
    
    For Each p In ActiveDocument.Pages
        p.Activate
        Set sr = p.Shapes.FindShapes(, cdrBitmapShape, True)
        For Each s In sr
            If s.Bitmap.ExternallyLinked = True Then
                    s.Bitmap.UpdateLink
            End If
        Next s
    Next p
    
    Optimization = False
    Application.Refresh
    ActiveWindow.Refresh
End Sub
Reply With Quote
  #7  
Old 17-06-2007, 00:10
Jeff Harrison
Guest
 
Posts: n/a
Default Looks good

Hi Shelby,

This is good. Thanks for your work!

Speeds up process of making sure linked images on page resemble the real ones that will print, without having to go to the link docker at all.

I tried recording in Corelscript in Draw ver 9 to see if the refresh command would appear that way, but nope.

FYI, it's possible to use Photoshop files as linked documents. I prefer PP myself, but some like PS. They open in PS with the "open link with associated application" button in link docker.

But... the "open link with associated application" icon in link docker doesn't seem to have VBA command either. Only way to launch PS is through link docker, not a toolbar button or hotkey. Oh well.

Thanks Again,

Jeff
Reply With Quote
  #8  
Old 17-06-2007, 08:54
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

activeshape.OLE.Edit - should invoke associated editor
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help on external linked bitmaps desparatly needed! lukasdesign General 8 16-06-2007 03:55
Change styles throughout entire document Ruffus General 0 12-12-2005 19:58
Bitmaps externally linked... meandirtyjoe CorelDRAW/Corel DESIGNER VBA 4 19-10-2004 12:46
Active document issues.. wbochar CorelDRAW/Corel DESIGNER VBA 2 19-03-2003 15:15


All times are GMT -5. The time now is 00:05.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com