Determine if an object's layer is frozen or thawed

Determine if an object's layer is frozen or thawed

Anonymous
Not applicable
415 Views
4 Replies
Message 1 of 5

Determine if an object's layer is frozen or thawed

Anonymous
Not applicable
I'm trying to calculate the total area of all polygons in the drawing whose layers include the prefix "AREA-" AND whose layer is not currently frozen. I don't want to include layers that are frozen.

I have gotten the calculation part down, as well as the layer prefix. How do I determine if the object's layer is frozen or thawed?

Here's what I've got so far...

Public Sub getareathawed()
Dim obj As AcadObject
totalArea = 0
For Each obj In ThisDrawing.ModelSpace
If obj.ObjectName = "AcDbPolyline" And InStr(1, obj.Layer, "AREA-", vbTextCompare) <> 0 Then
totalArea = totalArea + Format((obj.Area / 144), 0)
End If
Next
MsgBox totalArea & " Sq. Ft. on AREA layers"
End Sub
0 Likes
416 Views
4 Replies
Replies (4)
Message 2 of 5

fxcastil
Advocate
Advocate
from the object browser help files


Sub Example_Freeze()
' This example creates a new layer called "Freeze".
' It then displays the status of the Freeze property
' for the new layer, toggles the status of the
' Freeze property, and again displays it's status.
' After running this example, you can check the layer
' control on the Object Properties tool bar. It will
' show the new layer and the latest Freeze status.

Dim layerObj As AcadLayer

' Create the new layer
Set layerObj = ThisDrawing.Layers.Add("Freeze")

' Display the Freeze status of the new layer
GoSub DISPLAYSTATUS

' Toggle the status of the Freeze property for the layer
layerObj.Freeze = Not (layerObj.Freeze)

' Display the Freeze status of the new layer
GoSub DISPLAYSTATUS
Exit Sub

DISPLAYSTATUS:
If layerObj.Freeze Then
MsgBox "Layer " & layerObj.name & " is frozen.", , "Freeze Example"
Else
MsgBox "Layer " & layerObj.name & " is thawed.", , "Freeze Example"
End If
Return

End Sub

Sub Example_Lock()
' This example creates a new layer called "Lock".
' It then displays the status of the Lock property
' for the new layer, toggles the status of the
' Lock property, and again displays it's status.
' After running this example, you can check the layer
' control on the Object Properties tool bar. It will
' show the new layer and the latest Lock status.

Dim layerObj As AcadLayer

' Create the new layer
Set layerObj = ThisDrawing.Layers.Add("Lock")

' Display the Lock status of the new layer
GoSub DISPLAYSTATUS

' Toggle the status of the Lock property for the layer
layerObj.Lock = Not (layerObj.Lock)

' Display the Lock status of the new layer
GoSub DISPLAYSTATUS
Exit Sub

DISPLAYSTATUS:
If layerObj.Lock Then
MsgBox "Layer " & layerObj.name & " is locked.", , "Lock Example"
Else
MsgBox "Layer " & layerObj.name & " is unlocked.", , "Lock Example"
End If
Return

End Sub

Fred Castillo
0 Likes
Message 3 of 5

Anonymous
Not applicable
Ok, I copied that example code and used it, and it worked fine as is. However, ince I tried to apply the same stuff to my own code, it didn't work anymore. I'm partly confused because in the example, both the layer name and the property are called Freeze, so I'm not sure when it's referring to the layer by name or to the property.

I tried this before, but it didn't work:
----------------------------------------------------------------------
Public Sub getareathawed()
Dim obj As AcadObject
totalArea = 0
For Each obj In ThisDrawing.ModelSpace
If obj.ObjectName = "AcDbPolyline" And InStr(1, obj.Layer, "AREA-", vbTextCompare) 0 And obj.Layer.Freeze = False Then
totalArea = totalArea + Format((obj.Area / 144), 0)
End If
Next
MsgBox totalArea & " Sq. Ft. on AREA layers"
End Sub
----------------------------------------------------------------------

I'm thinking that my syntax is wrong when evaluating the layer's Freeze property. Any tips on how to correct that?
0 Likes
Message 4 of 5

Anonymous
Not applicable
You must test the Layer itself for the freeze property.....

If (obj.ObjectName = "AcDbPolyline") And (InStr(1, obj.Layer,
"AREA-", vbTextCompare) <> 0) _
And (ThisDrawing.Layers.Item(obj.Layer).Freeze = False) Then
totalArea = totalArea + Format((obj.Area / 144), 0)
End If

wrote in message news:5088847@discussion.autodesk.com...
Ok, I copied that example code and used it, and it worked fine as is.
However, ince I tried to apply the same stuff to my own code, it didn't work
anymore.
0 Likes
Message 5 of 5

Anonymous
Not applicable
Perfect! Thanks alot. That makes sense, and it works exactly how I want it to.
0 Likes