Dimension on Hatch Pattern Slab

Dimension on Hatch Pattern Slab

Anonymous
Not applicable
11,851 Views
34 Replies
Message 1 of 35

Dimension on Hatch Pattern Slab

Anonymous
Not applicable

 

Hi everyone,

I want to get dimension on hatch pattern slab like this. But I don't know how to retrieve hatch line.

Please help, thanks :).

05-May-17 10-52-26 AM.png

 

0 Likes
Accepted solutions (2)
11,852 Views
34 Replies
Replies (34)
Message 21 of 35

c_hanschen
Advocate
Advocate

@FAIR59 , Thanks for this! I think you helped a lot of people a lot wit this reply.

 

Should it also be possible to get the hatchlines through Custom Exporter?

 

I gave it a try, but got no further accessing Face (OnFaceBegin) and Polymesh (OnPolymesh)

 

I would think that the Custom Exporter can access the (Hatch)Lines? How else would you be able to export patters?

 

Thanks in advance,

 

Chris 

LKSVDD architecten

The Netherlands

 

0 Likes
Message 22 of 35

RPTHOMAS108
Mentor
Mentor

They are there part of OnPolylineSegments.

 

Each call is one line for the square grids model hatch pattern e.g.

 

OnPolylineSegments =============================================
IsFilled=False
Line Properties:
RGB=0,0,0
LineWidth=0.000328083988279104,Transparency=0
Id:-1 PatternId
GetVertices
XYZ:-80.306982018425,23.9686043593474,0 
XYZ:-58.1716084357853,23.9686043593474,0 
OnPolylineSegments =============================================
IsFilled=False
Line Properties:
RGB=0,0,0
LineWidth=0.000328083988279104,Transparency=0
Id:-1 PatternId
GetVertices
XYZ:-58.1716084357853,23.9686043593474,0 
XYZ:-58.1716084357853,47.2261081288202,0 

220516a.PNG

 

 

 

 

Message 23 of 35

c_hanschen
Advocate
Advocate

@RPTHOMAS108 , Thanks for your Reply!

 

I can't get 'OnPolylineSegments' to be invoked, can't even get the 2D view (ceilingplan) exported.

 

Maybe you can take a look at my new post?

 

https://forums.autodesk.com/t5/revit-api-forum/custom-exporter-the-view-is-not-exportable-but-ceilin... 

 

Thanks in advance,

 

Chris Hanschen

LKSVDD architecten

The Netherlands

0 Likes
Message 24 of 35

c_hanschen
Advocate
Advocate

@BardiaJahan , 

 

You sad: 

"But I'm trying to figure out how to get XYZ coordinates of the grid line"

 

Did you succeeded? Without creating a dimension first? 

I'm trying to get all start- and endpoints of the hatch-lines, got it working for ceilings by exporting a CeilingPlan trough Custom Exporter, but now i'm trying to get the hatchlines of walls.

I got all the reference of the hatchlines thanks to previous post of @FAIR59 on https://forums.autodesk.com/t5/revit-api-forum/dimension-on-hatch-pattern-slab/m-p/7078368#M22785 

 

Thanks in advance, 

 

Chris Hanschen

The Netherlands

0 Likes
Message 25 of 35

c_hanschen
Advocate
Advocate

How can you know if the Reference is outside the Face?

 

The reference is created anyway, even the dimension outside the face.

 

the only check in this code is ==Null, but that does not check if the reference is inside the face.

 

Thanks in Advance,

 

Chris

The Netherlands

0 Likes
Message 26 of 35

cdd1171022
Explorer
Explorer

Hi, refer to your code and how should I label multiple

0 Likes
Message 27 of 35

Chuong.Ho
Advocate
Advocate

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

EESignature

Message 28 of 35

jorge_morente
Participant
Participant

Many thanks to @Chuong.Ho  and especially to @FAIR59  for this very valuable information. I have used this code and it works perfectly for me. I managed to center elements in the ceiling grid when I have the ceiling and the element in the same model. What happens when the ceiling is in a linked model? I tried it and I have a problem.

 

What I do to get a point from the grid and from there 2 perpendicular lines is to get the origin of each dimension, add or subtract half the value of one of the grid cells, and I have the point positioned on the line. I create a line with the point and direction, and I have "the axes" of the grid. This worked perfectly in my initial case but not with the ceiling in a linked model.

 

WrongAxis.png

 

 

As seen in the images, I have the 2 dimensions from which I can obtain any of the green lines and thus any of the 4 red points. But the point I get with the script is the origin of the pink lines. It is displaced and I don't know why.

 

