OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 19-06-2003, 10:07
s_federici
Guest
 
Posts: n/a
Default "Unexpected condition" error message (with code)

I'm trying to export to a CDR file all the bitmap shapes belonging to a (group) shape selected by the user.

I tried different ways to extract and export all the bitmap shapes contained in a group, but all of them give raise to the same error message:



The error is in Italian. My best translation is:

"CorelDRAW11 Condition #5002-OBJECTUTILS-7432.
Unexpected conditions. Check for Techical Assistance in the Help"

I attached a zip file containing a very simplified version of my project and a CDR file. You can replicate the error condition by:

1. Opening the CDR file
2. Running the "ProcessDocument" macro
3. Pressing the "Start Selection" button
4. Clicking on the "black box" bitmap shape

Then, if you click on the "ok" button in the error dialog, everything seems to work fine. The problem is that I have to export all the bitmaps from very large documents...

Does someone have already seen this weird error message?

Thanks for any help
Stefano
Attached Files
File Type: zip Test_6.zip (83.3 KB, 841 views)
Reply With Quote
  #2  
Old 22-06-2003, 13:42
johndankey
Guest
 
Posts: n/a
Default

Stefano,

Is this version 11? My version 10 won't open your graphic.

johndankey
Reply With Quote
  #3  
Old 23-06-2003, 06:42
s_federici
Guest
 
Posts: n/a
Default

In fact I'm using CorelDRAW11. Please, try again using the new attanched files. This time I saved the cdr file as version 10. I personally get the same problem. I also realized that the gms file did contain some useless references that would prevent the macro to work on a computer with different references if not disabled.

Let me know how these new files work.

Stefano
Attached Files
File Type: zip Test6.1.zip (75.3 KB, 669 views)
Reply With Quote
  #4  
Old 23-06-2003, 10:05
johndankey
Guest
 
Posts: n/a
Default

Stefano,

I noticed three problems. One, your variables you used were private to seleziona_Click(), so ExportSelectedShape() could not use them. Two, your construction
Code:
Set shr = doc.Selection.Shapes.FindShapes(cdrBitmapShape, False)
is faulty, at least in version 10. Findshapes() can be referenced by Layers or by Page, not Shapes, so in 10, this works:
Code:
    Set shr = doc.ActiveLayer.FindShapes(, cdrBitmapShape, True)
but that doesn't use Selection. This uses Selection:
Code:
Set shr = doc.ActivePage.ActiveLayer.FindShapes(, cdrBitmapShape, True)
but now that I start using this, the error you received comes up. Hmm. Now I can't go back to the previous code & have that work. Even shutting down & restarting doesn't work.

What I would do (in ExportSelectedShape() ) is this: ungroup the group & search through it for those cdrBitmapShapes, instead of trying to use FindShapes(). There must be an error in the FindShapes() function.

johndankey
PS, the third one is that FindShapes() would have to be recursive ("True") in order to find your shapes. At least that's what (briefly) worked for me.
Reply With Quote
  #5  
Old 23-06-2003, 11:14
s_federici
Guest
 
Posts: n/a
Default

Hi John,
after a warm thanks for spending your time in trying to solve my weird problem

Quote:
your variables you used were private to seleziona_Click(), so ExportSelectedShape() could not use them.
I thought that a reference to the Selection object in ExportSelectedShape()didn't need the use of a public variable in seleziona_click(). But I'm very new to Corel VBA, so I guess I'm wrong.

Quote:
your construction
Code:
Set shr = doc.Selection.Shapes.FindShapes(cdrBitmapShape, False)
is faulty, at least in version 10. Findshapes() can be referenced by Layers or by Page, not Shapes, so in 10, this works:
Code:
    Set shr = doc.ActiveLayer.FindShapes(, cdrBitmapShape, True)
but that doesn't use Selection. This uses Selection:
Code:
Set shr = doc.ActivePage.ActiveLayer.FindShapes(, cdrBitmapShape, True)
Thanks for the clarification. But in the last line of your code I can't see any reference to the Selection object. I tried to modify your code to insert a reference to it, but neither ActivePage nor ActiveLayer allow me to do that.

