Skip to content

Commit

Permalink
create rolling offset pipe using static Pipe.Create method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Tammik committed Jan 24, 2014
1 parent 21f7e60 commit 770c084
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 40 deletions.
217 changes: 180 additions & 37 deletions BuildingCoder/BuildingCoder/CmdRollingOffset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// CmdRollingOffset.cs - calculate a rolling offset pipe segment between two existing pipes and hook them up
//
// Copyright (C) 2013 by Jeremy Tammik, Autodesk Inc. All rights reserved.
// Copyright (C) 2013-2014 by Jeremy Tammik, Autodesk Inc. All rights reserved.
//
#endregion // Header

Expand Down Expand Up @@ -45,7 +45,7 @@ class CmdRollingOffset : IExternalCommand
/// method and the obsolete
/// Document.Create.NewPipe.
/// </summary>
static bool _use_static_pipe_create = false;
static bool _use_static_pipe_create = true;

const string _prompt
= "Please run this in a model containing "
Expand All @@ -59,9 +59,8 @@ const string _prompt
const BuiltInParameter bipDiameter
= BuiltInParameter.RBS_PIPE_DIAMETER_PARAM;


/// <summary>
/// Allow selection of curve elements only.
/// Allow selection of pipe elements only.
/// </summary>
class PipeElementSelectionFilter : ISelectionFilter
{
Expand Down Expand Up @@ -460,67 +459,211 @@ FamilySymbol symbol
{
if( _use_static_pipe_create )
{
ElementId idSystem = pipe.MEPSystem.Id; // invalid
ElementId idType = pipe.PipeType.Id;
ElementId idLevel = pipe.LevelId;
// Element id arguments to Pipe.Create.

idSystem = ElementId.InvalidElementId; // invalid
ElementId idSystem;
ElementId idType;
ElementId idLevel;

PipingSystem system = PipingSystem.Create(
doc, pipe.MEPSystem.GetTypeId(), "Tbc" );
// All these values are invalid for idSystem:

idSystem = system.Id; // invalid
ElementId idSystem1 = pipe.MEPSystem.Id;
ElementId idSystem2 = ElementId.InvalidElementId;
ElementId idSystem3 = PipingSystem.Create(
doc, pipe.MEPSystem.GetTypeId(), "Tbc" )
.Id;

// 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 );
//pipe = Pipe.Create( doc, idSystem,
// idType, idLevel, q0, q1 );

// Retrieve pipe system type, e.g.
// hydronic supply.

PipingSystemType pipingSystemType
= new FilteredElementCollector( doc )
.OfClass( typeof( PipingSystemType ) )
.OfType<PipingSystemType>()
.FirstOrDefault( st
=> st.SystemClassification
== MEPSystemClassification
.SupplyHydronic );

if( null == pipingSystemType )
{
message = "Could not find hydronic supply piping system type";
return Result.Failed;
}

idSystem = pipingSystemType.Id;

Debug.Assert( pipe.get_Parameter(
BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM )
.AsElementId().IntegerValue.Equals(
idSystem.IntegerValue ),
"expected same piping system element id" );

// Retrieve the PipeType.

PipeType pipeType =
new FilteredElementCollector( doc )
.OfClass( typeof( PipeType ) )
.OfType<PipeType>()
.FirstOrDefault();

if( null == pipeType )
{
message = "Could not find pipe type";
return Result.Failed;
}

idType = pipeType.Id;

Debug.Assert( pipe.get_Parameter(
BuiltInParameter.ELEM_TYPE_PARAM )
.AsElementId().IntegerValue.Equals(
idType.IntegerValue ),
"expected same pipe type element id" );

Debug.Assert( pipe.PipeType.Id.IntegerValue
.Equals( idType.IntegerValue ),
"expected same pipe type element id" );

// Retrieve the reference level.
// pipe.LevelId is not the correct source!

idLevel = pipe.get_Parameter(
BuiltInParameter.RBS_START_LEVEL_PARAM )
.AsElementId();

// Create the rolling offset pipe.

pipe = Pipe.Create( doc,
idSystem, idType, idLevel, q0, q1 );
}
else
{
pipe = doc.Create.NewPipe( q0, q1,
pipe_type_standard );
}

pipe.get_Parameter( bipDiameter )
.Set( diameter );
pipe.get_Parameter( bipDiameter )
.Set( diameter );

// Connect rolling offset pipe segment
// directly with the neighbouring original
// pipes
//
//Util.Connect( q0, pipes[0], pipe );
//Util.Connect( q1, pipe, pipes[1] );
// Connect rolling offset pipe segment
// directly with the neighbouring original
// pipes
//
//Util.Connect( q0, pipes[0], pipe );
//Util.Connect( q1, pipe, pipes[1] );

// NewElbowFitting performs the following:
// - select appropriate fitting family and type
// - place and orient a family instance
// - set its parameters appropriately
// - connect it with its neighbours
// NewElbowFitting performs the following:
// - select appropriate fitting family and type
// - place and orient a family instance
// - set its parameters appropriately
// - connect it with its neighbours

Connector con0 = Util.GetConnectorClosestTo(
pipes[0], q0 );
Connector con0 = Util.GetConnectorClosestTo(
pipes[0], q0 );

Connector con = Util.GetConnectorClosestTo(
pipe, q0 );
Connector con = Util.GetConnectorClosestTo(
pipe, q0 );

doc.Create.NewElbowFitting( con0, con );
doc.Create.NewElbowFitting( con0, con );

Connector con1 = Util.GetConnectorClosestTo(
pipes[1], q1 );
Connector con1 = Util.GetConnectorClosestTo(
pipes[1], q1 );

con = Util.GetConnectorClosestTo(
pipe, q1 );
con = Util.GetConnectorClosestTo(
pipe, q1 );

doc.Create.NewElbowFitting( con, con1 );
}
doc.Create.NewElbowFitting( con, con1 );
}

