using CopyElements between two documents,the generated new element are not displayed

using CopyElements between two documents,the generated new element are not displayed

564538157
Contributor Contributor
408 Views
6 Replies
Message 1 of 7

using CopyElements between two documents,the generated new element are not displayed

564538157
Contributor
Contributor

hi.

My question is I use revitnet.dll to copy the element from Document 1 to Document 2 in an external application, and then save Document 2 as Document 3. When I open Document 3, I cannot see the generated element, but if I use addin the way I do, I will get the correct results. not all documents will experience this error. 

When I search for this ID in revit (id is 225857), after clicking "show", prompt "no good view could be found". after clicking "ok", only one dimension line can be seen. What could be the reason for this

 

1.png2.png

 

revit version: 2019

thanks

 

 

0 Likes
Accepted solutions (1)
409 Views
6 Replies
Replies (6)
Message 2 of 7

ken_marsh_pelogic
Contributor
Contributor

Have you tried using this overload of ElementTransformUtils from the standard RevitAPI.dll?

 
ElementTransformUtils.CopyElements(Document, ICollection<(Of <(<'ElementId>)>)>, Document, Transform, CopyPasteOptions)

 

public static ICollection<ElementId> CopyElements(
	Document sourceDocument,
	ICollection<ElementId> elementsToCopy,
	Document destinationDocument,
	Transform transform,
	CopyPasteOptions options
)

 

0 Likes
Message 3 of 7

564538157
Contributor
Contributor

Yes, I am using this method. The same code is correct in plugin mode, but using revitnet.dll in an external program can cause this problem.

0 Likes
Message 4 of 7

ken_marsh_pelogic
Contributor
Contributor
Accepted solution

Hi, If you're talking about starting Revit with the RevitNet.dll, not only is this unsupported, unless something has changed, it is also a violation of the license to agreement to run Revit from an external application context.  I would recommend an Autodesk Platform Services (APS) Design Automation approach if you want to perform this kind of automation.  Another approach is to use the Application.Initilized event and some command line switches which you can handle in a Revit Addin.  This way you are running the Revit product correctly and leveraging automation as well.  Note, do your own due diligence on reading and complying with the Revit licensing agreement but my reading says that you are not allowed to host Revit as a service so do proceed with caution.

0 Likes
Message 5 of 7

564538157
Contributor
Contributor

I seem to know what to do now, thank you very much.

0 Likes
Message 6 of 7

564538157
Contributor
Contributor

hi, I tried to execute the code in the Application Initialized event, but still got the same error. Is it possible that this issue is not the cause?

 

public Result OnStartup(UIControlledApplication application)
        {
            application.ControlledApplication.ApplicationInitialized -= ControlledApplication_ApplicationInitialized;
            application.ControlledApplication.ApplicationInitialized += ControlledApplication_ApplicationInitialized;

            return Result.Succeeded;
        }

        private void ControlledApplication_ApplicationInitialized(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e)
        {
            Autodesk.Revit.ApplicationServices.Application app = sender as Autodesk.Revit.ApplicationServices.Application;

            model1Path = @"C:\revitmodel\1.rvt";
            model2Path = @"C:\revitmodel\2.rvt";

            Document doc1 = app.OpenDocumentFile(model1Path);
            Document doc2 = app.OpenDocumentFile(model2Path);

            string ModulePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            DirectoryInfo di = Directory.CreateDirectory($@"{ModulePath}/Export/{GetTimeStamp()}");
            exportDirect = di.FullName;

            Compare(doc1, doc2);

            doc1.Close(false);
            doc2.Close(false);

            Process.Start("Explorer", $"/select,{exportDirect}\\{exportTextName}");
        }

 

0 Likes
Message 7 of 7

ken_marsh_pelogic
Contributor
Contributor
This bit helps, can you show us the code where you perform the copy? I'm curious what you're using for transforms etc., also is it safe to assume that these are two, otherwise identical files started from the same template? I'm curious about view visibility settings between them, I'm curious about origin points, etc. A bit more info could help us home in on the issue. We use copyElements cross document in a major application so I'm nearly certain that this should be achievable.
0 Likes