CopyElements method in RVT 2024

phantbinh99
Enthusiast

CopyElements method in RVT 2024

phantbinh99
Enthusiast
Enthusiast

Hello everyone,

 

ElementTransformUtils.CopyElements(RevitSourceDocument, new List<ElementId> { viewToCopy.ViewId }, DestinationDoc, Autodesk.Revit.DB.Transform.Identity, new CopyPasteOptions());

 

I'm using the CopyElements method to copy sheet views from one file to another and get the error "Sheet views in this model cannot contain more than one instance of the same view" when trying to copy in Revit 2024 version.

 

In version 2023 and earlier CopyElements allows me to copy sheetview (but does not include draftView or title, text) I have to use copyelements (view to view) again to copy them.

In version 2024 there has been a change, (title ,text) will be copied along with the sheet view, however when I copy the sheet view containing Drafting View or Image View, the CopyElements function returns the error "Sheet views in this model cannot contains more than one instance of the same view."

 

Has anyone else had a similar problem and how did you handle it?

0 Likes
Reply
713 Views
8 Replies
Replies (8)

jeremy_tammik
Autodesk
Autodesk

I have asked the development team whether they are aware of this and how to handle it for you.

  

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

phantbinh99
Enthusiast
Enthusiast

Thank you for your response, I'm waiting for your solution.

0 Likes

jeremy_tammik
Autodesk
Autodesk

I discussed this with the development team. They tested and confirm that doing this through the UI appears unchanged (copying the sheet instance, from the project browser):

 

Revit 2023:

 

  • Copy a sheet to the clipboard; which contains a detail line \ text \ drafting view \ schedule instance.
  • Create a new model.
  • Paste. The sheet and all elements are pasted, along with the creation and placement of the drafting view and schedule view in the new model.

 

Revit 2024 and preview version:

 

  • Copy a sheet to the clipboard; which contains a detail line \ text \ drafting view \ schedule instance.
  • Create a new model.
  • Paste. The sheet and all elements are pasted, along with the creation and placement of the drafting view and schedule view in the new model.

 

If the customer has a specific reproducible example, or if this is always reproducible in your testing with the API, could yu please provide a complete minimal reproducible case?

 

 

Thank you!

    

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

sragan
Collaborator
Collaborator

There also appears to be a "duplicate sheet" option, with options to include viewports or not.  But unfortunately, it doesn't look like you can duplicate sheets from one file to another.  

 

Duplicate Method (SheetDuplicateOption) (revitapidocs.com)

 

Duplicate Method (SheetDuplicateOption) (revitapidocs.com)

 

 

0 Likes

phantbinh99
Enthusiast
Enthusiast

Sorry for the late reply, I think there's a mistake here

I am trying to use the Revit API : CopyElements Method to copy the sheet view rather than using the UI.

https://www.revitapidocs.com/2024/b22df8f6-3fa3-e177-ffa5-ba6c639fb3dc.htm

As mentioned before in RVT 2023 version, CopyElements allows me to copy sheetview (which may contain drafting view)
However, in RVT 2024, using CopyElements for cases where drafting views cause the error "Sheet views in this model cannot contain more than one instance of the same view".

Can you help me with this problem?

Best regard,

0 Likes

phantbinh99
Enthusiast
Enthusiast

Yes that's right, actually I'm also thinking about duplicating the sheetview to get rid of the drafting view first, but I keep getting the error that the sheetview cannot be duplicated.

If there is no other way, I will go this way.

 

Thank you,

0 Likes

phantbinh99
Enthusiast
Enthusiast

I appreciate your initial response, and I recently provided additional information. I understand that you are very busy, and I might have missed your response in the thread. If you have had the chance to review my latest comment, I would be grateful for any further insights or thoughts you might have. Your input is valuable to me, and I'm eager to continue the discussion.
Thank you for your time, and I look forward to hearing from you soon.

@jeremy_tammik 

0 Likes

eric.isaac2KKE9
Enthusiast
Enthusiast

@jeremy_tammik Does the dev team need a full VS project that replicates the issue, or will a snippet that raises the error in context work (for a reproducible example)?

We are encountering this issue as well. We have a tool that copies sheets, and can confirm that the ElementTransformUtils.CopyElements(...) function can copy sheets in Revit 2023, but the same code fails in 2024, raising the exception @phantbinh99 mentioned above. Something like...

using Autodesk.Revit.DB;

public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
   ref string message, ElementSet elements)
{
    ExternalCommandData cdata = revit;
    Document fromDocument = cdata.View.Document;
    Document toDocument = cdata.View.Document;
    var sheets = new FilteredElementCollector(fromDocument).OfClass(typeof(ViewSheet)).ToElements();

    using (Transaction transaction = new Transaction(toDocument)) {
        foreach (ViewSheet sheet in sheets) {
            bool canBeDuplicated = sheet.CanViewBeDuplicated(ViewDuplicateOption.Duplicate);
            if (!canBeDuplicated) { continue; }

            List<ElementId> toCopy = new List<ElementId> { sheet.id };
            List copiedElements = ElementTransformUtils.CopyElements(
                fromDocument, toCopy, toDocument, null, null);
        }
    }
}

This fails the same way, regardless of if the sheet is being copied within the same document or between linked documents. We aren't actually copying every sheet, I just removed the filtering & UI code to avoid including too much cruft that would distract from the relevant calls.

 

It isn't urgent on our end, but it is something we would like to resolve before moving our firm to 2024. The ability to copy sheets via the API really does save us a lot of time, and it would be sorely missed in 2024!

0 Likes