Skip to content

Commit

Permalink
converted CmdNewSweptBlend to use manual transaction mode and impleme…
Browse files Browse the repository at this point in the history
…nted CreateNewSweptBlendArc
  • Loading branch information
Jeremy Tammik committed Nov 10, 2014
1 parent 3212bdd commit 487148e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 9 deletions.
91 changes: 82 additions & 9 deletions BuildingCoder/BuildingCoder/CmdNewSweptBlend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace BuildingCoder
{
[Transaction( TransactionMode.Automatic )]
[Transaction( TransactionMode.Manual )]
class CmdNewSweptBlend : IExternalCommand
{
/// <summary>
Expand All @@ -31,19 +31,23 @@ SketchPlane CreateSketchPlane(
{
Application app = doc.Application;

// create a Geometry.Plane required by the NewSketchPlane() method
// Create a Geometry.Plane required by the
// NewSketchPlane() method

Plane geometryPlane = app.Create.NewPlane(
normal, origin );

Plane geometryPlane = app.Create.NewPlane( normal, origin );
if( null == geometryPlane )
{
throw new Exception( "Geometry plane creation failed." );
}

// create a sketch plane using the Geometry.Plane
// Create a sketch plane using the Geometry.Plane

//SketchPlane plane = doc.FamilyCreate.NewSketchPlane( geometryPlane ); // 2013

SketchPlane plane = SketchPlane.Create( doc, geometryPlane ); // 2014
SketchPlane plane = SketchPlane.Create(
doc, geometryPlane ); // 2014

if( null == plane )
{
Expand Down Expand Up @@ -125,7 +129,67 @@ SweepProfile sweepProfile1
{
Util.ErrorMsg( "NewSweptBlend exception: " + ex.Message );
}
return;
}

/// <summary>
/// Create a new swept blend form using arcs to
/// define circular start and end profiles and an
/// arc path. The NewSweptBlend method requires
/// the input profiles to be in the XY plane.
/// </summary>
public void CreateNewSweptBlendArc( Document doc )
{
Debug.Assert( doc.IsFamilyDocument,
"this method will only work in a family document" );

Application app = doc.Application;

Autodesk.Revit.Creation.Application creapp
= app.Create;

Autodesk.Revit.Creation.FamilyItemFactory credoc
= doc.FamilyCreate;

XYZ px = XYZ.BasisX;
XYZ py = XYZ.BasisY;
Arc arc1 = Arc.Create( -px, px, -py );
Arc arc2 = Arc.Create( px, -px, py );
CurveArray arr1 = new CurveArray();
arr1.Append( arc1 );
arr1.Append( arc2 );
CurveArrArray arrarr1 = new CurveArrArray();
arrarr1.Append( arr1 );

SweepProfile bottomProfile
= creapp.NewCurveLoopsProfile( arrarr1 );

px += px;
py += py;
Arc arc3 = Arc.Create( -px, px, -py );
Arc arc4 = Arc.Create( px, -px, py );
CurveArray arr2 = new CurveArray();
arr2.Append( arc3 );
arr2.Append( arc4 );
CurveArrArray arrarr2 = new CurveArrArray();
arrarr2.Append( arr2 );

SweepProfile topProfile
= creapp.NewCurveLoopsProfile( arrarr2 );

XYZ p0 = XYZ.Zero;
XYZ p5 = 5 * XYZ.BasisY;
XYZ pmid = new XYZ( 2.5, 2.5, 0 );
Arc testArc = Arc.Create( p0, p5, pmid );

Plane geometryPlane = creapp.NewPlane(
XYZ.BasisZ, XYZ.Zero );

SketchPlane sketchPlane = SketchPlane.Create(
doc, geometryPlane );

SweptBlend aSweptBlend = credoc.NewSweptBlend(
true, testArc, sketchPlane, bottomProfile,
topProfile );
}

public Result Execute(
Expand All @@ -138,13 +202,22 @@ public Result Execute(

if( doc.IsFamilyDocument )
{
CreateNewSweptBlend( doc );
using( Transaction tx = new Transaction( doc ) )
{
tx.Start( "Create New Swept Blend" );

CreateNewSweptBlend( doc );
CreateNewSweptBlendArc( doc );

tx.Commit();

return Result.Succeeded;
return Result.Succeeded;
}
}
else
{
message = "Please run this command in a family document.";
message
= "Please run this command in a family document.";

return Result.Failed;
}
Expand Down
1 change: 1 addition & 0 deletions BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
// 2014-10-16 2015.0.114.3 added pipe wall thickness determination to CmdRollingOffset
// 2014-10-11 2015.0.115.0 implemented CmdNewCrossFitting
// 2014-10-11 2015.0.115.1 fixed some of the warnings about deprecated use of Selection.Elements collection
// 2014-11-10 2015.0.115.2 converted CmdNewSweptBlend to use manual transaction mode and implemented CreateNewSweptBlendArc
//
[assembly: AssemblyVersion( "2015.0.115.1" )]
[assembly: AssemblyFileVersion( "2015.0.115.1" )]

0 comments on commit 487148e

Please sign in to comment.