Skip to content

Commit

Permalink
creating a rolling offset pipe between two pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Tammik committed Jan 10, 2014
1 parent 4ecbe00 commit 1e1f104
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 12 deletions.
93 changes: 83 additions & 10 deletions BuildingCoder/BuildingCoder/CmdRollingOffset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ namespace BuildingCoder
[Transaction( TransactionMode.Manual )]
class CmdRollingOffset : IExternalCommand
{
/// <summary>
/// This command can place either a model line
/// to represent the rolling offset calculation
/// result, or insert a real pipe segment and the
/// associated fittings.
/// </summary>
static bool _place_model_line = false;

/// <summary>
/// Switch between the new static Pipe.Create
/// method and the obsolete
/// Document.Create.NewPipe.
/// </summary>
static bool _use_static_pipe_create = false;

const string _prompt
= "Please run this in a model containing "
+ "exactly two parallel offset pipe elements, "
Expand Down Expand Up @@ -260,21 +275,78 @@ double remainingPipeLength
{
tx.Start( "Rolling Offset" );

// Trim or extend existing pipes
if( _place_model_line )
{
// Trim or extend existing pipes

( pipes[0].Location as LocationCurve ).Curve
= Line.CreateBound( p0, q0 );

( pipes[1].Location as LocationCurve ).Curve
= Line.CreateBound( p1, q1 );

// Add a model line for the rolling offset pipe

( pipes[0].Location as LocationCurve ).Curve
= Line.CreateBound( p0, q0 );
Creator creator = new Creator( doc );

( pipes[1].Location as LocationCurve ).Curve
= Line.CreateBound( p1, q1 );
Line line = Line.CreateBound( q0, q1 );

// Add a model line for the rolling offset pipe
creator.CreateModelCurve( line );
}
else
{
Pipe pipe = pipes[0];

if( _use_static_pipe_create )
{
ElementId idSystem = pipe.MEPSystem.Id; // invalid
ElementId idType = pipe.PipeType.Id;
ElementId idLevel = pipe.LevelId;

idSystem = ElementId.InvalidElementId; // invalid

Creator creator = new Creator( doc );
PipingSystem system = PipingSystem.Create(
doc, pipe.MEPSystem.GetTypeId(), "Tbc" );

Line line = Line.CreateBound( q0, q1 );
idSystem = system.Id; // invalid

creator.CreateModelCurve( line );
// This throws an argument exception saying
// The systemTypeId is not valid piping system type.
// Parameter name: systemTypeId

pipe = Pipe.Create( doc, idSystem,
idType, idLevel, q0, q1 );
}
else
{
BuiltInParameter bip
= BuiltInParameter.RBS_PIPE_DIAMETER_PARAM;

double diameter = pipe
.get_Parameter( bip ) // "Diameter"
.AsDouble();

PipeType pipe_type_standard
= new FilteredElementCollector( doc )
.OfClass( typeof( PipeType ) )
.Cast<PipeType>()
.Where<PipeType>( e
=> e.Name.Equals( "Standard" ) )
.FirstOrDefault<PipeType>();

Debug.Assert(
pipe_type_standard.Id.IntegerValue.Equals(
pipe.PipeType.Id.IntegerValue ),
"expected all pipes in this simple "
+ "model to use the same pipe type" );

pipe = doc.Create.NewPipe( q0, q1,
pipe_type_standard );

pipe.get_Parameter( bip )
.Set( diameter );
}
}

tx.Commit();
}
Expand All @@ -283,4 +355,5 @@ double remainingPipeLength
}
}

// Z:\a\rvt\rolling_offset.rvt
// Z:\a\rvt\rolling_offset.rvt
// /a/j/adn/case/bsd/1264642/attach/PipeTest.cs
4 changes: 2 additions & 2 deletions BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion( "2014.0.106.1" )]
[assembly: AssemblyFileVersion( "2014.0.106.1" )]
[assembly: AssemblyVersion( "2014.0.106.2" )]
[assembly: AssemblyFileVersion( "2014.0.106.2" )]

0 comments on commit 1e1f104

Please sign in to comment.