Quote:
What I would do (in ExportSelectedShape() ) is this: ungroup the group & search through it for those cdrBitmapShapes, instead of trying to use FindShapes(). There must be an error in the FindShapes() function.
That was what I first tried. I wasn't using FindShapes(s) at start. The fact is that I must solve the following problem:

1. get a shape (or group of shapes)
2. get rid of every non-bitmap shape in it (if any; in my document I have (grouped) images grouped with their text description)
3. save the remaining shape(s) in a single CDR file.

To do this I'm using the SaveAs method in which the Range property of the StructSaveAsOptions object is set to cdrSelection as follows:

Code:
    
    Dim so As New StructSaveAsOptions
    
    With so
        .Range = cdrSelection
        .Filter = cdrCDR
        .Overwrite = True
    End With
    Call doc.SaveAs("myfile.cdr", so)
So, what I really need, is to be able to select all the non-bitmap shapes in a shape (or shape group). But every trick I tried so far doesn't bring me to the solution.

Any alternative coding is welcome

Ciao
Stefano
Reply With Quote
  #6  
Old 23-06-2003, 14:55
johndankey
Guest
 
Posts: n/a
Default

Stefano,

This seems to work for me:
Code:
Sub ExportSelectedShape(doc As Document)
    Dim shr As New ShapeRange
    Set sel = ActiveShape
    CorelScript.Ungroup
    For Each s In ActiveSelection.Shapes
        If (s.Type = cdrBitmapShape) Then
            shr.Add s
        End If
    Next s
    Call ExportBitmapShapes(doc, shr.Group)
End Sub
Perhaps the problem you encountered earlier is with the Shape.Ungroup object. For the life of me, I couldn't figure out how to reselect the objects after ungrouping, since Shape.Ungroup leaves the objects unselected. CorelScript.Ungroup, however, leaves them selected. If anyone out there could show us newbies how it's done, I'd appreciate it. Otherwise, Stefano, does this do the job you want it to?

jdk
Reply With Quote
  #7  
Old 24-06-2003, 06:18
s_federici
Guest
 
Posts: n/a
Default

Very well done John!!! Much much much better!!!!!

The "unexpected condition" error message is now completely gone. The difference between your solution and one of my attempts is that I was trying to use UnGroupAllEx to ungroup the selection and get a handle to the resulting ShapeRange. But this gave raise to the same error. Maybe there is a wrong interaction between the shapes obtained by UnGroupAllEx and the following Group methods I was using.

Now. My project is built in order to examine all the files in a given folder. I'm doing this with the following (simplified) routine:

