I'm stuck. I'm trying to add assign a Pipe Network to a profile view Band in Civil 3D 2011. I was using COM to add profiles to bands because I couldn't figure out how to do it in .NET. But when it comes to pipe networks I don't see how you can do that with COM. Does anyone have some code for how the .NET implementation is supposed to work? Here's the code I have that works for COM, except for the pipe networks. I essentially need to assign the correct pipe network to the band.
Thank you,
public static void AddProfileToBand(this ProfileView profileView, ObjectId profObjId, List<BandItemInfo> bandStyleInfosFromSet, ObjectId profileBandSetId) { using (Transaction tr = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()) { try { Alignment align = profileView.AlignmentId.GetObject(OpenMode.ForRead) as Alignment; AeccAppConnection aecApp = new AeccAppConnection(); AeccAlignment alignCOM = aecApp.AeccDoc.AlignmentsSiteless.Item(align.Name); AeccProfileView profViewCOM = alignCOM.ProfileViews.Item(profileView.Name); Profile prof = profObjId.GetObject(OpenMode.ForRead) as Profile; AeccProfile profCOM = alignCOM.Profiles.Item(prof.Name); // Remove the existing bands. while (profViewCOM.BandSet.Count > 0) { profViewCOM.BandSet.Remove(0); } profileView.UpgradeOpen(); profileView.Bands.ImportBandSetStyle(profileBandSetId); // Add them back in, this is if the user hasn't added them in. //foreach (var bandStyleInfo in bandStyleInfosFromSet) //{ // try // { // AeccBandStyle bandStyleCom = null; // switch (bandStyleInfo.BandStyleType) // { // case BandStyleType.HorizontalGeometry: // bandStyleCom = aecApp.AeccDb.ProfileViewBandStyles.HorizontalGeometryBandStyles[bandStyleInfo.Name] as AeccBandStyle; // break; // case BandStyleType.PipeNetwork: // // Not present in COM???? // ObjectId bandStyleObjId = GetPipeNetworkBandStyleObjId(bandStyleInfo.Name); // BandStyle bandStyle = bandStyleObjId.GetObject(OpenMode.ForRead) as BandStyle; // bandStyleCom = bandStyle.AcadObject as AeccBandStyle; // break; // case BandStyleType.ProfileData: // bandStyleCom = aecApp.AeccDb.ProfileViewBandStyles.ProfileDataBandStyles[bandStyleInfo.Name] as AeccBandStyle; // break; // case BandStyleType.SuperelevationData: // bandStyleCom = aecApp.AeccDb.ProfileViewBandStyles.SuperElevationBandStyles[bandStyleInfo.Name] as AeccBandStyle; // break; // case BandStyleType.VerticalGeometry: // bandStyleCom = aecApp.AeccDb.ProfileViewBandStyles.VerticalGeometryBandStyles[bandStyleInfo.Name] as AeccBandStyle; // break; // default: // break; // } // if (bandStyleCom != null) // profViewCOM.BandSet.Add(bandStyleCom, alignCOM, profCOM, profCOM); // else // { // Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; // ed.WriteMessage("\nError in adding band to profile view: " + bandStyleInfo.Name + "\n"); // } // } // catch (Exception ex) // { // Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; // ed.WriteMessage("\nError in adding band to profile view: " + ex.Message + "\n"); // } //} foreach (AeccProfileViewBandSetItem band in profViewCOM.BandSet) { try { if (HasName(bandStyleInfosFromSet, band.BandStyle.Name) && band.BandStyle.Type == AeccBandStyleType.aeccProfileDataBandStyle) { band.Profile1 = profCOM; } } catch (Exception) { } } tr.Commit(); } catch (System.Exception ex) { Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("\nError in adding profile to band: " + ex.Message + "\n"); } } } private static bool HasName(List<BandItemInfo> bandStyleInfosFromSet, string name) { return (bandStyleInfosFromSet.Where(x => x.Name == name).Count() > 0); } private static ObjectId GetPipeNetworkBandStyleObjId(string name) { CivilDocument civDoc = CivilApplication.ActiveDocument; ObjectId bandStyleObjId = civDoc.Styles.BandStyles.ProfileViewPipeNetworkBandStyles.Where(x => (x.GetObject(OpenMode.ForRead) as BandStyle).Name == name).FirstOrDefault(); return bandStyleObjId; }
Solved! Go to Solution.
Solved by Civil3DReminders_com. Go to Solution.
Well I finally figured it out, one has to Set the ProfileViewBandItems after Getting it and then adding the profile or data source.
http://blog.civil3dreminders.com/2013/03/modifying-profile-view-bands.html
I have the same problem with bandset for sectionview.
Did you have import bandset for sectionview?
I use this medthod: sectionView.Bands.ImportBandSetStyle(bandstyle.Id);
it work well in Civil 3d 2023, but another version, it doesn't work.
Can you help me to sovled it?
c# tip 🙂
HasName method
private static bool HasName(List<BandItemInfo> bandStyleInfosFromSet, string name)
{
return bandStyleInfosFromSet.Any(x => x.Name == name);
}
I think the API change was made in Civil 3D 2020 Update 5. This is the only code that I've been using for updating the section view bands.
Can you share me the function of "UpdateBandProfileAndDataSource" as picture below?
Thank you!
This is the one I found first.
private static void UpdateBandProfileAndDataSource(ObjectId PipeNetworkObjId, Profile prof, ProfileViewBandItemCollection bottomBandItems, ObjectId prof2ObjId)
{
foreach (ProfileViewBandItem bandItem in bottomBandItems)
{
switch (bandItem.BandType)
{
case Autodesk.Civil.BandType.HorizontalGeometry:
bandItem.Profile1Id = prof.ObjectId;
if (!prof2ObjId.IsNull)
{
bandItem.Profile2Id = prof2ObjId;
}
break;
case Autodesk.Civil.BandType.PipeNetwork:
if (PipeNetworkObjId != ObjectId.Null)
{
bandItem.DataSourceId = PipeNetworkObjId;
}
break;
case Autodesk.Civil.BandType.ProfileData:
bandItem.Profile1Id = prof.ObjectId;
if (!prof2ObjId.IsNull)
{
bandItem.Profile2Id = prof2ObjId;
}
break;
case Autodesk.Civil.BandType.SectionData:
break;
case Autodesk.Civil.BandType.SectionSegment:
break;
case Autodesk.Civil.BandType.SectionalData:
break;
case Autodesk.Civil.BandType.SuperelevationData:
break;
case Autodesk.Civil.BandType.VerticalGeometry:
bandItem.Profile1Id = prof.ObjectId;
if (!prof2ObjId.IsNull)
{
bandItem.Profile2Id = prof2ObjId;
}
break;
default:
break;
}
bandItem.ShowLabels = true;
}
}