Cannot find attachmentType correctly in link tree.

Cannot find attachmentType correctly in link tree.

pmeigneux
Advocate Advocate
2,308 Views
11 Replies
Message 1 of 12

Cannot find attachmentType correctly in link tree.

pmeigneux
Advocate
Advocate

I rebuild tree link but attachmenttype is incorrect..

 

My code :

public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
ref string message, ElementSet elements)
{
  // get active document
  Document mainDoc = revit.Application.ActiveUIDocument.Document;

 

  // prepare to show the results...
  TreeNode mainNode = new TreeNode();
  mainNode.Text = mainDoc.PathName;

 

  // start by the root links (no parent node)
  FilteredElementCollector coll = new FilteredElementCollector(mainDoc);
  coll.OfClass(typeof(RevitLinkInstance));


  foreach (RevitLinkInstance inst in coll)
  {
    RevitLinkType type = mainDoc.GetElement(inst.GetTypeId()) as RevitLinkType;
    if (type.GetParentId() == ElementId.InvalidElementId)
    {
      TreeNode parentNode = new TreeNode(type.Name+"->"+type.AttachmentType.ToString());
      mainNode.Nodes.Add(parentNode);

      GetChilds(mainDoc, type.GetChildIds(), parentNode);
    }
  }

 

  // show the results in a form
  System.Windows.Forms.Form resultForm = new System.Windows.Forms.Form();
  TreeView treeView = new TreeView();
  treeView.Size = resultForm.Size;
  treeView.Anchor |= AnchorStyles.Bottom | AnchorStyles.Top;
  treeView.Nodes.Add(mainNode);
  resultForm.Controls.Add(treeView);
  resultForm.ShowDialog();

  return Result.Succeeded;

}

 

private void GetChilds(Document mainDoc, ICollection<ElementId> ids,
TreeNode parentNode)
{
    foreach (ElementId id in ids)
  {
    // get the child information
    RevitLinkType type = mainDoc.GetElement(id) as RevitLinkType;

   TreeNode subNode = new TreeNode(type.Name + "->" + type.AttachmentType.ToString());
    parentNode.Nodes.Add(subNode);

 

    // then go to the next level
    GetChilds(mainDoc, type.GetChildIds(), subNode);
  }
}

 

Result :

 

Screenshot_1.png

 

0 Likes
2,309 Views
11 Replies
Replies (11)
Message 2 of 12

jeremytammik
Autodesk
Autodesk

Dear Pmeigneux,

 

Thank you for your query.

 

I assume this is a follow-up to your previous questions on retrieving the hierrchy of linked Revit files, and the sample code that Augusto provided for you:

 

 

Correct?

 

I would suggest that you debug the code and step through it statement by statement.

 

Pay particular atention to the statement that sets the attachment type string on the tree node.

 

Is it performing correctly?

 

If no, fix it.

 

If yes, you can submit a much simpler reproducible case which is independent of the rest of the hierarchy and simply demonstrates that the AttachmentType property returns a wrong value on a specific linked file.

 

Please provide that as a minimal reproducible case that we can pass on to the development team for further analysis:

 

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

 

If it the problem is as simple as it appears, your sample code just needs one single line of code:

 

 

print type.AttachmentType.ToString()

 

And you just need to submit one single Revit model file, or possibly two: the main project file and the linked file reporting the erroneous attachment type.

 

Thank you!

 

I hope this helps.

 

Best regards,

 

Jeremy

 



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

0 Likes
Message 3 of 12

pmeigneux
Advocate
Advocate

Hello Jeremy

This is the sample code used as well as files:

public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
{
    // get active document
    Document mainDoc = revit.Application.ActiveUIDocument.Document;

    // prepare to show the results...
    TreeNode mainNode = new TreeNode();
    mainNode.Text = mainDoc.PathName;

    // start by the root links (no parent node)
    FilteredElementCollector coll = new FilteredElementCollector(mainDoc);
    coll.OfClass(typeof(RevitLinkInstance));
    foreach (RevitLinkInstance inst in coll)
    {
        RevitLinkType type = mainDoc.GetElement(inst.GetTypeId()) as RevitLinkType;
        if (type.GetParentId() == ElementId.InvalidElementId)
        {
            TreeNode parentNode = new TreeNode(type.Name+"->"+type.AttachmentType.ToString());
            mainNode.Nodes.Add(parentNode);

            GetChilds(mainDoc, type.GetChildIds(), parentNode);
        }
    }
    
    // show the results in a form
    System.Windows.Forms.Form resultForm = new System.Windows.Forms.Form();
    TreeView treeView = new TreeView();
    treeView.Size = resultForm.Size;
    treeView.Anchor |= AnchorStyles.Bottom | AnchorStyles.Top;
    treeView.Nodes.Add(mainNode);
    resultForm.Controls.Add(treeView);
    resultForm.ShowDialog();
    
    return Autodesk.Revit.UI.Result.Succeeded;
}

