/// <summary> /// Sets the material's base texture. /// </summary> /// <param name="material"></param> /// <param name="angle"></param> /// <param name="offset"></param> /// <param name="size"></param> /// <param name="initAngle"></param> public static void SetTextureBase(this Material material, double angle, double[] offset, double[] size, TextureAngle initAngle) { if (offset == null || offset.Length == 0) { return; } if (size == null || size.Length == 0) { return; } angle += (int)initAngle; angle %= 360; if (angle < 0) { throw new InvalidDataException(nameof(angle)); } material.SetTextureBase(angle, offset, size); }
/// <summary> /// Divide part list for element. /// </summary> /// <param name="elm"></param> /// <param name="origin"></param> /// <param name="baseX"></param> /// <param name="step"></param> /// <param name="initAngle"></param> /// <param name="radius"></param> public static void DividePartList(this Element elm, XYZ origin, XYZ baseX, double[] step, TextureAngle initAngle, double radius = 5000) { if (elm is null) { throw new ArgumentNullException(nameof(elm)); } if (origin is null) { throw new ArgumentNullException(nameof(origin)); } if (baseX is null) { throw new ArgumentNullException(nameof(baseX)); } if (step[0] < 0) { throw new ArgumentException(nameof(step)); } if (step[1] < 0) { throw new ArgumentException(nameof(step)); } if (radius < 0) { throw new ArgumentException(nameof(radius)); } if (initAngle == Rotation90 || initAngle == Rotation270) { step = new[] { step[1], step[0] } } ; var plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, origin); var baseY = plane.Normal.CrossProduct(baseX); var lines = new List <Curve>(); var xAxis = Line.CreateBound(origin - radius * baseX, origin + radius * baseX); var yAxis = Line.CreateBound(origin - radius * baseY, origin + radius * baseY); lines.Add(xAxis); lines.Add(yAxis); var yp0 = yAxis.GetEndPoint(0); var yp1 = yAxis.GetEndPoint(1); var xNum = Convert.ToInt32(Math.Ceiling(radius / step[0])); var yNum = Convert.ToInt32(Math.Ceiling(radius / step[1])); // Draws lines on x direction for (var i = 0; i < xNum; i++) { var offset = (i + 1) * step[0] * baseX; // On Right. lines.Add(Line.CreateBound(yp0 + offset, yp1 + offset)); // On Left. lines.Add(Line.CreateBound(yp0 - offset, yp1 - offset)); } var xp0 = xAxis.GetEndPoint(0); var xp1 = xAxis.GetEndPoint(1); // Draws lines on y direction for (var i = 0; i < yNum; i++) { var offset = (i + 1) * step[1] * baseY; // Above. lines.Add(Line.CreateBound(xp0 + offset, xp1 + offset)); // Below. lines.Add(Line.CreateBound(xp0 - offset, xp1 - offset)); } var doc = elm.Document; var sketchPlane = SketchPlane.Create(doc, plane); var ids = PartUtils.GetAssociatedParts(doc, elm.Id, true, false).ToList(); if (ids.Count > 0) { var partMaker = PartUtils.GetAssociatedPartMaker(doc, ids[0]); doc.Delete(partMaker.Id); } ids = PartUtils.GetAssociatedParts(doc, elm.Id, true, true).ToList(); if (ids.Count <= 0) { PartUtils.CreateParts(doc, new List <ElementId> { elm.Id }); doc.Regenerate(); ids = PartUtils.GetAssociatedParts(doc, elm.Id, true, true).ToList(); } if (ids.Count == 1) { PartUtils.DivideParts(doc, ids, new List <ElementId>(), lines, sketchPlane.Id); } }