comcu Posted September 10, 2008 Author Share Posted September 10, 2008 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. Quote Link to comment Share on other sites More sharing options...
ML0940 Posted September 10, 2008 Share Posted September 10, 2008 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 Quote Link to comment Share on other sites More sharing options...
ML0940 Posted September 10, 2008 Share Posted September 10, 2008 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 Quote Link to comment Share on other sites More sharing options...
borgunit Posted September 11, 2008 Share Posted September 11, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.