private void GetChilds(Document mainDoc, ICollection<ElementId> ids, TreeNode parentNode)
{
    foreach (ElementId id in ids)
    {
        // get the child information
        RevitLinkType type = mainDoc.GetElement(id) as RevitLinkType;

        TreeNode subNode = new TreeNode(type.Name + "->" + type.AttachmentType.ToString());
        parentNode.Nodes.Add(subNode);

        // then go to the next level
        GetChilds(mainDoc, type.GetChildIds(), subNode);
    }
}

 

Obtained Result:

 

0 Likes
Message 4 of 12

jeremytammik
Autodesk
Autodesk

Dear Pmeigneux,

 

Thank you for your sample code and model structure.

 

I compiled and ran your sample successfully in Revit 2016 and see the same as you show above:

 

treeview_result.png

 

Now what is the problem, please?

 

What result would you expect?

 

Best regards,

 

Jeremy



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

Message 5 of 12

jeremytammik
Autodesk
Autodesk

Dear Pmeigneux,

 

I cleaned up your sample code and created a full minimal sample add-in solution for it, attached below.

 

It now produces the same treeview form and also lists the result in the debug output window:

 

Det1AssemblyA2.rvt->Attachment
Det1AssemblyA2.rvt->Attachment
Det1AssemblyA2.rvt->Attachment
Sub1AssemblyA2.rvt->Attachment
  Det1AssemblyA2.rvt->Overlay
Sub1AssemblyA2.rvt->Attachment
  Det1AssemblyA2.rvt->Overlay
Sub1AssemblyA2.rvt->Attachment
  Det1AssemblyA2.rvt->Overlay

 

Are the nested links not overlays?

 

How should they be classified?

 

I guess a defect should be registered for this, then?

 

Thank you!

 

Cheers,

 

Jeremy



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

Message 6 of 12

pmeigneux
Advocate
Advocate

Hi,

 

All Links are in Attachment... No Overlay in this Example.

 

I'm use revit 2015.

 

Philippe Meigneux.

0 Likes
Message 7 of 12

jeremytammik
Autodesk
Autodesk

Dear Philippe,

 

Thank you for confirming that.

 

I logged the issue REVIT-83477 [AttachmentType returns wrong value -- 11363552] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide us with additional information at any time by submitting a new case quoting the change request number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team, and prioritised against all of the other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.


This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

Best regards,

 

Jeremy



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

Message 8 of 12

Aaron.Lu
Autodesk
Autodesk
While we are fixing the issue, the workaround can be:
nested links are always Attachments. (If the nested link was an overlay, then we wouldn't have brought it into the main file, so its existence demonstrates that it's an attachment.) - by development team.


Aaron Lu
Developer Technical Services
Autodesk Developer Network
Message 9 of 12

jeremytammik
Autodesk
Autodesk

Dear Philippe,

 

Can you check whether the following sample Revit add-in implements the workarou8hnd suggested by Aaron and the development team?

 

https://github.com/jeremytammik/ListLinkType

 

The relevant code is basically this:

 

  /// <summary>
  /// Return a label to display for a link type.
  /// Nested links are always attachments.
  /// </summary>
  static string LinkLabel( 
    RevitLinkType type, 
    int level )
  {
    AttachmentType a = type.AttachmentType;
    AttachmentType b = 0 < level
      ? AttachmentType.Attachment
      : a;

    Debug.Print(
      "AttachmentType {0} at level {1} -> {2}", 
      a, level, b );

    return type.Name + "->" + b.ToString();
  }


Thank you!

 

Best regards,

 

Jeremy



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

Message 10 of 12

jeremytammik
Autodesk
Autodesk

The development team report that the issue that I raised for this and the follow-up code fixing issue REVIT-84580 [AttachmentType returns wrong value -- 11363552] have been addressed and the problem is now resolved -- in the development stream, that is 🙂

 

Cheers,

 

Jeremy



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

Message 11 of 12

jeremytammik
Autodesk
Autodesk

Dear Philippe,

 

This issue has been resolved via the two development issues:

 

  • REVIT-83477 [AttachmentType returns wrong value -- 11363552]
  • REVIT-84580 [AttachmentType returns wrong value -- 11363552]

 

Can you please verify that it works as expected for you too now in Revit 2018?

 

Thank you!

 

Best regards,

 

Jeremy



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

0 Likes
Message 12 of 12

gnab
Enthusiast
Enthusiast

Hello, Jeremy. I guess the problem is still not solved (Revit 2022) because I tried to change AttachmentType of rvt-link via Revit API too. The property value in the Type properties of a rvt-link changes via Revit API, but the icon of a rvt-link in a Project Browser does not change....
However, if we do this operations by hands as standard (not via Revit API), a link icon in Project Browser changes only after press Apply or OK buttons in Type properties window. 

0 Likes