New Layer creation

New Layer creation

RoyWickrama_RWEI
Advisor Advisor
583 Views
2 Replies
Message 1 of 3

New Layer creation

RoyWickrama_RWEI
Advisor
Advisor

I found the following code from the forum: Thanks.

However, it runs one time. All fine.

 

But repeated use of the same gives an error message!

SyntaxEditor Code Snippet

Sub Main()            'LayerAddTest()
    
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    
'    Dim oLayers As LayersEnumerator'    oLayers = oDrawDoc.StylesManager.Layers
    
    Dim oLayer As Layer
    ' oLayer = oDrawDoc.StylesManager.Layers.Item(68)
    oLayer = oDrawDoc.StylesManager.Layers.Item("Title (ISO)")
    
    Dim oNewLayer As Layer
    oNewLayer = oLayer.Copy("waynes_layer_copy")
'    '    oNewLayer.Color = ThisApplication.TransientObjects.CreateColor(0, 0, 255)

End Sub

 Could someone help me?

0 Likes
Accepted solutions (1)
584 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

it is probably the copy that is failing on subsequent runs. according to the API

Layer.Copy Method

 

Input String that specifies the name for the new style. This name must be unique with respect to all other styles of a similar type in the document. That is, if a dimension style is being copied, the name must be unique with respect to all the other dimension styles. If it is not unique the method will fail.

 

you are not changing the name of the new layer. 

Message 3 of 3

RoyWickrama_RWEI
Advisor
Advisor
Accepted solution

Thanks for the reply.

I was doing with another rule for the same (see the attached). It was giving me some errors. I incorporated a "Try ... Catch" and got around the problem.

Sub Main()
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    Dim oLayer As Layer
    ' oLayer = oDrawDoc.StylesManager.Layers.Item(68)
    oLayer = oDrawDoc.StylesManager.Layers.Item("Title (ISO)")
    Dim oNewLayer As Layer
    oNewLayer_Name = "XYZ"
    Try
    oNewLayer = oLayer.Copy(oNewLayer_Name)
    Catch
    MessageBox.Show("New layer, " & oNewLayer_Name & ": Exists", "Title")
    End Try
ThisDrawing.Document.StylesManager.Layers(oNewLayer_Name).Visible = False
ThisDrawing.Document.StylesManager.Layers(oNewLayer_Name).Plot = False
End Sub 

 Thanks again.

0 Likes