Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting the location of hooks in a rebar shape family

22 REPLIES 22
SOLVED
Reply
Message 1 of 23
FrodeTo
2968 Views, 22 Replies

Getting the location of hooks in a rebar shape family

When editing a Rebar Shape family I would like to find out what lines in the family the hooks are attached to. In other words I would like the id of the line the start hook is attached to and the coordinate of this hook.  

 

I have written code to edit the family and I do find the rebar lines and the dimensions, but I cannot find any way to locate the placement of the hooks. Any help is appreciated.

 

regards

Frode

 

 

22 REPLIES 22
Message 2 of 23
jeremytammik
in reply to: FrodeTo

Dear Frode,

 

Thank you for your query.

 

I do not know off-hand, so I am asking the development team for help.

 

Hang on...

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 23
jeremytammik
in reply to: FrodeTo

Dear Frode,

 

Thank you for your patience with this.

 

I heard back now from the development team. They say:

 

After further investigations I found that this is indeed a tricky subject.

There is no clear/easy way to obtain what the user asked for. (I could not find any API methods for retrieving the position of the hooks in relation to the RebarShape Family lines).

 

It would be helpful to know more high-level details about what the user wants to obtain.

Could you provide me a scenario?

 

I am thinking of this one but I need to be sure this is what the user wants.

The user wants to edit the shape family so that all rebars in the model will get a hook at a certain/expected end.

 

These details would help us decide if we need to implement a new method for API, or if we can suggest some other solutions.

 

Could you please provide the desired background information so we can raise a wish list item for this?

 

Best of all would be in the form of a reproducible case including a minimal testing BIM and some sample code illustrating what does and does not work:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Thank you!

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 23
FrodeTo
in reply to: jeremytammik

Hi Jeremy.

Thank you for investigating.

 

What we are trying to do here is to create images of the rebars that will be used in a report. We are able to produce the image shown below, but we would like to be able to put hooks on the image as well. The actual geometry of the hook is not that important. What we need is the hook angle, what end is "Hook at Start" connected to and what is the orientation of the hook.

 

The code is too long to show here, but what we do is to call EditFamily on the shape. Then we create the rebars shape from the model lines in the family. The dimension lines and text are created from the dimension elements. If there are other ways to create this image we will be very happy. Please note that we need both the hooks and the dimesions in our figur. 

 

21.png

regards

Frode

Message 5 of 23
jeremytammik
in reply to: FrodeTo

Dear Frode,

 

Thank you for your update, which I passed on to the development team.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 6 of 23
tiberiu.pinzariu
in reply to: FrodeTo

Hello Frode,

 

You can get the shape centerlines (without hooks) in order (from start to end) with the following method  :

   IList<Curve> curvesForBrowser = rebarShape.GetCurvesForBrowser();

 

Note: You should be able to retrieve the RebarShape element from the family document.

 

Hook information can be retrieved through methods:

 

                    int hookangle0 = rebarShape.GetDefaultHookAngle(0);
                    RebarHookOrientation orient0 = rebarShape.GetDefaultHookOrientation(0);

 

                    int hookangle1 = rebarShape.GetDefaultHookAngle(1);
                    RebarHookOrientation orient1 = rebarShape.GetDefaultHookOrientation(1);

 

Hook position should be as follows:

 

   Start hook origin point should be : curvesForBrowser[0].GetEndPoint(0);

   End hook origin point should be : curvesForBrowser[curveSize -1].GetEndPoint(1);

 

And the connection between the curvesForBrowser and the dimensions in the family can be retrieved like this:

 

1. Map the dimensions to their label parameter ids.

            IDictionary<ElementId, ElementId> labelParamIdToDimId = new Dictionary<ElementId, ElementId>();

            foreach (Dimension dim in familyDimensions)
            {

                try
                {
                    FamilyParameter famParam = dim.FamilyLabel;
                    if (null == famParam)
                        continue;
                    labelParamIdToDimId[famParam.Id] = dim.Id;
                }
                catch (Autodesk.Revit.Exceptions.InvalidOperationException)
                {
                    continue;
                }
            }

 

2.Get the constraint information from the shape definition.            

 

            // Get the shape definition : constraints should be available for every definition.

            // Get all the shape segments (indexes of segments) and their corresponding constraint parameter ids

            // The RebarShapeSegment should be in the same order as the curvesForBrowser.

            // The constraint param ids  should correspond to the dimension label param ids.

 

            RebarShapeDefinitionBySegments defBySeg = rebarShape.GetRebarShapeDefinition() as RebarShapeDefinitionBySegments;

 

            IDictionary<int, string> segmentPosToLabel = new Dictionary<int, string>();
            for (int ii = 0; ii < defBySeg.NumberOfSegments; ii++)
            {
                RebarShapeSegment seg = defBySeg.GetSegment(ii);
                IList<RebarShapeConstraint> constraints = seg.GetConstraints();
                foreach (RebarShapeConstraint constraint in constraints)
                {
                    ElementId paramID = constraint.GetParamId();
                    if ((paramID == ElementId.InvalidElementId) || !labelParamIdToDimId.ContainsKey(paramID))
                        continue;

                    string labelName = "";
                    foreach (Parameter param in rebarShape.Parameters)
                    {
                        if (param.Id == paramID)
                        {
                            labelName = param.Definition.Name;
                            break;
                        }
                    }
                    segmentPosToLabel.Add(ii, labelName);
                }
            }

 

