Revit 2023 rebar tag, strategies to avoid "Reference can not be tagged"

Revit 2023 rebar tag, strategies to avoid "Reference can not be tagged"

Einar_Raknes
Participant Participant
1,395 Views
2 Replies
Message 1 of 3

Revit 2023 rebar tag, strategies to avoid "Reference can not be tagged"

Einar_Raknes
Participant
Participant

There is a change from Revit 2023 that you are not longer allowed to tag a whole rebar set with a Independent Tag. You need to tag one of the individual rebars which are Subelements of the rebar set. See this forum post for more: https://forums.autodesk.com/t5/revit-api-forum/revit-2023-version-getting-an-error-at-independenttag...

 

Is there any way to avoid this exception without a try/catch block? I have tried the following:

 

1) Use a ObjectType.Subelement filter in PickObject. This works to some degree, but if you mouse over the first or the last rebar in a rebar higlights the whole set.

 

pickedRebarRef = uidoc.Selection.PickObject(ObjectType.Subelement, "Pick a single Rebar");

 

 

2) Try to create a filter using the  ISelectionFilter interface, but it requires an Element and not Subelement.

 

3) Check if the selected reference can be converted to a Subelement. The problem is that even if the whole rebar set is selected it still converts to a valid  Subelement.

 

pickedRebarRef = uidoc.Selection.PickObject(ObjectType.Subelement, "Pick a Rebar");
if(doc.GetSubelement(pickedRebarRef) == null) {
  //please select only one bar
}

 

 

4) Similar to 3)  this returns true even when the whole set is selected:

 

 

Subelement.IsValidSubelementReference(doc, pickedRebarRef);

 

 

0 Likes
Accepted solutions (1)
1,396 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni

Can't you force the user to select a rebar element, query it for its subelements using the GetSubelements method, and use one of those to generate the tag?

  

https://www.revitapidocs.com/2023/feabfd59-bd0f-ab61-34a1-d0d22f58c881.htm

  

The method remarks state that this collection will not include the Element itself, so you should be safe.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

Einar_Raknes
Participant
Participant
Accepted solution

Thanks for the suggestion! I suppose the challenge would be to figure out which rebar in the set the user clicked on and match that with the correct Subelement.

 

The ideal solution to this would be to restrain the user from doing the wrong thing in the first place, by using something like the ISelectionFilter.

 

However, I found a way to check if the user did select a Subelement by checking for the correct ElementRefereceType. Here is the code with a little bit more context:

Reference pickedRebarRef = uidoc.Selection.PickObject(ObjectType.Subelement, "Pick a induvidual Rebar, use TAB if the whole set is highlighted");

Rebar rebar = doc.GetElement(pickedRebarRef) as Rebar;
if (rebar == null || pickedRebarRef.ElementReferenceType != ElementReferenceType.REFERENCE_TYPE_SUBELEMENT)
{
    TaskDialog td = new TaskDialog("Wrong selection")
    {
        MainInstruction = "Please select a single rebar",
        MainContent = "You need to select an individual rebar, use TAB if the whole set gets higlighted.",
        AllowCancellation = true,
        CommonButtons = TaskDialogCommonButtons.Retry | TaskDialogCommonButtons.Cancel
    };
    TaskDialogResult dialogResult = td.Show();

    if (dialogResult == TaskDialogResult.Cancel)
    {
        return Result.Cancelled; 
    }

 

Before:

EinarRaknes_0-1665130762224.png

 

After:

 

EinarRaknes_1-1665130765981.png

 

0 Likes