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 30-06-2008, 05:43
mitchellhu mitchellhu is offline
Junior Member
 
Join Date: Nov 2007
Posts: 17
Red face OLE oject and object tab order problem?

I write a small Delphi program to chek out is there any ole shape in a .cdr file.
I found two strnage problem:

first:
CDRX3 treats ole objects in two different ways. If the OLE object is created by CDRX3, it can be added to shaperange object. But, if it was an linked OLE shape that form outside world, it can't not be added in shaperange object. Eventhought, both shape.type= 12(cdrOLEobjectShape). Why?

second:
How to get each shape's tab order.
Each time, I finished my program. I found, those OLE objects(from outside world) was lost it origional tab order, There were behind another shpae. Before running my cheking program, There were all over another shpape
Why?

refer to picture, I hope you understand what I mean;(my English ability is poor)

1.befor checking:
http://www.flickr.com/photos/21630468@N08/2624532634/
2.after checking:
http://www.flickr.com/photos/21630468@N08/2623707837/
Thanks
Attached Files
File Type: cdr beforchecking.cdr (16.0 KB, 18 views)
File Type: cdr after checking.cdr (16.1 KB, 11 views)

Last edited by mitchellhu; 30-06-2008 at 05:50.
Reply With Quote
  #2  
Old 30-06-2008, 21:09
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
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 Played...

I played with this a bit and could not replicate the problem. What are you doing to the OLE Objects? If you are copying them or converting them I could see the Z-Order changing, but just looping them.....

In CorelDRAW X4 I updated some older code that was posted. Someone might find it useful.
Code:
Sub OLEtoShapes()
    Dim s As Shape, sCopy As Shape
    Dim srOLEShapes As ShapeRange, l As Layer
    Dim x As Double, y As Double, w As Double, h As Double
    
    Set srOLEShapes = ActivePage.Shapes.FindShapes(Type:=cdrOLEObjectShape) 'Get all the OLE Objects
    If srOLEShapes.Count = 0 Then MsgBox "No OLE Objects found", , "OLEtoCurves": Exit Sub

    'Start the Undo Group.
    ActiveDocument.BeginCommandGroup "Convert OLE to Shapes"
    'If error goto error handler so undo stack is not currupted.
    On Error GoTo ErrHandler

    'Loop through each OLE Object and convert to curves
    For Each s In srOLEShapes
        s.GetBoundingBox x, y, w, h
        Set l = s.Layer ' Get the layer the OLE object is on
        s.Copy 'Copy the OLE Object
        l.PasteSpecial "Metafile" 'Paste OLE object as Metafile
        Set sCopy = ActiveShape 'Get our new Metafile shape
        sCopy.SetBoundingBox x, y, w, h
        sCopy.OrderFrontOf s 'Place in the proper Z-Order
    Next s
    
    srOLEShapes.Delete ' Delete all the OLE Objects
    
'Ends the undo command group and refreshes the application.
ExitSub:
    ActiveDocument.EndCommandGroup
    Exit Sub

'Displays message if there was an error.
ErrHandler:
    MsgBox "Error occured: " & Err.Description
    Resume ExitSub
End Sub
-Shelby
Reply With Quote
  #3  
Old 30-06-2008, 23:59
mitchellhu mitchellhu is offline
Junior Member
 
Join Date: Nov 2007
Posts: 17
Default

Shelby thanks.
My program is for a client who is a pulisher.
He lists a lot of checking rules for .cdr file printing.
One of thoes rules is finding out OLE shpaes and show a message to user.
Form a lot sample .cdr files, I for CDRX3 ShpeRange object can not find some kind of OLE shpes( in my last post attachment, you coud find it).
In code:
if a cdr.file has this kind OLE shapes
Shapes := acitvedoc.ActiveLayer.FindShapes();
Shapes did find this kind shapes.

only way to let Shapes add thoes shapes is use a loop to find all ole objects as belowsorry, it is a delphi code!)

olecount :integer;
oleshape :shape;
oleshaperange: shaperange;

olecount := bsCDLayer.shapes.count;
for ocount := 1 to olecount do
begin
oleshape := bsCDLayer.shapes[ocount];
oleshape.createselection;
oletype := oleshape.type;
if oletype = 12 then //判斷各shpae.type是為12(oleojbect)
begin
showmessage('oleshpe['+inttostr(ocount)+'].type='+inttostr(oletype));
oleshaperange.add(oleshape);
end;
end

then after process all checking rules, those OLE object lost it's oringal stacking order. So, you will find all OLE objects are in bottom. Means picture is different ,now!

This morning, I have an idea, In loop, while finding ole objct then record the shpe (behind/in front of ole object). After all checking process then let ole objec set order behind/in forn of the shpe I recored.
I don't know it will work nor not?
I would test this iead latter.
Hope it will work.
Reply With Quote
  #4  
Old 01-07-2008, 14:16
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
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 Another try...

I have now tested this in 12, X3 and X4 all with the same results. I used your first file: beforechecking.cdr and ran the following code:
Code:
Sub TestOLE()
    Dim s As Shape
    Dim sr As ShapeRange
    Dim strResult As String
    
    Set sr = ActiveDocument.ActivePage.Shapes.FindShapes()
    
    For Each s In sr
        strResult = strResult & "id: " & s.StaticID & ", type: " & s.Type & Chr(13)
    Next s
    
    MsgBox strResult
End Sub
Each time all 8 shapes are displayed with the correct ID's and Types. The z-order is not changed and everything is as expect. I have attached a screenshot of the X4 results, but again they were the exact same for 12 and X3.

Maybe it is a Delphi thing, you might want to try your code in VBA first.

-Shelby
Attached Images
 
Reply With Quote
  #5  
Old 01-07-2008, 22:08
mitchellhu mitchellhu is offline
Junior Member
 
Join Date: Nov 2007
Posts: 17
Default

Shelby, thanks a lot again.
You are right.
It's a Delphi problem.
Maybe, it is a COM iterface problem( for C, C#, Delphi........)

Any way, you do me a lot of favior, thanks.
Reply With Quote
  #6  
Old 13-07-2008, 20:55
mitchellhu mitchellhu is offline
Junior Member
 
Join Date: Nov 2007
Posts: 17
Default

Finally, Delphi findshapes() function problem solved.
According to CdrX3 type libray, findshpaes() has many options, such as Name, Type, Index....
Always, we think findshapes()(no option) can find all sahpes at a shaprang, layer.... But, it does not work in Delphi ( for Embeddin shapes). In VBA it works well.
So, gives a ' '(blank string, Name option) to findshape(''), In Delphi code,it works(no stacking order broken problem) as well as VBA does.
Normally, Cdrx3 creates all shape with a blnak Name,
So, findshape('') can find all shpes( inculde Embedding shpes).
Ojbect's overload/orverride , that's why. I think so.

Thanks all and Selbym
Mitchell Hu

Last edited by mitchellhu; 14-07-2008 at 04:38.
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
Color.UserAssignEx with Tab,Esc,Enter handling wOxxOm CorelDRAW/Corel DESIGNER VBA 0 12-12-2007 19:14
OLE Error Craig Tucker CorelDRAW/Corel DESIGNER VBA 2 21-09-2004 12:44
stack order 2 Michael Cervantes CorelDRAW/Corel DESIGNER VBA 3 15-06-2004 06:58
stack order Michael Cervantes CorelDRAW/Corel DESIGNER VBA 2 20-05-2004 00:32
COM/OLE Automation Gerry Hickman Corel Photo-Paint VBA 2 02-01-2004 18:31


All times are GMT -5. The time now is 10:35.


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