Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Autodesk.Revit.Creation.Application app = commandData.Application.Application.Create;
Document doc = commandData.Application.ActiveUIDocument.Document;
using (Transaction tran = new Transaction(doc, "Test"))
{
tran.Start();
//ElementId id = doc.GetElement(new ElementId(1)).Id;
CreateNewSweptBlend(commandData.Application.ActiveUIDocument.Document);
tran.Commit();
return Result.Succeeded;
}
}
public void CreateNewSweptBlend( Document doc )
{
var app = doc.Application;
Autodesk.Revit.Creation.Application creapp
= app.Create;
CurveArrArray curvess0
= creapp.NewCurveArrArray();
CurveArray curves0 = new CurveArray();
XYZ p00 = creapp.NewXYZ( 0, 7.5, 0 );
XYZ p01 = creapp.NewXYZ( 0, 15, 0 );
// changing Z to 1 in the following line fails:
XYZ p02 = creapp.NewXYZ( -1, 10, 0 );
curves0.Append( Line.CreateBound( p00, p01 ) );
curves0.Append( Line.CreateBound( p01, p02 ) );
curves0.Append( Line.CreateBound( p02, p00 ) );
curvess0.Append( curves0 );
CurveArrArray curvess1 = creapp.NewCurveArrArray();
CurveArray curves1 = new CurveArray();
XYZ p10 = creapp.NewXYZ( 7.5, 0, 0 );
XYZ p11 = creapp.NewXYZ( 15, 0, 0 );
// changing the Z value in the following line fails:
XYZ p12 = creapp.NewXYZ( 10, -1, 0 );
curves1.Append( Line.CreateBound( p10, p11 ) );
curves1.Append( Line.CreateBound( p11, p12 ) );
curves1.Append( Line.CreateBound( p12, p10 ) );
curvess1.Append( curves1 );
SweepProfile sweepProfile0
= creapp.NewCurveLoopsProfile( curvess0 );
SweepProfile sweepProfile1
= creapp.NewCurveLoopsProfile( curvess1 );
XYZ pnt10 = new XYZ( 5, 0, 0 );
XYZ pnt11 = new XYZ( 0, 20, 0 );
Curve curve = Line.CreateBound( pnt10, pnt11 );
XYZ normal = XYZ.BasisZ;
Plane plane = Plane.CreateByNormalAndOrigin(normal, new XYZ(0, 0, 0));
SketchPlane splane = SketchPlane.Create(doc,plane);
try
{
SweptBlend sweptBlend = doc.FamilyCreate.NewSweptBlend(
true, curve, splane, sweepProfile0, sweepProfile1 );
}
catch( Exception ex )
{
MessageBox.Show(ex.ToString());
}
}
@chuongmep
Copy link
Author

chuongmep commented Jun 20, 2022

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment