Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FREEZING A LIST OF LAYERS WITH VBA?

Status
Not open for further replies.

vbcad

Technical User
Jul 12, 2002
159
0
0
US
I AM ATTEMPTING TO FREEZE A LIST OF LAYERS WITH A VBA MACRO. CAN I MODIFY THIS CODE TO FREEZE A LIST OF LAYERS BY NAME? I HAVE TRIED TO PUT A LAYER NAME IN (SHOWN IN RED) BUT IT DOES NOT WORK. I KNOW IT IS NOT THE CORRECT SYNTAX.

Dim FRZLayer As AcadLayer
For Each FRZLayer In ThisDrawing.Layers ("A-WALL")
FRZLayer.Freeze = True
Next FRZLayer
End Sub
 
Hi vbcad,

Try this...

Code:
...

Dim FRZLayer as AcadLayer

For Each FRZLayer In ThisDrawing.Layers
  If FRZLayer.Name = "A-WALL" Then
    FRZLayer.Freeze = True
  End IF
Next FRZLayer

or:

Code:
Dim strLyrs as Variant
Dim iCnt as Integer

strLyrs = Array("A-WALL", "A-GLAZ", "A-DOOR")

For iCnt = LBound(strLyrs) to UBound(strLyrs)
  ThisDrawing.Layers(strLyrs(iCnt)).Freeze = True
Next iCnt

HTH
Todd
 
will this work with wildcard symbols? such as "*|A-WALL-glaz" in the list of layers? it doesn's seem to work properly for freezing xref layers.
 
i have been experimenting further and the code examples above do not work for native as well as xref layers. they appear that they should work. i do not get an error but the drawing is not affected at all.
 
Hi vbcad,

For your first question, no, VBA will want a fully qualified name for this work, no wildcards allowed.

I just tried the code above (with the array) and it worked for me, you might check and see if one of the layers you are trying to freeze is the current layer, that may cause the routine to not work.

HTH
Todd
 
you were right both work now. one of the layers was current. Is there a way to use wildcards with the VBA code? I have a lisp version of this which does accept wildcards. i am trying to use VBA to learn more of the functions.
 
i found this on another forum. it claims to use wildcards but dont know if it works yet.

Function layfreeze(sLayers As String)
''sLayers is a string containing the layer(s) to be frozen, seperated by commas. _
May conatin wildcards..... "Layer1,ThisOne2,ANNO*"
Dim oLay As AcadLayer
Dim sLayName As Variant
Dim vLayers As Variant
vLayers = Split(sLayers, ",")
For Each oLay In ThisDrawing.Layers
For Each sLayName In vLayers
If (oLay.Name Like sLayName) And (ThisDrawing.ActiveLayer.Name <> oLay.Name) Then
oLay.Freeze = True
Exit For
End If
Next
Next oLay
End Function

Sub test()
layfreeze "*CONT*,C-*"
End Sub
 
Hi vbcad,

It should work fine, if you look, it's using the Like operator to make a wildcard type function - should do what you need.

HTH
Todd
 
there seems to be a problem with the sub to call the routine. i tried quotes around the layer names.

Sub test()
layfreeze ("*CONT*", "c-*")
End Sub

This still doesnt work. even with layers with names with cont etc in them.
 
Hi vbcad,

From the looks of the routine, you'll only be able to pass it one layer name at a time - something like:

Code:
 layfreeze "*CONT*"

HTH
Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top