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 18-03-2006, 03:43
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default Please someone check this!

Hello, I'd be grateful if someone with CorelDraw 12 would try this experiment. Create a new document and rename Layer 1 as "picture layer". Create a new layer and name it "word layer". Then try and run the following sub.

Code:
Sub Layercheck()

ActiveDocument.ActivePage.Layers("word layer").Name = "text"
ActiveDocument.ActivePage.Layers("picture layer").Name = "images"

End Sub
I get an out of range error. The picture layer is being changed to text. What am I doing wrong? Is this some kind of bug or corruption or am I being crazy?

Thanks,

Chris (hunt)
Reply With Quote
  #2  
Old 18-03-2006, 08:30
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
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 Layers

Try it this way:
Code:
Sub Layercheck()

ActivePage.Layers("word layer").Activate
ActiveLayer.Name = "text"

ActivePage.Layers("picture layer").Activate
ActiveLayer.Name = "images"

End Sub
Good luck,

Shelby
Reply With Quote
  #3  
Old 18-03-2006, 18:30
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default

Thanks Shelby, that worked. The code I was trying to use is straight from page 47 of the Programming Guide for VBA

Do you know anything about checking for the existence of layers? I tried using Alex's macro from this thread but I have a problem with master layers. The thread was created in 2002 so I'm hoping there is another way now.

Best wishes,

Chris
Reply With Quote
  #4  
Old 18-03-2006, 22:32
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,791
Blog Entries: 15
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 Master Layers

What is the problem you are running into. Alex's example is the way I would do it. I use something very similar for objectdata fields, to check and make sure they exist.

Shelby
Reply With Quote
  #5  
Old 19-03-2006, 04:35
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default

Here's an example. If I run the macro more than once I get an error message. If it is a master layer it keeps trying to create the back layer. If back isn't a master layer there is no error. I guess I'm doing something wrong with the master layer? I tried using If lr not is nothing then as well but had the same problem

Chris


Code:
Sub Layercheck()
Dim lr0 As Layer

Set lr = FindLayer(ActivePage, "back")
If lr Is Nothing Then
ActiveDocument.ActivePage.CreateLayer ("back")
Set lr0 = ActiveDocument.ActivePage.Layers("back")
lr0.Master = True
End If
End Sub

------------------------

Public Function FindLayer(ByVal pg As Page, ByVal Name As String) As Layer
    Dim LayerFound As Layer
    Dim lr As Layer
    
    Set LayerFound = Nothing
        
    For Each lr In pg.Layers
        If lr.Name = Name Then
            Set LayerFound = lr
            Exit For
        End If
    Next lr
    
    Set FindLayer = LayerFound
    
End Function
Reply With Quote
  #6  
Old 24-03-2006, 17:33
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default Checking Existence of Master layers

Can anyone please confirm if the code posted in my previous post should work with master layers? It seems my check is ignored if the layer is a master layer and I get an error because the layer is being created more than once.

Thanks,

Chris (Hunt)
Reply With Quote
  #7  
Old 27-03-2006, 00:52
amollondhe
Guest
 
Posts: n/a
Default tRY THIS OUT

hI gUYS,

i HAVE SIMILER STUFF RUNNING IN MY SYSTEM,U TRY TO DO AS FOLLOWS:

BLNlAYEREXISTS=FALSE
fOR EACH LAYER IN ACTIVE PAGE.LAYERS
IF LAYER.NAME="sOME LAYER YOU WANT" THEN
BLNlAYEREXISTS=TRUE
EXIT FOR
ELSE
GOTO NEXTLOOP
ENDIF
NEXTLOOP:
NEXT
IF NOT BLNlAYEREXISTS THEN
DO YOUR OPRATION
ENDIF

tHIS IS THE WAY I USE IN MY PROGRAM AND IT WORKS FOR ALL LAYERS.

THANKS
AMOL
Reply With Quote
  #8  
Old 28-03-2006, 19:18
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default

Thanks for the idea, unfortunately I'm still getting an error message with master layers. Here is what I tried:

