@grobnik thanks again sir, it's working properly, however the adding of codes every new created layer is kinda hard, it's confusing and time consuming. I have to re-edit the codes every cad file with different layer names >..<
anyway, thank you again for this sir.
And this code that you gave me from the beginning or from my other post, I've been trying to troubleshoot it, seems the main problem is getting the:
LayersX (list of layer in selectionset with no repeated Layers)
then
LayCount will only be LayCount=LayersX .Count
I hope you could still help me figure it out, since it doesn't require me to edit the codes every adding of LAYERS
Code (I tried to revised):
Sub TOTAL_LINEAR()
Dim ASelSet As AcadSelectionSet
Dim FilterType(1) As Integer
Dim FilterData(1) As Variant
On Error Resume Next
Set ASelSet = ThisDrawing.SelectionSets.Add("SS")
FilterType(0) = 0
FilterData(0) = "LINE,POLYLINE,LWPOLYLINE,ARC,CIRCLE,ELLIPSE,SPLINE"
FilterType(1) = 8
FilterData(1) = "Yellow,Red,Cyan,Green,Blue,ORANGE,REINFORCEMENTS,8mm RSB by 6m,10mm RSB by 6m,12mm RSB by 6m,16mm RSB by 6m,20mm RSB by 6m,25mm RSB by 6m,28mm RSB by 6m,32mm RSB by 6m,8mm RSB by 7.5m,10mm RSB by 7.5m,12mm RSB by 7.5m,16mm RSB by 7.5m,20mm RSB by 7.5m,25mm RSB by 7.5m,28mm RSB by 7.5m,32mm RSB by 7.5m,8mm RSB by 9m,10mm RSB by 9m,12mm RSB by 9m,16mm RSB by 9m,20mm RSB by 9m,25mm RSB by 9m,28mm RSB by 9m,32mm RSB by 9m,8mm RSB by 10.5m,10mm RSB by 10.5m,12mm RSB by 10.5m,16mm RSB by 10.5m,20mm RSB by 10.5m,25mm RSB by 10.5m,28mm RSB by 10.5m,32mm RSB by 10.5m,8mm RSB by 12m,10mm RSB by 12m,12mm RSB by 12m,16mm RSB by 12m,20mm RSB by 12m,25mm RSB by 12m,28mm RSB by 12m,32mm RSB by 12m"
If Err.Number <> 0 Then
Set ASelSet = ThisDrawing.SelectionSets.Item("SS")
FilterType(0) = 0
FilterData(0) = "LINE,POLYLINE,LWPOLYLINE,ARC,CIRCLE,ELLIPSE,SPLINE"
FilterType(1) = 8
FilterData(1) = "Yellow,Red,Cyan,Green,Blue,ORANGE,REINFORCEMENTS,8mm RSB by 6m,10mm RSB by 6m,12mm RSB by 6m,16mm RSB by 6m,20mm RSB by 6m,25mm RSB by 6m,28mm RSB by 6m,32mm RSB by 6m,8mm RSB by 7.5m,10mm RSB by 7.5m,12mm RSB by 7.5m,16mm RSB by 7.5m,20mm RSB by 7.5m,25mm RSB by 7.5m,28mm RSB by 7.5m,32mm RSB by 7.5m,8mm RSB by 9m,10mm RSB by 9m,12mm RSB by 9m,16mm RSB by 9m,20mm RSB by 9m,25mm RSB by 9m,28mm RSB by 9m,32mm RSB by 9m,8mm RSB by 10.5m,10mm RSB by 10.5m,12mm RSB by 10.5m,16mm RSB by 10.5m,20mm RSB by 10.5m,25mm RSB by 10.5m,28mm RSB by 10.5m,32mm RSB by 10.5m,8mm RSB by 12m,10mm RSB by 12m,12mm RSB by 12m,16mm RSB by 12m,20mm RSB by 12m,25mm RSB by 12m,28mm RSB by 12m,32mm RSB by 12m"
End If
ASelSet.Clear
ASelSet.SelectOnScreen FilterType, FilterData
Dim LayerX As AcadLayer
Dim LayersX As AcadLayers
Set LayersX = ThisDrawing.Layers 'ASelSet.Layers
Dim LayCount As Integer
LayCount = ASelSet.count 'LayersX.count
ThisDrawing.Regen acAllViewports
On Error Resume Next
ThisDrawing.ActiveLayer = ThisDrawing.Layers.Add("TABLE")
Dim SelInsPoint As Variant
SelInsPoint = ThisDrawing.Utility.GetPoint(, "Select Insertion Point of Table: ")
Dim MyModelSpace As AcadModelSpace
Set MyModelSpace = ThisDrawing.ModelSpace
Set MyTableLinear = MyModelSpace.AddTable(SelInsPoint, LayCount, 2, 500, 5000)
MyTableLinear.SetCellValue 0, 0, "Total Linear (m)"
MyTableLinear.SetCellValue 1, 0, "Description"
MyTableLinear.SetCellValue 1, 1, "Quantity"
Dim Row As Integer
Row = 2
For Each LayerX In LayersX 'ASelSet.Layers '
If LayerX.Name <> "0" And LayerX.Name <> "Defpoints" And LayerX.Name <> "AM_CL" Then
MyTableLinear.SetCellValue Row, 0, LayerX.Name
Row = Row + 1
End If
Next
Dim ObjectsName() As Variant
Dim OBJECT As AcadObject
Dim LayName() As Variant
Dim count As Integer
Dim count1 As Integer
Dim TotalLength As Long
' count = 0
' count1 = 0
For Each LayerX In LayersX
' If LayerX.Name <> "0" And LayerX.Name <> "Defpoints" And LayerX.Name <> "AM_CL" Then
' ReDim Preserve LayName(count)
' LayName(count) = LayerX.Name
' count = count + 1
For Each OBJECT In ASelSet
If OBJECT.Layer = LayerX.Name Then
ReDim Preserve ObjectsName(count1)
ObjectsName(count1) = OBJECT.ObjectName
Select Case ObjectsName(count1)
Case "AcDbPolyline"
TotalLength = TotalLength + OBJECT.Length
Case "AcDbLine"
TotalLength = TotalLength + OBJECT.Length
Case "AcDbCircle"
TotalLength = TotalLength + OBJECT.Circumference
Case "AcDbArc"
TotalLength = TotalLength + OBJECT.ArcLength
End Select
End If
Next
' End If
'
For Row = 2 To LayCount
If MyTableLinear.GetCellValue(Row, 0) = LayerX.Name Then
MyTableLinear.SetCellValue Row, 1, FormatNumber(TotalLength / 1000, 2)
End If
Next Row
' LayName(count).Clear
' LayName(count) = 0
' count1 = 0
' Row = 2
TotalLength = 0
Next
End Sub
Again and again, thank you sir, I'm learning at the same time.
God Bless