Jump to content

Changing Layer Names


comcu

Recommended Posts

ML,

 

Yes thank you for the help.

 

Of course i will post the code once i complete it.

 

Its the only way to learn really, if people just do the code for you then you never really improve and i would like to develop.

 

I am working on something at the moment which if you asked me a month ago i would never imagin i could but it a lot easier now and things come to me which they never did before so i must be improvin. . . at least i hope i am! :)

 

thanks again for your help ML,

 

Cheers,

 

Col.

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • ML0940

    13

  • comcu

    8

  • borgunit

    2

  • smorales02

    1

Top Posters In This Topic

Col,

 

Somewhere in the code, before you do the sset, use a loop such as

 

Dim lay as acadlayer

 

'Lets check to see if layer Text_Hadrian is in fact in the drawing.

'If not, let's create it

For each lay in ThisDrawing.Layers

If lay.name = "Text_Hadrian" Then

Goto Continue

Else

ThisDrawing.Layers.Add ("Text_Hadrian")

End If

Next lay

 

Continue:

'Col, start the rest of the code here

 

ML

Link to comment
Share on other sites

That's right Col!

 

That is why you are going to be a dam good programmer! :)

 

Some people just want to rub the Magic Latern and hope that the code Gene will appear LOL

 

Those people can still learn, if they even want to, but it takes a whole lot longer and it can be very frustrating trying to get there when fully reliant on others.

 

OK, I have left you with a little code snippet that may help you

 

Now, rock on man! Rock on! :)

 

ML

Link to comment
Share on other sites

This may be of help also.

 

Instead of cycling through the layers and checking for a layer, then creating it. You can just add a layer to the layers collection and then just handle and clear the error (if the layer already exists). A small tip that can help if the layers collection is huge. The layer gets created either way.

 

Public Function CreateLayer(ByVal slyrName As String) As Boolean
'------------------------------------------------------------------------------
'
'Arguments: sLyrName - string
'------------------------------------------------------------------------------
Dim acLyr As AcadLayer
'''''''''''''''''''''''''''''''''''''''
On Error GoTo ErrHandler 'if layer exists already, clear error

'add layer to collection and set layer active
Set acLyr = ThisDrawing.Layers.Add(slyrName)
       
ExitHere:
   Exit Function
ErrHandler:
   Debug.Print Err.Number, Err.description, "Method 'CreateLayer' Error"
   Err.Clear
   GoTo ExitHere
End Function

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...