Skip to content

Commit

Permalink
implemented CreateConduitOffsets for https://forums.autodesk.com/t5/r…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremytammik committed Jan 2, 2021
1 parent 153a55b commit cb81d50
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
52 changes: 52 additions & 0 deletions BuildingCoder/BuildingCoder/CmdIntersectJunctionBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,57 @@ ElementSlowFilter intersect_junction

return Result.Succeeded;
}

#region Create Offset Conduits
void CreateConduitOffsets(
Element conduit,
double diameter,
double distance)
{
Document doc = conduit.Document;

var obj = conduit.Location as LocationCurve;
XYZ start = obj.Curve.GetEndPoint( 0 );
XYZ end = obj.Curve.GetEndPoint( 1 );
XYZ v = end - start;
double vlen = v.GetLength();

XYZ w = XYZ.BasisZ.CrossProduct( v );
XYZ start1 = start + distance * w;
XYZ start2 = start - distance * w;
XYZ start3 = start + distance * XYZ.BasisZ;
XYZ end1 = start1 + v;
XYZ end2 = start2 + v;
XYZ end3 = start3 + v;

// Confusing sample code from
// https://forums.autodesk.com/t5/revit-api-forum/offset-conduit-only-by-z-axis/m-p/9972671

var L = Math.Sqrt( (start.X - end.X) * (start.X - end.X) + (start.Y - end.Y) * (start.Y - end.Y) );
double x1startO = start.X + distance * (end.Y - start.Y) / L;
double x1endO = end.X + distance * (end.Y - start.Y) / L;
double y1startO = start.Y + distance * (start.X - end.X) / L;
double y1end0 = end.Y + distance * (start.X - end.X) / L;
Conduit conduit1 = Conduit.Create( doc, conduit.GetTypeId(), new XYZ( x1startO, y1startO, start.Z ), new XYZ( x1endO, y1end0, end.Z ), conduit.LevelId );
conduit1.get_Parameter( BuiltInParameter.RBS_CONDUIT_DIAMETER_PARAM ).Set( diameter );

double x2startO = start.X - distance * (end.Y - start.Y) / L;
double x2endO = end.X - distance * (end.Y - start.Y) / L;
double y2startO = start.Y - distance * (start.X - end.X) / L;
double y2end0 = end.Y - distance * (start.X - end.X) / L;

Conduit conduit2 = Conduit.Create( doc, conduit.GetTypeId(), new XYZ( x2startO, y2startO, start.Z ), new XYZ( x2endO, y2end0, end.Z ), conduit.LevelId );
conduit2.get_Parameter( BuiltInParameter.RBS_CONDUIT_DIAMETER_PARAM ).Set( diameter );

XYZ p0 = new XYZ( start.X - (end.Y - start.Y) * (1 / obj.Curve.ApproximateLength), start.Y + (end.X - start.X) * (1 / obj.Curve.ApproximateLength), start.Z );
XYZ p1 = new XYZ( start.X + (end.Y - start.Y) * (1 / obj.Curve.ApproximateLength), start.Y - (end.X - start.X) * (1 / obj.Curve.ApproximateLength), start.Z );

Conduit conduit3;

Curve copyCurve = obj.Curve.CreateOffset( -diameter * Math.Sqrt( 3 ) / 2, Line.CreateBound( p0, p1 ).Direction );
conduit3 = Conduit.Create( doc, conduit.GetTypeId(), copyCurve.GetEndPoint( 0 ), copyCurve.GetEndPoint( 1 ), conduit.LevelId );
conduit3.get_Parameter( BuiltInParameter.RBS_CONDUIT_DIAMETER_PARAM ).Set( diameter );
}
#endregion Create Offset Conduits
}
}
5 changes: 3 additions & 2 deletions BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@
// 2020-11-09 2021.0.150.8 implemented IsLessOrEqual and improved GetLevelFor
// 2020-11-10 2021.0.150.9 implemented ListForgeTypeIds
// 2020-11-25 2021.0.150.10 integrated simple updater sample from https://forums.autodesk.com/t5/revit-api-forum/iupdater-simple-example-needed/m-p/9893248
// 2021-01-02 2021.0.150.11 implemented CreateConduitOffsets for https://forums.autodesk.com/t5/revit-api-forum/offset-conduit-only-by-z-axis/m-p/9972671
//
[assembly: AssemblyVersion( "2021.0.150.10" )]
[assembly: AssemblyFileVersion( "2021.0.150.10" )]
[assembly: AssemblyVersion( "2021.0.150.11" )]
[assembly: AssemblyFileVersion( "2021.0.150.11" )]

0 comments on commit cb81d50

Please sign in to comment.