Ok, a bit more detail...
Dim LayerName as String
LayerName = "MyCoolLayer"
ThisDrawing.Layers.Add(LayerName)
This is good. Permits you to change the layer name sometime in the future at
one point.
acXREFS.Layer = "XREFS"
This is bad. In the same procedure you have used a "hard-coded" string. So
if you change the string for the variable, and *forget* to look for other
instances of that string in the procedure, you have created a bug.
It would be far better to do this, in the 2nd case:
acXREFS.Layer = LayerName
This way, you only need to change the string in one place, and be confident
that the rest of the code will still work.
--
R. Robert Bell, MCSE
www.AcadX.com
"Gilles" wrote in message
news:C91FC2F023959C91326BDC5063545FE9@in.WebX.maYIadrTaRb...
| Thank you for your answer which was much more efficient than my first
code.
| I tried it through a few drawings and everything is OK... As a new user I
| am everyday surprised by the potential of VBA but I need to learn some (
| what dou I say... a lot of) things to succeed in my objectives.
| By the way, what do you mean exactly by "BTW, you used a variable for the
| layer name in one spot, and the actual string in another (can you spell
| p-o-t-e-n-t-i-a-l b-u-g? )". What I understand is that I should use the
| same variable to declare the layer name and layer object ??? ... ???
|
|
| Thanks again....
|
| Gilles
|
| ----- Original Message -----
| From: "R. Robert Bell"
| Newsgroups: autodesk.autocad.customization.vba
| Sent: Wednesday, May 28, 2003 7:12 PM
| Subject: Re: selecting all xrefs in modelspace
|
|
| > What if ModelSpace has objects *other* than XRefs?! 😉
| >
| > Public Sub Test()
| >
| > Dim Layer_Name As String
| > Layer_Name = "XREFS"
| >
| > Dim layerXREFS As AcadLayer
| > Set layerXREFS = ThisDrawing.Layers.Add(Layer_Name)
| >
| > layerXREFS.color = acWhite
| > layerXREFS.LayerOn = True
| > layerXREFS.Linetype = "continuous"
| > layerXREFS.Lock = False
| > layerXREFS.PlotStyleName = "Normal"
| > layerXREFS.Lineweight = acLnWtByLwDefault
| > layerXREFS.Plottable = True
| >
| > Dim thisObj As AcadEntity
| >
| > For Each thisObj In ThisDrawing.ModelSpace
| > If TypeOf thisObj Is AcadExternalReference Then thisObj.Layer =
| > Layer_Name
| > Next thisObj
| >
| > End Sub
| >
| > BTW, you used a variable for the layer name in one spot, and the actual
| > string in another (can you spell p-o-t-e-n-t-i-a-l b-u-g? )
| >
| >
| > --
| > R. Robert Bell, MCSE
| > www.AcadX.com
| >
| >
| > "Gilles" wrote in message
| > news:074A51AC13DB08BC531859BBAA5F631E@in.WebX.maYIadrTaRb...
| > | Hello all,
| > |
| > | How can I select all xrefs attached in a modelspace drawing and change
| > their
| > | layer into "XREFS" for example ???
| > |
| > | Here is the code I created but it does not work in all my drawings.
| Don't
| > | understand why...
| > |
| > | 1° When I create a new drawing and attach XREFS inside it (in
| modelspace)
| > it
| > | works fine.
| > | 2° But when I try it in existing files it doesn't work any more.....
:-(
| > |
| > |
| > | I would really appreciate if someone more experienced than I am could
| help
| > | me.
| > |
| > | Thanks
| > |
| > |
| > | Gilles
| > |
| > |
| > |
| > | Option Explicit
| > |
| > | Public Sub Add_Layer_Vport()
| > |
| > |
| > | Dim Layer_Name As String
| > | Dim layerXREFS As AcadLayer
| > |
| > | Layer_Name = "XREFS"
| > |
| > | Set layerXREFS = ThisDrawing.Layers.Add(Layer_Name)
| > |
| > | layerXREFS.Color = acWhite
| > | layerXREFS.LayerOn = True
| > | layerXREFS.Linetype = "continuous"
| > | layerXREFS.Lock = False
| > | layerXREFS.PlotStyleName = "Normal"
| > | layerXREFS.Lineweight = acLnWtByLwDefault
| > | layerXREFS.Plottable = True
| > |
| > |
| > | Dim acXREFS As AcadExternalReference
| > |
| > | For Each acXREFS In ThisDrawing.ModelSpace
| > |
| > | acXREFS.Layer = "XREFS"
| > |
| > | Next acXREFS
| > |
| > |
| > | End Sub
| > |
| > |
| >
| >
|
|