Code:
Dim lr0 As Layer

blnlayerexists = False
For Each Layer In ActivePage.Layers
If Layer.Name = "back" Then
blnlayerexists = True
Exit For
Else
GoTo nextloop
End If
nextloop:
Next
If Not blnlayerexists Then
ActiveDocument.ActivePage.CreateLayer ("back")
Set lr0 = ActiveDocument.ActivePage.Layers("back")
lr0.Master = True

End If
If I run this more than once I get an error message. There seems to be some kind of problem with master layers.

Chris
Reply With Quote
  #9  
Old 28-03-2006, 20:05
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default

Chris,

Yes, there is a problem, but not so much with CorelDRAW but with your code. Layers collection on a regular page just includes the layers of that page. It doesn't include master layers. That's why the first time you are able to create the layer "back". Then you run the code again, it can't find that layer in ActivePage.Layers collection because your layer is a master layer and is not listed in the page's layer collection. Then you try to create the layer again and CorelDRAW doesn't allow to create two layers with the same name, so the error occurs.

I had a bit of a trouble going through your code because of the text formatting, so I rewrote it a bit for others who could be interested in this conversation. I hope this version is a bit more readable (yet still exibits the problem). I also simplified it a bit. You can see that I have removed a few lines as they were not needed:

Code:
Sub EnsureLayerExists()
    Dim lr As Layer
    Dim bLayerExists As Boolean
    
    bLayerExists = False
    For Each lr In ActivePage.Layers
        If lr.Name = "back" Then
            bLayerExists = True
            Exit For
        End If
    Next lr
    
    If Not bLayerExists Then
        Set lr = ActivePage.CreateLayer("back")
        lr.Master = True
    End If
End Sub
Now, fortunately, CorelDRAW X3 has another layer collection of the Page object that lists both regular and master layers. It is called Page.AllLayers. So, simple modification of the code makes it work:

Code:
Sub EnsureLayerExists()
    Dim lr As Layer
    Dim bLayerExists As Boolean
    
    bLayerExists = False
    For Each lr In ActivePage.AllLayers
        If lr.Name = "back" Then
            bLayerExists = True
            Exit For
        End If
    Next lr
    
    If Not bLayerExists Then
        Set lr = ActivePage.CreateLayer("back")
        lr.Master = True
    End If
End Sub
If you are using a previous version of CorelDRAW, then you will need to iterate through the layers of the master page instead:

Code:
Sub EnsureLayerExists()
    Dim lr As Layer
    Dim bLayerExists As Boolean
    
    bLayerExists = False
    For Each lr In ActiveDocument.MasterPage.Layers
        If lr.Name = "back" Then
            bLayerExists = True
            Exit For
        End If
    Next lr
    
    If Not bLayerExists Then
        Set lr = ActivePage.CreateLayer("back")
        lr.Master = True
    End If
End Sub
Note that Document.MasterPage property only available in CorelDRAW 12 and X3. If you use v10 or 11 you will need to use Document.Pages(0) to access the master page.
Reply With Quote
  #10  
Old 31-03-2006, 18:46
knowbodynow knowbodynow is offline
Senior Member
 
Join Date: Mar 2006
Location: Hatsukaichi near Hiroshima
Posts: 434
Default

Thank you, thank you - I've got my script working and learnt more about scripting as well. You're brilliant!

Best wishes,

Chris
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
Is there a property/method to check for shape off page? Shaddy CorelDRAW/Corel DESIGNER VBA 8 26-08-2006 13:04
Corel Draw X3 crashes on spell check IMRKE General 1 23-02-2006 07:21
VBA and XML cam889 CorelDRAW/Corel DESIGNER VBA 3 10-02-2006 04:47
How to Check for two keys pressed at the same time xombie CorelDRAW/Corel DESIGNER VBA 2 09-12-2005 09:29
How to check presence effects? G-Kir CorelDRAW/Corel DESIGNER VBA 3 22-06-2005 06:11


All times are GMT -5. The time now is 00:46.


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