OberonPlace.com Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 27-03-2006, 02:33
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
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 Select Object and VirtualShape

I wanted to try and use the new virtualshape in CorelDRAW X3 to basically store my original outline settings so that I could restore them after I made a couple changes to easily show a selection to a user (turning the outline thick, dotted and red). The problem I have run into is I see both shapes, if my original shape has a thick outline then I don't see my outline changes at all they seem to be covered by the virtualshape. Any help or comments would be great. Here is a little sample code of what I am trying to do:
Code:
Sub SelectObject()

Dim Response
Dim retval As Long, shift As Long
Dim x As Double, y As Double
Dim sel As Shape, selShape As Shape, sOrig As Shape
        
MsgBox "No selection was found, Please click OK, then select a shape", , "Select Objects"

Do While Response <> vbYes
    retval = ActiveDocument.GetUserClick(x, y, shift, 100, False, cdrCursorWinArrow)
    Set sel = ActiveDocument.ActivePage.SelectShapesAtPoint(x, y, False)
    If sel.Shapes.Count > 0 Then
        Set selShape = sel.Shapes(1)
        Set sOrig = selShape.TreeNode.GetCopy().VirtualShape
        sel.Outline.SetProperties 0.125, OutlineStyles(4), CreateCMYKColor(0, 100, 100, 0)
        Response = MsgBox("Is the dotted red object the shape you wanted to select?", vbYesNo, "Select Objects")
        If Response = vbYes Then
            selShape.ReplaceWith sOrig
        Else
            ActiveDocument.ClearSelection
            selShape.ReplaceWith sOrig
            MsgBox "Please click OK and try again to select the shape", , "Select Objects"
        End If
    End If
Loop

End Sub
Thanks,

Shelby

Last edited by shelbym; 27-03-2006 at 02:53.
Reply With Quote
  #2  
Old 29-03-2006, 10:20
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Shelby,

Unfortunately I don't think you can use it this way. All virtual shapes give you is quick transaction-less changes to the objects. When you create a virtual shape, the whole process doesn't log any undo transactions and thus it is much faster. Also many commands applied to virtual shapes do not log any transactions as well (moving, stretching objects, changing fills/outlines, etc).

However having said that, you must be extremely careful when using these, since CorelDRAW has a lot of assumptions on what the state of the application should be at any given point. If you change the state without informing the transaction manager of the change at some point, this could destabilize the application and lead to all sorts of things, even crashes.

Normally the typical workflow of using virtual shapes would be:

Workflow A - tempoarary objects:
1. Create virtual shape
2. Change some properties
3. Get some data (like size of the resulting object, or whatever)
4. Delete the shape

Workflow B - creating objects quickly:
1. Create virtual shape
2. Change size, rotate, apply fill/outline
3. Call Document.LogCreateShape to log the real shape creation transaction for undo purposes

Workflow C - editing existing objects:
1. Make a copy of existing object (Shape.TreeNode.GetCopy().VirtualShape)
2. Edit the copy (stretch/rotate, change fill/outline)
3. Call OriginalObject.ReplaceWith(virtualShapeCopy) to log the actual transaction.

Anything else could result in potential problems.
Reply With Quote
  #3  
Old 17-02-2009, 14:16
Joe Joe is offline
Member
 
Join Date: Nov 2008
Location: Latvia
Posts: 92
Send a message via Skype™ to Joe
Default

Sorry for bumping such an old topic, but a relevant question has popped up.

I finally managed to semi-understand the VS tech and all of a sudden certain parts of the code got 200 TIMES faster (For example creating and distributing 2500 objects in 0.17 seconds or so). Way cool!

However I still have no idea how to create a Virtual Shape directly, without using the .GetCopy method. Currently my code looks like this:

Code:
Set MakeShape = ActiveLayer.CreateRectangle2(0, 0, 1, 1)

For Each Current In MakeShapeRange
    If Current.SizeWidth - Pad * 2 > 0 And Current.SizeHeight - Pad * 2 > 0 Then
        With MakeShape.TreeNode.GetCopy
            .VirtualShape.SetBoundingBox Current.LeftX + Pad, Current.BottomY + Pad, Current.SizeWidth - Pad * 2, Current.SizeHeight - Pad * 2
            .LinkAsChildOf MakeShape.Layer.TreeNode
            MakeShapeRange.Add .VirtualShape
        End With
    End If
Next Current

MakeShape.Delete

ActiveDocument.LogCreateShapeRange MakeShapeRange
As you see a Temp shape is created which I then copy as a Virtual Shape and do all the nice fast things with. Then the shape gets deleted.

This seems cumbersome. As another problem if this gets Undo-ed the original shapes (presented as "Current" in the code above) disappear.

So basically the question is how to properly create stand-alone Virtual Shapes, as mentioned in Alex's Workflow B example. Thanks in advance for any help.
Reply With Quote
  #4  
Old 17-02-2009, 16:39
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

You need to use ActiveVirtualLayer to create objects:

Code:
Dim s As Shape
Set s = ActiveVirtualLayer.CreateRectangle2(0, 0, 1, 1)
' do all the modifications to the shape here
ActiveDocument.LogCreateShape s
Reply With Quote
  #5  
Old 17-02-2009, 17:20
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
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 Once again....

Alex's beats me to the answer, but I will post mine also:
Code:
Sub CreateVirtualShape()
    Dim sVirtual As Shape
    
    Set sVirtual = ActiveVirtualLayer.CreateRectangle(0, 0, 5, 5)
    sVirtual.Fill.ApplyFountainFill CreateRGBColor(255, 0, 0), CreateRGBColor(255, 255, 0)
    sVirtual.Rotate 45
    ActiveDocument.LogCreateShape sVirtual
End Sub
-Shelby
Reply With Quote
  #6  
Old 18-02-2009, 01:35
Joe Joe is offline
Member
 
Join Date: Nov 2008
Location: Latvia
Posts: 92
Send a message via Skype™ to Joe
Default

Superb, thank you! This should improve pretty much every aspect of what I'm doing here.
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


All times are GMT -5. The time now is 22:33.


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