Finally you should be able to retrieve/create all the curves and their corresponding dimensions:

 

            IList<Curve> curvesForPicture = new List<Curve>();
            for (int ii = 0; ii < defBySeg.NumberOfSegments; ii++)
            {
                Curve curve = curvesForBrowser[ii];
                string label = "";
                if (!segmentPosToLabel.TryGetValue(ii, out label))
                    continue;

            }

 

Please let me know if this works for you.

 

Regards,

Tiberiu

Message 7 of 23

Dear Tiberiu,

 

Thank you very much for researching and sharing this important solution!

 

Dear Frode,

Does this solve your issue?

 

If so, could you please mark it as an accepted solution?

 

Thank you!

Best regards,

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 8 of 23
jeremytammik
in reply to: jeremytammik

Dear Frode,

 

We are still eagerly awaiting your confirmation that this works for you.

 

In the meantime, I cleaned up and published this thread for legibility and posteriority:

 

http://thebuildingcoder.typepad.com/blog/2016/04/location-of-hooks-in-a-rebar-shape-family.html

 

Thanks you again, Tibi, for your research!

 

Best regards,

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 9 of 23
FrodeTo
in reply to: jeremytammik

Sorry for the late replay. I've been away on vacation.

 

Thank you Tiberiu for the suggestions. However I did not manage to use this exactly as you describe. The information that the curves for browser is correctly ordered is very helpful. But unfortunatly the shape from curves for browser is not identical to the shape in the family. And I need the lines in the family to draw the dimension lines. What I have done instead is to use the information from the curves from browser to determine what segments in the family that the hooks are connected to. This seems to work. At the moment the code is not publishable as it's quite long and experimental.

 

Thank you for the help!

 

If it's possible to wish for a new function in the API I very much would like a funkction that gets the picture shown in the Revit Shape Browser with both the hooks and the dimension. 

 

regards

Frode

Message 10 of 23
tiberiu.pinzariu
in reply to: FrodeTo

You are welcome.

 

I will pass the API request to my team and we will consider it in the near future.

We will let you know when we have updates on this matter.

 

Regards,

Tibi

Message 11 of 23

 Hi this all looks good but can't get past the first hurdle:

 

1. foreach (Dimension dim in familyDimensions)

 

 

How do I obtain familyDimensions (and annotations) for the rebar?

Message 12 of 23
FrodeTo
in reply to: PhoneCoolie

You have to open the family for edit (document.EditFamily) and iterate the Dimension's in the family document.

Message 13 of 23
scarta
in reply to: FrodeTo

Hi FrodeTo

 

have you a sample for open the family for edit (document.EditFamily) and iterate the Dimension's in the family document?

 

thanks

Stefano

Message 14 of 23
PhoneCoolie
in reply to: scarta

Hi Stefano,

This is what I ended up with (data is an array of dimension name-value pairs, and SegInfo struct definition is at the end):


private List<List<SegInfo>> GetDimensionInfo(Dictionary<string, int> data, RebarShape rebarShape) { IEnumerable<Dimension> dims = null; var infoLists = new List<List<SegInfo>>(); var rebar = _Document.GetFamilySymbolrebarShape.Name); if (rebar != null) { var doc = _Document.EditFamily(rebar.Family); dims = doc.GetTypes<Dimension>().Where(x => HasLabel(x)); } // get the shape definition RebarShapeDefinitionBySegments shapeDef = rebarShape.GetRebarShapeDefinition() as RebarShapeDefinitionBySegments; // get the dimension name and value for each segment for (int i = 0; i < shapeDef.NumberOfSegments; i++) { RebarShapeSegment segment = shapeDef.GetSegment(i); var constraints = segment.GetConstraints(); var infoList = new List<SegInfo>(); foreach (var constraint in constraints) { ElementId id = constraint.GetParamId(); if ((id == ElementId.InvalidElementId)) continue; var p = rebarShape.get_Parameter(id); if (p == null) continue; // store segment information SegInfo sd; sd.name = p.Definition.Name; sd.value = data[sd.name]; sd.constraint = constraint; sd.dimension = dims?.Where(x => x.FamilyLabel.Id == id).FirstOrDefault(); infoList.Add(sd); } infoLists.Add(infoList); } return infoLists; } private struct SegInfo { public string name; public double value; public RebarShapeConstraint constraint; public Dimension dimension; }

 

Message 15 of 23
scarta
in reply to: PhoneCoolie

Thanks

 

I will try it!!

Message 16 of 23
PhoneCoolie
in reply to: scarta

Hi Stefano,

 

My edit timed out but here is the code for GetTypes<T>():

 

public static IList<T> GetTypes<T>(this Document document) where T : Element
        {
            return new FilteredElementCollector(document)
                .OfClass(typeof(T))
                .Cast<T>()
                .ToList();
        }

 

Also  a typeo at the line GetFamilySymbolrebarShape.Name) is missing a bracket:  GetFamilySymbol(rebarShape.Name).

 

You may not need the Dimenison dictionary if you have the rebar instance available.

 

Message 17 of 23
scarta
in reply to: PhoneCoolie

I try to convert it to Vb.NET, but I receive  this error " line 1 col 9: invalid TypeDecl"

Message 18 of 23
PhoneCoolie
in reply to: scarta

Your on your own with VB!

Message 19 of 23

Hi FrodeTo,

 

How did you get the images for the rebars? 

 

Regards,

Senne

Message 20 of 23
1368026189
in reply to: FrodeTo

Hello  FrodeTo:

 

I got the same Requirement as you descibe,So can you share your solution to us dispite the long code?

Thanks a lot!!!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community