![]() |
#1
|
|||
|
|||
![]()
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 Thanks, Chris (hunt) |
#2
|
||||
|
||||
![]()
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 Shelby |
#3
|
|||
|
|||
![]()
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 |
#5
|
|||
|
|||
![]()
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 |
#6
|
|||
|
|||
![]()
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) |
#7
|
|||
|
|||
![]()
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 |
#8
|
|||
|
|||
![]()
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 Chris |
#9
|
||||
|
||||
![]()
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 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 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 |
#10
|
|||
|
|||
![]()
Thank you, thank you - I've got my script working and learnt more about scripting as well. You're brilliant!
Best wishes, Chris |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
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 |