Code:
Sub ProcessAllDocumentsFromFolder()
    Dim doc As Document
        
    MyPath = "C:"
    
    MyName = Dir(MyPath & "\*.cdr")
    Do While MyName <> ""
        If MyName <> "." And MyName <> ".." Then
            If (GetAttr(MyPath & "\" & MyName) And vbDirectory) <> vbDirectory Then
    
                fileName = MyPath & "\" & MyName
                Set doc = OpenDocument(fileName)
            
                Call ProcessDocument
                
                doc.Close
            End If
        End If
        
        MyName = Dir    ' find next file
    Loop
         
End Sub
The problem now is that after having processed 2 out of 4 files contained in the C:\ folder, when VBA comes for the second time to the line of code with the "find next file" comment (to open the theird document), I get the following error message:



My (best) translation is:

"Run-time error '5':
Routine call or argument not valid"

The weirdness is that this only happens the second time VBA processes this line of code. The second document is instead regularly open. And, weirdest of all, nothing happens if I simply run the sample.gms project by putting 3 copies of the same cdr file (the one I attached to my previous post). If no one knows about possible bugs of "Dir" (or different ways of cycling through the documents in a folder) and you are interested john I can put somewhere the 3 original documents (15-50MB each...).

Anyway, a round of applause and a bravo to you john, thanks a lot!

Stefano
Reply With Quote
  #8  
Old 24-06-2003, 09:57
johndankey
Guest
 
Posts: n/a
Default

Stefano,

You're quite welcome. I'm kinda wondering why the "heavy hitters" haven't weighed in on this one. Some of those guys could have solved it in 10 seconds with one line of code I would like to see another solution, should one exist.

With this problem, I'd really need to have the script. If you could post the script, and preferably slightly smaller files (I'm on dialup), I'll take a look. As it is, the only thing I can see is that maybe you need to add more to that Dir to find the next file. It says in the help file:
Quote:
To iterate over all files in a folder, specify an empty string:

Dir("")
johndankey
Reply With Quote
  #9  
Old 24-06-2003, 11:10
s_federici
Guest
 
Posts: n/a
Default

Ciao John,
you are right, the empty string will iterate over all files in a folder. Otherwise the first call will get a single file name matching the specified pathname. Then, as I pasted'n'copied from the VB sample for the Dir function, you are supposed to use Dir without arguments to get all other matching files. When all matching files have been retrieved, you get a zero length file name. At least this is what I understood from the Italian help (the only I have available. Generally any badly written original help in English is always better than any Italian translation). This is the Italian version:

Quote:

Sintassi

Dir[(nomepercorso[, attributi])]

Dir restituisce il primo nome di file che corrisponde a quello specificato in nomepercorso. Per ottenere i successivi nomi di file corrispondenti a nomepercorso, chiamare di nuovo la funzione Dir senza alcun argomento. Se non vengono trovati altri nomi di file corrispondenti, Dir restituirà una stringa di lunghezza zero, dopodiché sarà necessario utilizzare di nuovo nomepercorso nelle successive chiamate, altrimenti verrà generato un errore.
My traslation follows:

Quote:
Sintax
Dir[(pathname[,attributes])]

Dir returns the first file name that matches the one specified in pathname. To get all other file names that match pathname, call again the Dir function with no argument. When no other matching file names are found, Dir will return a zero length string. After that you will have to use again pathname, otherwise an error will be generated.
And in my cycle-through-files routine I check for the empty file name, so...

I'll try generating some lighter files that give raise to the same error. I don't want your connection to get fire :wink:

talk to you soon
Stefano
Reply With Quote
  #10  
Old 25-06-2003, 05:33
s_federici
Guest
 
Posts: n/a
Default

I have solved the last problem.
I'm not saying that I understood why Dir doesn't work as expected (or at least as I would expect it to work), but I found an alternative way of iterating through all the CDR files of a folder that does not give raise to errors of any sort.

This is the new cycle-through-files routine:

Code:
    Dim FSO As FileSystemObject
    Dim myFolder As Folder
    Dim myFile As File
    
    MyPath = "C:\CDR VBA test"
    Set FSO = New FileSystemObject
    Set myFolder = FSO.GetFolder(MyPath)
    For Each myFile In myFolder.Files
        
        If InStr(myFile.Name, ".cdr") Then
            Set doc = OpenDocument(myFile.Path)
            Call ProcessDocument
            
            doc.Close
        End If
    Next
    Set myFolder = Nothing
    Set myFile = Nothing
    Set FSO = Nothing
    Exit Sub
As I didn't find a real answer to the problem I'm not sure that my project will work 100% of the time... so if someone else would like to step in...

Stefano
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
Simple Bar code generator Webster Code Critique 2 06-09-2010 02:41
HOW-TO call coreldraw12 find dialog from VBA code???? wOxxOm CorelDRAW/Corel DESIGNER VBA 4 02-03-2008 09:32
Text ENCODE Craig Tucker CorelDRAW/Corel DESIGNER VBA 10 26-01-2005 14:59
How to use events from CorelDRAW.Document in my code? me CorelDRAW/Corel DESIGNER VBA 2 30-10-2004 03:49
Generic code to process all shapes in a document glennwilton CorelDRAW/Corel DESIGNER VBA 0 05-09-2003 04:13


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


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