【Revit】族及项⽬下创建拉伸,融合,放样
族:
Ps. 函数⾥⾯的ConvertToInternalUnits这个⽅法,是将毫⽶单位转成recit内部单位,这个转换可以⾃⾏转换,代码这边没有贴出来。
public static Element GetHostInstance(Document doc, CurveArrArray curveArrs, XYZ faceNormal, double start, double end, bool IsSolid = true)
{
Element element = null;
#if Revit2018
element = doc.FamilyCreate.NewExtrusion(IsSolid,
curveArrs,
SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(faceNormal, new XYZ(start * faceNormal.X,
start * faceNormal.Y, start * faceNormal.Z).ConvertToInternalUnits())),
好好学习天天向上英语Math.Abs(end - start).ConvertToInternalUnits());beatboxer
obvious是什么意思#elif Revit2019
element = doc.FamilyCreate.NewExtrusion(IsSolid, curveArrs,
SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(faceNormal, new XYZ(start * faceNormal.X, start * faceNormal.Y, start * faceNormal.Z).ConvertToInternalUnits())), Math.Abs(end - start).ConvertToInternalUnits());
#el
element = doc.FamilyCreate.NewExtrusion(IsSolid, curveArrs,
SketchPlane.Create(doc, new Plane(faceNormal, new XYZ(start * faceNormal.X, start * faceNormal.Y, start * faceNormal.Z).ConvertToInternalUnits())),
Math.Abs(end - start).ConvertToInternalUnits());
warm
#endif
return element;
}
//创建拉伸
public static Extrusion CreateExtrusion(Document doc, CurveArrArray curveArrs, XYZ faceNormal, double start, double end, bool IsSolid = true)
{
return GetHostInstance(doc, curveArrs, faceNormal, start, end, IsSolid) as Extrusion;
}
//创建融合
public static Blend CreateBlend(Document doc, CurveArray topCurves, CurveArray bottomCurves, XYZ faceNormal, double start, bool IsSolid = true)
occupywallstreet
{
var plane = CreateSketchPlane(doc, faceNormal, start);
var blend = doc.FamilyCreate.NewBlend(IsSolid, topCurves, bottomCurves, plane);netbook
return blend;
}
//创建放样
public static Sweep CreateSweep(Document doc, CurveArrArray profileArray, XYZ start, XYZ end, bool IsSolid = true)
{
XYZ xvec = new XYZ(end.X - start.X, end.Y - start.Y, 0).Normalize();
XYZ yvec = XYZ.BasisZ;
start = start.ConvertToInternalUnits();
end = end.ConvertToInternalUnits();
var plane = SketchPlane.Create(doc, CreatePlane(xvec, yvec, start));
功夫熊猫1台词SweepProfile profile = doc.Application.Create.NewCurveLoopsProfile(profileArray);
Curve curve = Line.CreateBound(start, end);
CurveArray curves = new CurveArray();
curves.Append(curve);
return doc.FamilyCreate.NewSweep(IsSolid, curves, plane, profile, 0, ProfilePlaneLocation.Start);
beman}
public static SketchPlane CreateSketchPlane(Document doc, XYZ faceNormal, XYZ origin)
{
SketchPlane element = null;
#if Revit2018
element = SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(faceNormal, origin));
#elif Revit2019
element = SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(faceNormal, origin));
#el
element = SketchPlane.Create(doc, new Plane(faceNormal, origin));
adolescent#endif
return element;
}
public static SketchPlane CreateSketchPlane(Document doc, XYZ faceNormal, double start)
{
SketchPlane element = null;
#if Revit2018
element = SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(faceNormal, new XYZ(start * faceNormal.X, start * faceNormal.Y, start * faceNormal.Z).ConvertToInternalUnits())); #elif Revit2019
element = SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(faceNormal, new XYZ(start * faceNormal.X, start * faceNormal.Y, start * faceNormal.Z).ConvertToInternalUnits())); #el
element = SketchPlane.Create(doc, new Plane(faceNormal, new XYZ(start * faceNormal.X, start * faceNormal.Y, start * faceNormal.Z).ConvertToInternalUnits()));
#endif
return element;
}
补充PS:拉伸⽅向貌似和轮廓线的⽅向有关系。
项⽬:
先来⼀段项⽬⽂档下,拉伸的测试。复制可直接⽤(需要⾃⼰开事务):
public static void CreateCubicDirectShape(Autodesk.Revit.UI.UIApplication app)
{
List<Curve> profile = new List<Curve>();
double edgeLength = 2.0;
XYZ p1 = new XYZ(edgeLength, 0, 0);
XYZ p2 = new XYZ(edgeLength, edgeLength, 0);
danny moderXYZ p3 = new XYZ(0, edgeLength, 0);
XYZ p4 = new XYZ(0, 0, 0);
profile.Add(Line.CreateBound(p1, p2));
profile.Add(Line.CreateBound(p2, p3));
profile.Add(Line.CreateBound(p3, p4));
profile.Add(Line.CreateBound(p4, p1));
CurveLoop curveLoop = CurveLoop.Create(profile);
SolidOptions options = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId);
Solid cubic = GeometryCreationUtilities.CreateExtrusionGeometry(new CurveLoop[] { curveLoop }, XYZ.BasisZ, 10);
// create direct shape and assign the sphere shape
DirectShape ds = DirectShape.CreateElement(app.ActiveUIDocument.Document, new ElementId(BuiltInCategory.OST_Floors), app.ActiveAddInId.GetGUID().ToString(), ""); ds.AppendShape(new GeometryObject[] { cubic });
edgeLength = 3.0;
p1 = new XYZ(edgeLength, 0, 0);
p2 = new XYZ(edgeLength, edgeLength, 0);
p3 = new XYZ(0, edgeLength, 0);
p4 = new XYZ(0, 0, 0);
profile = new List<Curve>();
profile.Add(Line.CreateBound(p1, p2));
profile.Add(Line.CreateBound(p2, p3));
profile.Add(Line.CreateBound(p3, p4));
profile.Add(Line.CreateBound(p4, p1));
var curveLoop2 = CurveLoop.Create(profile);
var cubic2 = GeometryCreationUtilities.CreateExtrusionGeometry(new CurveLoop[] { curveLoop2 }, -XYZ.BasisZ, 5);
ds.AppendShape(new GeometryObject[] { cubic2 });
}
以下是正式代码:
正式代码没有了。。。因为⽬前没有找到在项⽬下空⼼剪切的实现⽅法,那就没必要继续研究下去了。。