Using tr As Transaction = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()
Dim doc As CivilDocument = CivilApplication.ActiveDocument
Dim oIdCollection As ObjectIdCollection = doc.GetPipeNetworkIds()
Dim objId As ObjectId = oIdCollection(cmbNetwork.SelectedIndex)
Dim oNetwork As Network = TryCast(tr.GetObject(objId, OpenMode.ForRead), Network)
Dim pl As PartsList = tr.GetObject(oNetwork.PartsListId, OpenMode.ForRead, False, True)
SelectPartFamily(pl.ObjectId, DomainType.Pipe, cmbPipeStyle, "pipe")
SelectPartFamily(pl.ObjectId, DomainType.Structure, cmbStructureStyle, "struct")
Dim pipeOIC As ObjectIdCollection = oNetwork.GetPipeIds()
Dim structureOIC As ObjectIdCollection = oNetwork.GetStructureIds()
lblStatus.Text = "Выбрана сеть - " & oNetwork.Name & ", содержит труб - " & pipeOIC.Count & " и колодцев - " & structureOIC.Count
grdStruct.Rows.Clear() ' заполняю таблицу колодцев
For i = 0 To structureOIC.Count - 1
Dim cStruct As [Structure] = tr.GetObject(structureOIC.Item(i), OpenMode.ForRead, False, True)
grdStruct.Rows.Add()
grdStruct.Rows(i).HeaderCell.Value = Str(i + 1)
grdStruct.Item(colSIDS.Index, i).Value = cStruct.ObjectId
grdStruct.Item(colSName.Index, i).Value = cStruct.Name
grdStruct.Item(colSPrim.Index, i).Value = cStruct.Description
grdStruct.Item(colSSurf.Index, i).Value = cStruct.RefSurfaceName
grdStruct.Item(colSX.Index, i).Value = cStruct.Position(0)
grdStruct.Item(colSY.Index, i).Value = cStruct.Position(1)
grdStruct.Item(colSZ.Index, i).Value = cStruct.Position(2)
Next
grdPipe.Rows.Clear() ' заполняю таблицу труб
Dim dlina(0 To 1) As Single
dlina(0) = 0
dlina(1) = 0
For i = 0 To pipeOIC.Count - 1
Dim cPipe As Pipe = tr.GetObject(pipeOIC.Item(i), OpenMode.ForRead, False, True)
grdPipe.Rows.Add()
grdPipe.Rows(i).HeaderCell.Value = Str(i + 1)
grdPipe.Item(colPIds.Index, i).Value = cPipe.ObjectId
grdPipe.Item(colPName.Index, i).Value = cPipe.Name
grdPipe.Item(colPPrim.Index, i).Value = cPipe.Description
grdPipe.Item(colPSurf.Index, i).Value = cPipe.RefSurfaceName
grdPipe.Item(colPUkon.Index, i).Value = cPipe.Slope * 1000
grdPipe.Item(colSurN.Index, i).Value = cPipe.StartStructureId
grdPipe.Item(colXN.Index, i).Value = cPipe.StartPoint(0)
grdPipe.Item(colYN.Index, i).Value = cPipe.StartPoint(1)
grdPipe.Item(colPOtmN.Index, i).Value = cPipe.StartPoint(2)
grdPipe.Item(colSurK.Index, i).Value = cPipe.EndStructureId
grdPipe.Item(colXK.Index, i).Value = cPipe.EndPoint(0)
grdPipe.Item(colYK.Index, i).Value = cPipe.EndPoint(1)
grdPipe.Item(colPOtmK.Index, i).Value = cPipe.EndPoint(2)
grdPipe.Item(colPDlina2.Index, i).Value = ((cPipe.StartPoint(0) - cPipe.EndPoint(0)) ^ 2 + (cPipe.StartPoint(1) - cPipe.EndPoint(1)) ^ 2) ^ 0.5
dlina(0) = dlina(0) + grdPipe.Item(colPDlina2.Index, i).Value
grdPipe.Item(colDlina3.Index, i).Value = ((cPipe.StartPoint(0) - cPipe.EndPoint(0)) ^ 2 + (cPipe.StartPoint(1) - cPipe.EndPoint(1)) ^ 2 + (cPipe.StartPoint(2) - cPipe.EndPoint(2)) ^ 2) ^ 0.5
dlina(1) = dlina(1) + grdPipe.Item(colDlina3.Index, i).Value
' ищю колодец для получения глубины трубы
X = 0
For pi = 0 To grdStruct.RowCount - 1
If cPipe.StartStructureId = grdStruct.Item(colSIDS.Index, pi).Value Then
grdPipe.Item(colDethN.Index, i).Value = FormatNumber(grdStruct.Item(colSZ.Index, pi).Value - cPipe.StartPoint(2), 2)
X = X + 1
End If
If cPipe.EndStructureId = grdStruct.Item(colSIDS.Index, pi).Value Then
grdPipe.Item(colDethK.Index, i).Value = FormatNumber(grdStruct.Item(colSZ.Index, pi).Value - cPipe.EndPoint(2), 2)
X = X + 1
End If
' If X = 2 Then
' выхожу из цикла, по идее больше данных не должно быть
' Exit For
' End If
Next
Next
lblStatus.Text = lblStatus.Text & ". 2D длина " & FormatNumber(dlina(0), 2) & ", 3D длина " & FormatNumber(dlina(1), 2)
End Using