tx.Commit();
}
return Result.Succeeded;
}

#region Victor's Code
Result f(
UIDocument uidoc,
Document doc )
{
string message = string.Empty;

// Extract all pipe system types

var mepSystemTypes
= new FilteredElementCollector( doc )
.OfClass( typeof( PipingSystemType ) )
.OfType<PipingSystemType>()
.ToList();

// Get the Domestic hot water type

var domesticHotWaterSystemType =
mepSystemTypes.FirstOrDefault(
st => st.SystemClassification ==
MEPSystemClassification.DomesticHotWater );

if( domesticHotWaterSystemType == null )
{
message = "Could not found Domestic Hot Water System Type";
return Result.Failed;
}

// Looking for the PipeType

var pipeTypes =
new FilteredElementCollector( doc )
.OfClass( typeof( PipeType ) )
.OfType<PipeType>()
.ToList();

// Get the first type from the collection

var firstPipeType =
pipeTypes.FirstOrDefault();

if( firstPipeType == null )
{
message = "Could not found Pipe Type";
return Result.Failed;
}

var level = uidoc.ActiveView.GenLevel;

if( level == null )
{
message = "Wrong Active View";
return Result.Failed;
}

var startPoint = XYZ.Zero;

var endPoint = new XYZ( 100, 0, 0 );

using( var t = new Transaction( doc ) )
{
t.Start( "Create pipe using Pipe.Create" );

var pipe = Pipe.Create( doc,
domesticHotWaterSystemType.Id,
firstPipeType.Id,
level.Id,
startPoint,
endPoint );

t.Commit();
}
Debug.Print( message );
return Result.Succeeded;
}
#endregion // Victor's Code
}
}

Expand Down
6 changes: 3 additions & 3 deletions BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration( "" )]
[assembly: AssemblyCompany( "Autodesk, Inc." )]
[assembly: AssemblyProduct( "BuildingCoder" )]
[assembly: AssemblyCopyright( "Copyright © 2008-2013 by Jeremy Tammik, Autodesk, Inc." )]
[assembly: AssemblyCopyright( "Copyright © 2008-2014 by Jeremy Tammik, Autodesk, Inc." )]
[assembly: AssemblyTrademark( "" )]
[assembly: AssemblyCulture( "" )]

Expand All @@ -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.5" )]
[assembly: AssemblyFileVersion( "2014.0.106.5" )]
[assembly: AssemblyVersion( "2014.0.106.6" )]
[assembly: AssemblyFileVersion( "2014.0.106.6" )]

0 comments on commit 770c084

Please sign in to comment.