Recenlly, I'm tried find the pick first point intersect of pattern and then suscess, but when you change between Floor and Ceiling, you need to change the number step of pattern:
Floor :
int index = 2 + (ip * _gridCount * 2);
int index = 3 + (ip * _gridCount * 2);
Ceiling :
int index = 1 + (ip * _gridCount * 2);
int index = 2 + (ip * _gridCount * 2);
Example to find the first intersect of pattern :
public XYZ? FindPlacePointPattern()
{
using Autodesk.Revit.DB.Transaction tran = new Transaction(Doc, "Find Place Point Pattern");
tran.Start();
//check for model surfacepattern
var hostObject = this.HostObjectPart.HostObject;
Reference? top = HostObjectUtils.GetTopFaces(hostObject)
.FirstOrDefault();
PlanarFace? topFace = hostObject.GetGeometryObjectFromReference(
top) as PlanarFace;
Material mat = Doc.GetElement(
topFace.MaterialElementId) as Material;
ElementId foregroundPatternId = mat.SurfaceForegroundPatternId;
FillPatternElement? patterntype = Doc.GetElement(
foregroundPatternId) as FillPatternElement;
FillPattern pattern = patterntype.GetFillPattern();
if (pattern.IsSolidFill || pattern.Target == FillPatternTarget.Drafting) return null;
// get number of gridLines in pattern
int _gridCount = pattern.GridCount;
//https://forums.autodesk.com/t5/revit-api-forum/dimension-on-hatch-pattern-slab/m-p/7078368#M22785
// construct StableRepresentations and find the Reference to HatchLines
string StableRef = top.ConvertToStableRepresentation(Doc);
ReferenceArray _resArr = new ReferenceArray();
for (int ip = 0; ip < 2; ip++)
{
int index = 2 + (ip * _gridCount * 2);
string StableHatchString = StableRef + $"/{index}";
var HatchRef = Reference.ParseFromStableRepresentation(Doc, StableHatchString);
_resArr.Append(HatchRef);
}
// 2 or moreReferences => create dimension
Dimension d1 = null;
if (_resArr.Size > 1)
{
d1 = Doc.Create.NewDimension(Doc.ActiveView,
Line.CreateBound(XYZ.Zero, new XYZ(1, 0, 0)), _resArr);
// move dimension a tiny amount to orient the dimension perpendicular to the hatchlines
// I can't say why it works, but it does.
ElementTransformUtils.MoveElement(Doc, d1.Id, new XYZ(.01, 0, 0));
}
_resArr.Clear();
for (int ip = 0; ip < 2; ip++)
{
int index = 3 + (ip * _gridCount * 2);
string StableHatchString = StableRef + $"/{index}";
var HatchRef = Reference.ParseFromStableRepresentation(Doc, StableHatchString);
_resArr.Append(HatchRef);
}
// 2 or more References => create dimension
Dimension? d2 = null;
if (_resArr.Size > 1)
{
d2 = Doc.Create.NewDimension(Doc.ActiveView,
Line.CreateBound(XYZ.Zero, new XYZ(0, 1, 0)), _resArr);
// move dimension a tiny amount to orient the dimension perpendicular to the hatchlines
// I can't say why it works, but it does.
ElementTransformUtils.MoveElement(Doc, d2.Id, new XYZ(0, .01, 0));
}
// create dimension between two dimensions
// try get cross point of two dimensions
if (d1 != null && d2 != null)
{
XYZ? intersection = FindIntersectByTwoDirection(d1, d2);
return intersection;
}
tran.RollBack();
return null;
}
Chuong Ho
