Profile views Show only Crossing Pipes and label it

[CommandMethod("AddPipeLabelsToSections")]
        public void LabelsToSections()
        {
            var civdoc = CivilApplication.ActiveDocument;
            var db = Application.DocumentManager.MdiActiveDocument.Database;
            double station = double.NaN, offset = double.NaN;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId alignId in civdoc.GetAlignmentIds())
                {
                    var align = (Alignment)alignId.GetObject(OpenMode.ForRead);
                    if (align.GetSampleLineGroupIds().Count < 1)
                        continue;
                    foreach(ObjectId slId in align.GetSampleLineGroupIds())
                    {
                        var slg = (SampleLineGroup)slId.GetObject(OpenMode.ForRead);
                        if (slg.SectionViewGroups.Count < 1)
                            continue;
                        for(int i = 0; i < slg.SectionViewGroups.Count; i++)
                        {
                            var group = slg.SectionViewGroups[i];
                            foreach(ObjectId svId in group.GetSectionViewIds())
                            {
                                var sv = (CivDb.SectionView)svId.GetObject(OpenMode.ForRead);
                                foreach (var oride in sv.GraphOverrides)
                                {
                                    var section = (CivDb.Section)oride.SectionId.GetObject(OpenMode.ForRead);
                                    if (section.SourceType != SectionSourceType.PipeNetwork)
                                        continue;
                                    var alignStation = section.Station;
                                    var network = (Network)section.SourceId.GetObject(OpenMode.ForRead);
                                    var partsInView = new Dictionary<ObjectId, double>();
                                    foreach (ObjectId strucId in network.GetStructureIds())
                                    {
                                        var structure = (Structure)strucId.GetObject(OpenMode.ForRead);
                                        align.StationOffset(structure.Easting, structure.Northing, ref station, ref offset);
                                        if (Math.Abs(station - alignStation) < 0.5)//structure must be within 0.5' of section
                                        {
                                            partsInView.Add(strucId, offset);
                                        }
                                    }
                                    foreach (ObjectId pipeId in network.GetPipeIds())
                                    {
                                        var pipe = (Pipe)pipeId.GetObject(OpenMode.ForRead);
                                        //find pipes connected to 2 structures in view
                                        if (partsInView.ContainsKey(pipe.StartStructureId) && partsInView.ContainsKey(pipe.EndStructureId))
                                        {
                                            var pipeOffset = (partsInView[pipe.StartStructureId] + partsInView[pipe.EndStructureId]) / 2;
                                            partsInView.Add(pipeId, pipeOffset);
                                            continue;
                                        }
                                        //add code to find pipes with only 1 structure connected but is parallel to sample line
                                        //add code to find pipes with no structure connected but is parallel to sample line
                                    }
                                    //sort the partsInView by the offsets, this may not be needed since the index appears to always be 0
                                    var sortedDict = from entry in partsInView orderby entry.Value ascending select entry;
                                    int pipeIdx = 0, strucIdx = 0;
                                    foreach (var part in sortedDict)
                                    {
                                        if (part.Key.ObjectClass.DxfName.Contains("PIPE"))
                                        {
                                            PipeSectionLabel.Create(svId, part.Key, section.ObjectId, pipeIdx);//pipeIdx fails for any value other than 0?
                                            //pipeIdx++;
                                        }
                                        else
                                        {
                                            StructureSectionLabel.Create(svId, part.Key, section.ObjectId, strucIdx); //strucIdx fails for any value other than 0?
                                            //strucIdx++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                tr.Commit();
            }
        }