Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Profile View Bands

13 REPLIES 13
Reply
Message 1 of 14
Civil3DReminders_com
2046 Views, 13 Replies

Profile View Bands

I'm having difficulty adding bands to a profile view in Civil 3D 2013 in that the bands appear to be come corrupt in not showing the data (the check box to show is unselected, even if I set it to show) and when I go into the UI and turn the bands to show the bands don't show the information correctly. 

 

                Alignment align = profileView.AlignmentId.GetObject(OpenMode.ForRead) as Alignment;
                Profile prof = profObjId.GetObject(OpenMode.ForRead) as Profile;

                if (!profileView.IsWriteEnabled)
                    profileView.UpgradeOpen();

                profileView.StyleId = profViewStyleObjId;

                ProfileViewBandItemCollection bottomBandItems = profileView.Bands.GetBottomBandItems();
                ProfileViewBandItemCollection topBandItems = profileView.Bands.GetTopBandItems();

                bottomBandItems.RemoveAll();
                topBandItems.RemoveAll();

                profileView.Bands.ImportBandSetStyle(profileBandSetId);
                bottomBandItems = profileView.Bands.GetBottomBandItems();
                topBandItems = profileView.Bands.GetTopBandItems();

                profileView.Bands.SetBottomBandItems(bottomBandItems);
                profileView.Bands.SetTopBandItems(topBandItems);

 

Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
13 REPLIES 13
Message 2 of 14

Hi,

 

This should have worked.

Are you trying this code snippet inside a Transaction? and Are you committing the Transaction ?

 

Thanks,

 

 



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Message 3 of 14

Here is some complete code that you can try.

 

        [CommandMethod("TestBands")]
        public void TestBandsIn2013()
        {
            Database db = Application.DocumentManager.MdiActiveDocument.Database;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                // Select the Profile View
                var promptResultsPV = ed.GetEntity("Select Profile View");
                var promptResultProfile = ed.GetEntity("Select Profile: ");
                // Add the profile to the profile view.
                ProfileView testPV = promptResultsPV.ObjectId.GetObject(OpenMode.ForWrite) as ProfileView;

                ProfileViewBandItemCollection bottomBandItems = testPV.Bands.GetBottomBandItems();
                ProfileViewBandItemCollection topBandItems = testPV.Bands.GetTopBandItems();

                bottomBandItems.RemoveAll();
                topBandItems.RemoveAll();

                var civDoc = CivilApplication.ActiveDocument;

                testPV.Bands.ImportBandSetStyle(civDoc.Styles.ProfileViewBandSetStyles[0]);
                bottomBandItems = testPV.Bands.GetBottomBandItems();
                topBandItems = testPV.Bands.GetTopBandItems();

                foreach (ProfileViewBandItem bandItem in bottomBandItems)
                {
                    switch (bandItem.BandType)
                    {
                        case Autodesk.Civil.BandType.HorizontalGeometry:
                            bandItem.Profile1Id = promptResultProfile.ObjectId;
                            break;
                        case Autodesk.Civil.BandType.PipeNetwork:
                            //if (PipeNetworkObjId != ObjectId.Null)
                            //{
                            //    bandItem.DataSourceId = PipeNetworkObjId;
                            //}
                            break;
                        case Autodesk.Civil.BandType.ProfileData:
                            bandItem.Profile1Id = promptResultProfile.ObjectId;
                            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 = promptResultProfile.ObjectId;
                            break;
                        default:
                            break;
                    }
                }

                testPV.Bands.SetBottomBandItems(bottomBandItems);
                testPV.Bands.SetTopBandItems(topBandItems);
                
                //testPV.AddProfileToBand(promptResultProfile.ObjectId, invertHelper.ProfileViewBandNames,
                //                                       invertHelper.ProfViewBandSetStyle.ObjId, PipeNetworkObjId, invertHelper.ProfileViewStyle.ObjId);


                trans.Commit();
            }
        }

 Attached is a drawing that you can run the code on. Select the profile view and then the profile. The band is updated with the bandset, but the bands are set to not show up. I find that I get different results when the band set only has one band in it (it shows it correctly), but having more then one band appears to lead to the issues.

Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
Message 4 of 14

Other than the pasting of the code mangled it a bit, I'm seeing the incorrect results, too, in 2014.
Jeff_M, also a frequent Swamper
EESignature
Message 5 of 14
Partha.Sarkar
in reply to: Jeff_M

Hi Chris / Jeff,

 

I tried the following code snippet in Civil 3D 2014 on a Civil 3D sample dwg file ( Profile-6B.dwg).

I removed the Profile view topbands before I run my following C# .NEt code sample. I find the bands are added with proper data. 

Am I missing something here ?

 

My C# .NET code snippet :

 

       

//select a profile view

       

Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

       

