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 27-05-2005, 16:57
Granite Golem
Guest
 
Posts: n/a
Lightbulb Glitches with Names of Objects

I noticed a bad bug in CorelDRAW 12 when I tried to operate with objects. Firstly I addressed to objects by their numbers on a layer - not very handy way, but it seems to be the only one reliable one. Because later I went to Object Manager and gave all objects sensible names, rewrote some code to address to objects by names, ran my macro - and saw that among 70 objects on my resulting page about 4-6 are wrong. It is always random places and amounts, and while I filled my resulting page consequently, I noticed that wrong objects were duplicates of those which have been placed just before them. I.e. if I command to copy "Colon" and then "Char_x", sometimes I get 2 "Colon"s - first in its right place, and another - instead of "Char_x", which went just after "Colon". I suppose that there are some delays in resolving object name, and it causes copy-pasting not current object but previous. I tried to clear clipboard after some copy-pastes, but it didn't help.

I have no patches for CorelDRAW 12 - maybe some patch fixes this problem? I had no other choice than to return to numbers. They don't glitch at all.
Reply With Quote
  #2  
Old 31-05-2005, 08:15
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Maybe you could post your code so that we can understand better, what is happening. And maybe also describe what you are trying to do. I've never had a problem with duplicating named objects.

Alos look into downloading Service Pack 1 from www.corel.com
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #3  
Old 31-05-2005, 10:17
Granite Golem
Guest
 
Posts: n/a
Default Re

Well, the code of my subroutine is here:
Code:
Sub PutShape(shp As Variant, cx As Integer, cy As Integer, ssiz As Integer)

ThisDocument.Pages(2).Activate
ActivePage.Layers(2).Shapes(shp).Copy
ThisDocument.Pages(1).Layers(1).Activate
ActiveLayer.Paste
ActiveSelectionRange.SetPosition cx, cy

If ssiz <> 100 Then
    Dim wdt, het As Double
    wdt = ActiveSelectionRange.SizeWidth
    het = ActiveSelectionRange.SizeHeight
    ActiveSelectionRange.SetSize (wdt * ssiz / 100), (het * ssiz / 100)
End If

End Sub
I call it many times just as following:
Call PutShape(9, 720, 1720, 100)

Sometimes I, of course, give numbers from some arrays. If I need to change color of the last shape put, I write:
ActiveSelectionRange.ApplyUniformFill CreateRGBColor(0, 147, 221)

This code works for now without problems.

For names I had only to substitute first variables for PutShape() with some strings like "day", "month" etc. So call was like this:
Call PutShape("day", 720, 1720, 100)

Also I went to Object Manager and assigned a name to each object. And from here those glitches began. When I tried to change color, ActiveSelectionRange was just previous object, and it was scaled (within PutShape()) and recolored (within the main routine).

I read about changes made in SP1, but found nothing about this glitch. Nevertheless I'll download it a bit later and check it out.
Reply With Quote
  #4  
Old 31-05-2005, 10:35
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

I'm not sure if this will help, but have you tried changing
Code:
Sub PutShape(shp As Variant, cx As Integer, cy As Integer, ssiz As Integer)
to...
Code:
Sub PutShape(shp As String, cx As Long, cy As Long, ssiz As Long)
I'm not sure that this will have much impact, but changing the Variant to String should help.
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #5  
Old 31-05-2005, 12:06
Lev
Guest
 
Posts: n/a
Default

then he would not be able to use
Call PutShape(9, 720, 1720, 100)
But he can, certainly make a second Sub with a string variable and use 2 different sub's for different calls.
Reply With Quote
  #6  
Old 31-05-2005, 12:24
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Excellent point Lev. However, according to his first post, I assumed that the objects were either named or number, not both at the same time. However is using number and string names, then yes, I agree, two subs would be useful here.

Thanks for catching that for me.
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
Reply With Quote
  #7  
Old 31-05-2005, 12:44
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default

I don't see a need for two different functions. Using the Variant in this case is fully justified and that's the way I'd do it too. The other parameters (Integer) should be changed to Double I guess because that's what CorelDRAW uses for coordinates anyway. Also instead of using SetSize you can use Stretch method. Also, instead of using ThisDocument, you should use ActiveDocument because ThisDocument is a very specific property of a VBA project embedded in the document. You can't put this code in a GMS module. It won't work. However ActiveDocument works everywhere.

Here is slightly modified version of this subroutine:

Code:
Sub PutShape(ByVal shp As Variant, ByVal cx As Double, ByVal cy As Double, ByVal dScale As Double)
    ActiveDocument.Pages(2).Activate
    ActivePage.Layers(2).Shapes(shp).Copy
    ActiveDocument.Pages(1).Layers(1).Activate
    ActiveLayer.Paste
    ActiveSelectionRange.SetPosition cx, cy
    
    If dScale <> 100 Then
        ActiveSelectionRange.Stretch dScale / 100
    End If
