renaming layers

renaming layers

Anonymous
Not applicable
408 Views
8 Replies
Message 1 of 9

renaming layers

Anonymous
Not applicable
Why won't this work?

strOldString = txtOldString.Text
strNewString = txtNewString.Text

For Each objLayer In ThisDrawing.Layers
' Debug.Print objLayer.Name
Replace objLayer.Name, strOldString, strNewString
Next

Josh
0 Likes
409 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
this doesn't work either.

Dim strLayerName As String
Dim strOldString As String
Dim strNewString As String
Dim objLayer As AcadLayer

'On Error GoTo cmdOK_error

strOldString = txtOldString.Text
strNewString = txtNewString.Text

For Each objLayer In ThisDrawing.Layers
' Debug.Print objLayer.Name
strLayerName = CStr(objLayer.Name)
Set objLayer = ThisDrawing.Layers(strLayerName)
Replace strLayerName, strOldString, strNewString, 1, , vbTextCompare
objLayer.Name = strLayerName
Next
0 Likes
Message 3 of 9

Anonymous
Not applicable
Try the following:

 


strOldString = txtOldString.Text
strNewString = txtNewString.Text

Dim tempstr

For Each objLayer In ThisDrawing.Layers
' Debug.Print
objLayer.Name 
tempstr = objLayer.Name   


Replace tempstr, strOldString, strNewString


objLayer.Name = tempstr
Next


 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Why
won't this work?

strOldString = txtOldString.Text
strNewString = txtNewString.Text

For Each objLayer In ThisDrawing.Layers
' Debug.Print objLayer.Name

    Replace objLayer.Name, strOldString, strNewString

Next

Josh

0 Likes
Message 4 of 9

Anonymous
Not applicable
Have you checked to see if the information is going
into your str variables. I quote, "You can't access a control if it does not
have the focus." Try this

 

strOldString = Me.txtOldString

strNewString = Me.txtNewString

 

For Each objLayer in
ThisDrawing.Layers

    If objLayer.Name =
ThisDrawing.Layers.Item(strOldString) Then

        objLayer.Name
= strNewLayer

    End If

Next


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Why
won't this work?

strOldString = txtOldString.Text
strNewString = txtNewString.Text

For Each objLayer In ThisDrawing.Layers
' Debug.Print objLayer.Name

    Replace objLayer.Name, strOldString, strNewString

Next

Josh

0 Likes
Message 5 of 9

Anonymous
Not applicable
Well, it looks like you're iterating through all
the

layers [which if that's the case then you're
trying

to rename layer "0"]. Need I say more?

 

Joe

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Why
won't this work?

strOldString = txtOldString.Text
strNewString = txtNewString.Text

For Each objLayer In ThisDrawing.Layers
' Debug.Print objLayer.Name

    Replace objLayer.Name, strOldString, strNewString

Next

Josh

0 Likes
Message 6 of 9

Anonymous
Not applicable
not if you are iterating through them and only
looking to match an individual name to an individual string.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Well, it looks like you're iterating through all
the

layers [which if that's the case then you're
trying

to rename layer "0"]. Need I say
more?

 

Joe

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Why
won't this work?

strOldString = txtOldString.Text
strNewString = txtNewString.Text

For Each objLayer In ThisDrawing.Layers
' Debug.Print objLayer.Name

    Replace objLayer.Name, strOldString,
strNewString
Next

Josh

0 Likes
Message 7 of 9

Anonymous
Not applicable
Well, that would depend on what he has in the
TextBox

which we don't know what that data might be. Also,
there

is no error trapping which I would add on this
particular

example to guard against that very
scenario.

 

Joe

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

not if you are iterating through them and only
looking to match an individual name to an individual string.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Well, it looks like you're iterating through
all the

layers [which if that's the case then you're
trying

to rename layer "0"]. Need I say
more?

 

Joe

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Why
won't this work?

strOldString = txtOldString.Text
strNewString = txtNewString.Text

For Each objLayer In ThisDrawing.Layers
' Debug.Print objLayer.Name

    Replace objLayer.Name, strOldString,
strNewString
Next

Josh

0 Likes
Message 8 of 9

Anonymous
Not applicable
This is still giving me fits. The idea behind this routine was that my client could rename the layers in their drawing to change a certain prefix that they had added to their layers; and they have a fair number of drawings to edit. So, the strOldString variable is the old prefix, and the strNewString is the new layer prefix.


Private Sub cmdOK_Click()
Dim strLayerName As String
Dim strOldString As String
Dim strNewString As String
Dim objLayer As AcadLayer

On Error Resume Next

strOldString = txtOldString.Text
strNewString = txtNewString.Text

'For Each objLayer In ThisDrawing.Layers
' Debug.Print objLayer.Name
'Next

For Each objLayer In ThisDrawing.Layers
strLayerName = CStr(objLayer.Name)
Set objLayer = ThisDrawing.Layers(strLayerName)
Replace strLayerName, strOldString, strNewString, 1, , vbTextCompare
objLayer.Name = strLayerName
Next

subExit

End Sub


What did I miss?

Thanks,

Joshua
0 Likes
Message 9 of 9

Anonymous
Not applicable
Josh,

 

Here's your answer. The Replace function returns
the

changed string which I then assign to the
Layer.Name

property accordingly.

 

Joe

--

Dim strOldString As String
Dim strNewString As
String
Dim objLayer As AcadLayer

 

  On Error Resume Next
 
 
strOldString = UCase(txtOldString.Text)
  strNewString =
UCase(txtNewString.Text)
 
  For Each objLayer In
ThisDrawing.Layers
    objLayer.Name = Replace(objLayer.Name,
strOldString, strNewString)
  Next objLayer


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
This
is still giving me fits. The idea behind this routine was that my client could
rename the layers in their drawing to change a certain prefix that they had
added to their layers; and they have a fair number of drawings to edit. So,
the strOldString variable is the old prefix, and the strNewString is the new
layer prefix.


Private Sub cmdOK_Click()
Dim strLayerName As String
Dim
strOldString As String
Dim strNewString As String
Dim objLayer As
AcadLayer

On Error Resume Next

strOldString = txtOldString.Text
strNewString = txtNewString.Text

'For Each objLayer In ThisDrawing.Layers
' Debug.Print objLayer.Name

'Next

For Each objLayer In ThisDrawing.Layers

    strLayerName = CStr(objLayer.Name)

    Set objLayer = ThisDrawing.Layers(strLayerName)

    Replace strLayerName, strOldString, strNewString,
1, , vbTextCompare
    objLayer.Name = strLayerName

Next

subExit

End Sub


What did I miss?

Thanks,

Joshua

0 Likes