/// <summary> /// 获取线管的直径。 /// </summary> /// <param name="cd"> 线管对象 </param> /// <returns>线管的直径,单位为 inch </returns> public double?GetConduitDiameter() { Parameter pa = ConduitIns.get_Parameter(BuiltInParameter.RBS_CONDUIT_DIAMETER_PARAM); if (pa != null) { return(pa.AsDouble()); } return(null); }
/// <summary> /// Given a curve element, determine three parallel /// curves on the right, left and above, offset by /// a given radius or half diameter. /// </summary> void CreateConduitOffsets( Element conduit, double diameter, double distance) { Document doc = conduit.Document; // Given element location curve var obj = conduit.Location as LocationCurve; XYZ start = obj.Curve.GetEndPoint(0); XYZ end = obj.Curve.GetEndPoint(1); XYZ vx = end - start; // Offsets double radius = 0.5 * diameter; double offset_lr = radius; double offset_up = radius * Math.Sqrt(3); // Assume vx is horizontal to start with XYZ vz = XYZ.BasisZ; XYZ vy = vz.CrossProduct(vx); XYZ start1 = start + offset_lr * vy; XYZ start2 = start - offset_lr * vy; XYZ start3 = start + offset_up * vz; XYZ end1 = start1 + vx; XYZ end2 = start2 + vx; XYZ end3 = start3 + vx; // 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); }