PromptEntityOptions peo = newPromptEntityOptions("\nSelect a profile view: ");

        peo.SetRejectMessage(

"\nSelect only profile views");

        peo.AddAllowedClass(

typeof(ProfileView), true);

       

PromptEntityResult per = ed.GetEntity(peo);

       

if (per.Status != PromptStatus.OK) return;

       

ObjectId pvId = per.ObjectId;

       

Database db = AcadApp.DocumentManager.MdiActiveDocument.Database;

       

using (Transaction trans = db.TransactionManager.StartTransaction())

        {

         

CivilDocument civilDoc = CivilApplication.ActiveDocument;

         

//open the profile view

         

ProfileView pv = trans.GetObject(pvId, OpenMode.ForWrite) asProfileView;

         

//get the style of the first Bottom Bands

         

ObjectId bandStyleId = pv.Bands.GetBottomBandItems()[0].BandStyleId;

         

//now access the collection of top band

         

ProfileViewBandItemCollection topBandItems = pv.Bands.GetTopBandItems();

         

//add a new one (using the above style)

          topBandItems.Add(bandStyleId);

         

//now Set the Top Bands

          pv.Bands.SetTopBandItems(topBandItems);

          trans.Commit();

 

 

Screenshot before I add the Profile View Top band :

 

 Civil_3D_ProfileView_TopBand_Empty.png

 

 

Screenshot after I added the Profile View Top band using the above code snippet :

 

Civil_3D_ProfileView_TopBand_API.png

 

Thanks,



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Message 6 of 14

Partha,

 

I want to add the entire an entire band set with multiple bands. It works correctly with one band, but add four to the mix and it quickly goes downhill. Also I'm adding an entire band set at once, not one at a time. I'll try adding the bands one at a time, but it seems like the code is going to be slow, especially if I have to add the bands in seperate transactions just so Civil 3D doesn't screw up the bands. I'd prefer not to code around bugs and would like to see the bug fixed.

Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
Message 7 of 14

Partha,

 

This won't really work. After adding the bands I have to go back and set ALL of the settings to match what was in the band set style. This includes weeding, gap, profile locations to label, etc... This is a severe bug for the API to have. I'd prefer Autodesk spend the time fixing the bug then me spending 4 to 8 hours working around it.

Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
Message 8 of 14

Ok, I will investigate this further.

 

Thanks,

Partha



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Message 9 of 14

Getting issue as Wrong type object ID when used this on Civil 3D 2016

bandItem.Profile1Id = promptResultProfile.ObjectId;

When we assign the ObjectID to Profile1ID am getting error. Tried assigining other ID's as well but it still persists.

 

Rgds,

Amit 

Senior Software Engineer
Message 10 of 14

Message 11 of 14
TimYarris
in reply to: Jeff_M

Hi Jeff,

We're in the process of fixing issues and adding new functionality to the API. We'll add this one to the list.

Thanks for your patience.

Message 12 of 14
bkanther
in reply to: TimYarris

Lol really enjoying the 12 years of history of API struggles I have read now that i am myself deep in the civil 3d API.. thanks for saving me probably 12 hours @Jeff_M. and @TimYarris  + 1 

Message 13 of 14
quangpt.tric
in reply to: Jeff_M

Hi @Jeff_M  and @Civil3DReminders_com ,

For now at 24/9/2022, I try to change Banset by ImportBandSetStyle(), It already change, but it still not show any information.

Hope Autodesk can fix it.

quangpttric_0-1664031911551.png

 

Message 14 of 14

Found some workaround for this one, seems to work fine

 

 

 

ProfileView PV = (ProfileView)pvId.GetObject(OpenMode.ForWrite);
PV.Bands.ImportBandSetStyle(civilDoc.Styles.ProfileViewBandSetStyles["Something"]);
ProfileViewBandItemCollection pvBic = new ProfileViewBandItemCollection(PV.Id,BandLocationType.Bottom);
                    ProfileViewBandItemCollection bottomBandItems = PV.Bands.GetBottomBandItems();
                    foreach (ProfileViewBandItem item in bottomBandItems)
                    {
                        pvBic.Add(item.BandStyleId);
                    }
                    bottomBandItems.RemoveAll();
                    foreach(ProfileViewBandItem item in pvBic)
                    {
                        if (item.BandType == BandType.PipeNetwork)
                        {
                            item.DataSourceId = Net.Id;
                        }
                    }
                    PV.Bands.SetBottomBandItems(pvBic);

 

 

 

long story short - create new ProfileViewBandItemCollection from ProfileView u created before. It will be empty, so u'll need to fill it with bands that u can grab from ProfileView u created before:)

Then go through ur new collection and set sources for bands and if u set this new collection to a ProfileView - data will be on place.

Dont forget to set another settings like gap or weeding.

 

Looks odd, but works and fast enough.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report