At first, I thought it could be because the origin point of the linked model was offset, but no, I checked and it is at (0,0,0). I can't figure out what it could be. Any ideas???

 

 

0 Likes
Message 29 of 35

jorge_morente
Participant
Participant

UPDATE 1: In the previous example, I had ceilings in both the model and the linked model, and it seems I was mixing things up that I shouldn't have.

I've created a model from scratch where I only have one ceiling, and it's from a linked model, and I've detected the problem. The references we created by adding some indices at the end to create the dimensions are not valid because the references I need are of the type:

33899bce-a21c-4067-af38-2260a13fa4e9-00023f0b:0:RVTLINK:147216:1/181

The string StableRef = bottom.ConvertToStableRepresentation(linkedDocument); command is giving me the following value:

f6c5042c-3953-4e47-afb0-42e0e62b1e73-00023f10:1:SURFACE

Curiously, if I dimension the grid in the model where the ceiling is, the references are with the code f6c5042... which is the UniqueId of the ceiling. If I dimension it in the model with the linked ceiling, the dimension references are 33899bce.... It's as if Revit renames the references, and I have no way of obtaining them from the ceiling because they are not those.

 

Any ideas?

0 Likes
Message 30 of 35

FAIR59
Advisor
Advisor

FAIR59_0-1722125317725.png

 

Message 31 of 35

jorge_morente
Participant
Participant

Thank you very much for your answer. I have tried to create the reference with your info and, following the same code as your example, I've managed to get:


8a9264c9-8bf7-47e4-9298-b2cb9c61c780-00037ae4:0:RVTLINK:228068:0/8.


It is not exactly the code I need because I should get 00037b5a but I have 00037ae4 which is part of the code above. Why?

0 Likes
Message 32 of 35

c_hanschen
Advocate
Advocate
RevitLinkInstance vs. Document?
0 Likes
Message 33 of 35

jorge_morente
Participant
Participant
Hi @c_hanschen ! 

I don't know which element will be 00037ae4 but now I know which one is 00037b5a. It' the RevitLinkInstance UniqueID.

Thank you!!!


Message 34 of 35

jorge_morente
Participant
Participant

I’m sharing the complete code I've used in case anyone got lost with all the posts. The code works perfectly for simple patterns, both in the model and in links:

int gridCount = pattern.GridCount;

for (int i = 1; i < 3; i++)
{
  for (int ip = 0; ip < 2; ip++)
  {
    int index = i + (ip * gridCount *2);

    string StableHatchString = null;
    if (isLinked)
    {
      var uniqueId = revitLinkInstance.UniqueId;
      string indexSurface = StableRef.Length >= 10 ? 
      StableRef.Substring(StableRef.Length - 10) : StableRef;
      StableHatchString = $"{uniqueId}:0:RVTLINK:{ceilingInstance.Id} 
                         {indexSurface}/{index}";
    }
    else
    {
      StableHatchString = StableRef + $"/{index}";
    }

    Reference HatchRef = null;
    HatchRef = Reference.ParseFromStableRepresentation(document, 
               StableHatchString);

    if (HatchRef == null)
    {
      continue;
    }

    _resArr.Append(HatchRef);
  }

  // 2 or more References => create dimension
  Dimension dimension = null;
  if (_resArr.Size > 1)
  {
    dimension = document.Create.NewDimension(document.ActiveView,
          Line.CreateBound(XYZ.Zero, new XYZ(1, 0, 0)), _resArr);
    ElementTransformUtils.MoveElement(document, dimension.Id,
                                        new XYZ(.01, 0, 0));
  }

  dimensions.Add(dimension);
  _resArr.Clear();
}

 

Just to add that I tested it with a ceiling that has a more complex pattern, with a gridCount of 6, 2 horizontally and 4 vertically, and I had to change the index formula because it was giving me the same dimension:

 

int index = i + 2 + (ip * gridCount * 2);

 

It worked for me, but I'm not sure if it will work in other cases where the gridCount is not equal to 2. This is the pattern. I managed to place the element in the center of the pattern, represented by the yellow dot. The goal was to place it at one of the intersections of the green lines. I think it's very complicated when the patterns aren't simple, and it's not worth the effort.

 

jorge_morente_0-1723733767357.png

 

Thanks to everyone who helped solve this problem.

 

Message 35 of 35

jeremy_tammik
Alumni
Alumni

Thank you all for the useful updates and enhancements to this solution. I shared them on the blog for posterity:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open