![]() |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
Stefano,
Is this version 11? My version 10 won't open your graphic. johndankey |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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) Code:
Set shr = doc.ActiveLayer.FindShapes(, cdrBitmapShape, True) Code:
Set shr = doc.ActivePage.ActiveLayer.FindShapes(, cdrBitmapShape, True) 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. |
|
#5
|
|||
|
|||
|
Hi John,
after a warm thanks for spending your time in trying to solve my weird problem Quote:
Quote:
Quote:
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)
Any alternative coding is welcome Ciao Stefano |
|
#6
|
|||
|
|||
|
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
jdk |
|
#7
|
|||
|
|||
|
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
![]() 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 |
|
#8
|
|||
|
|||
|
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:
|
|
#9
|
|||
|
|||
|
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:
Quote:
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 |
|
#10
|
|||
|
|||
|
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
Stefano |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Simple Bar code generator | Webster | Code Critique | 2 | 06-09-2010 01:41 |
| HOW-TO call coreldraw12 find dialog from VBA code???? | wOxxOm | CorelDRAW/Corel DESIGNER VBA | 4 | 02-03-2008 08:32 |
| Text ENCODE | Craig Tucker | CorelDRAW/Corel DESIGNER VBA | 10 | 26-01-2005 13:59 |
| How to use events from CorelDRAW.Document in my code? | me | CorelDRAW/Corel DESIGNER VBA | 2 | 30-10-2004 02:49 |
| Generic code to process all shapes in a document | glennwilton | CorelDRAW/Corel DESIGNER VBA | 0 | 05-09-2003 03:13 |