Civil 3D provides several ways to change the slope of pipes. You can use Prospector, right clicking and viewing the pipe's properties, grip editing the pipe or using pipe rules. Apart from the rules there is a limited number of ways to adjust the slope of a pipe run. The pipe rules, Cover and Slope, may be problematic for a run of pipes since the cover makes it difficult to get a slope at a constant grade. I did post about the availability of a Slope Only rule that I came up with for a coworker in Colorado, but nobody seemed interested in it. I'm just glad no one has asked for it recently because I think I misplaced the rule. For this post I'm going to be working outside of the rules and going with VBA.
I've covered on how to set up the VBA in pasts posts, so I'll skip it here. Once you have the VBA project set up we can go ahead and start programming. The first thing we need to do is get some information from the user.
So now that we have the pipes or structures and required slope we can modify the pipe slopes. The first thing we need to do is get the pipe application which is the AutoCAD object that contains all of the pipe information, which is borrowed from the sample file that comes with Civil 3D.
Now we need to get the pipe networks of the pipe parts selected to make sure the pipes/structures are in the same pipe network. Since we need to find it for each structure we'll use a separate Function to find the pipe network names. When using the Functions you can pass objects from the Sub to the Function and then return the value. The arrows are trying to illustrate what is being passed and where they are placed.
The code goes through all of the pipe networks in the drawing and then checks to see if the pipe or structure is included in the pipe network. So now that the pipe networks are known we can see if they are in the same network, if not the program will end using the Exit Sub.
So now we need to get all of the pipes and structures from the first pipe/structure selected and the second pipe/structure selected. To do that use the FindShortestNetworkPath method of the pipe network of the selected pipes/structures. The code below sets the pipe network and then creates an array based on what type of objects where selected (hopefully I covered all of the scenarios).
So now that we have the pipes/structures in an array the code will go through and change the slopes and elevations of the pipes. The code uses the first pipe's start elevation for the beginning elevation and then apply the elevations and slopes to the pipes. The structure's won't be changed, although they probably should be updated after adjusting the slopes and elevations. The last object selected, if it is a pipe, needs to be calculated separately since it is not included in the array for some reason.
So that's the code to do it. It could use some more code, maybe for recognizing that the pipes are going the opposite direction, but hey you don't pay for this. Here's a page that has the code as it is now: http://style.civil3dreminders.com/setpipeslopeonrun