End Sub
I didn't see a problem with this code on limited testing I did. But since you said that this is a very intermittent problem I might need to do a lot more testing before bumping into it...
Reply With Quote
  #8  
Old 31-05-2005, 13:18
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default

It appears you are right. There is some weird problem with Copy/Paste. It seems that the page doesn't get switched to properly (kind of the object is copied before the page has a chance to get activated or something). Anyway, to test the problem, I created the following code:

Code:
Sub TestCopy()
    Dim nx As Integer
    Dim ny As Integer
    Dim clr As Integer
    Dim doc As Document
    Set doc = CreateDocument
    doc.AddPages 1
    doc.ActivePage.CreateLayer "Layer 2"
    doc.ActivePage.Layers(2).Activate
    With ActiveLayer.CreateRectangle2(0, 0, 0.5, 0.5)
        .Name = "Red"
        .Fill.UniformColor.RGBAssign 255, 0, 0
    End With
    With ActiveLayer.CreateRectangle2(0.5, 0, 0.5, 0.5)
        .Name = "Green"
        .Fill.UniformColor.RGBAssign 0, 128, 0
    End With
    With ActiveLayer.CreateRectangle2(1, 0, 0.5, 0.5)
        .Name = "Blue"
        .Fill.UniformColor.RGBAssign 0, 0, 255
    End With
    Optimization = True
    For ny = 1 To 20
        For nx = 1 To 5
            For clr = 0 To 2
                PutShape Array("Red", "Green", "Blue")(clr), (nx * 3 + clr) / 2 - 1, ny / 2 + 0.5, 100
            Next clr
        Next nx
    Next ny
    Optimization = False
End Sub
It creates a new document with two pages and two layers. On Layer 2 or Page 2 it creates three rectangles with Red, Green, and Blue fills and gives them a corresponding name ("Red", "Green", "Blue"). Then it creates 20 rows or 15 columns on page 1, layer 1 with alternating colors (r, g, b, r, g, b). After running the code with using the original PutShape function (the one I posted in my previous post), the resulting grid had some colors off. As illustrated in the following attachment...
Attached Images
 
Reply With Quote
  #9  
Old 31-05-2005, 13:27
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default

Then I decided that if the problem is with Copy/Paste, then we need to rework the code to avoid using Copy/Paste for this altogether. In fact, I don't like using Copy/Paste for creating copies of objects in a macro for several reasons:

1. It changes user's clipboard which might not be desirable
2. It is extremely slow
3. As we just figured out, it is unreliable

It is much better/faster to use Shape.Duplicate method instead. Here is the reworked PutShape function which uses Duplicate instead of copy/paste:

Code:
Sub PutShape(ByVal shp As Variant, ByVal cx As Double, ByVal cy As Double, ByVal dScale As Double)
    Dim sCopy As Shape
    Set sCopy = ActivePage.Layers(2).Shapes(shp).Duplicate
    sCopy.MoveToLayer ActiveDocument.Pages(1).Layers(1)
    sCopy.SetPosition cx, cy
    
    If dScale <> 100 Then
        sCopy.Stretch dScale / 100
    End If
End Sub
As you can see it is much more compact, it works much faster (with the old version of PutShape it took my TestCopy function 1 min 43 sec to complete, while with the new one it only took 1.6 seconds! That's over 60 times faster). And, obviously, it produces the correct result. See attached.
Attached Images
 
Reply With Quote
  #10  
Old 31-05-2005, 13:45
ddonnahoe's Avatar
ddonnahoe ddonnahoe is offline
Senior Member
 
Join Date: Jan 2004
Location: Louisville, KY
Posts: 552
Send a message via ICQ to ddonnahoe Send a message via AIM to ddonnahoe Send a message via MSN to ddonnahoe Send a message via Yahoo to ddonnahoe
Default

Alex, a little off the subject but, how is it that you can time your macros? I'd like to know how to do this myself.
__________________
Sean
Waiting for a ride in the T.A.R.D.I.S.
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
Retrieve names list of constants in a given enumeration zlatev CorelDRAW/Corel DESIGNER VBA 5 09-02-2009 21:12
fit objects to path edges geopig Other Oberon Commercial Products 1 03-08-2006 00:28
Find objects by properties Webster CorelDRAW/Corel DESIGNER VBA 8 01-12-2004 19:51
Need help accessing objects in a group ama CorelDRAW/Corel DESIGNER VBA 5 20-02-2004 12:28
I need to update objects visibility faster NEHovis Corel Photo-Paint VBA 0 18-07-2003 08:54


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


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