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: 

Copy the revit model

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
techXMKH9
754 Views, 5 Replies

Copy the revit model

I am getting IOException that the file is being used by another process.

I tried to copy - programmatically -  the model file to the temp directory but I got the exception.

using (FileStream fsread = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.Read, array_length))

Opening the FileStream fails.

 

How can I get access to the file used by Revit itself?

5 REPLIES 5
Message 2 of 6
jeremytammik
in reply to: techXMKH9

Try different settings and access rights. Maybe using the native Windows API will give you more options than the .NET environment. Can you copy it in the Windows user interface? If not, then maybe you have to close the file in Revit before it can be copied. 

   



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

Message 3 of 6
sragan
in reply to: techXMKH9

You are using a file stream reader to try and save a revit file?  That sounds odd to me.  Isn't that usually used to read text from a file?

 

Why not use the Document object most external commands already have?  This works in a macro:

 

SaveAsOptions options = new SaveAsOptions();
UIDocument uidoc = this.ActiveUIDocument;  
Document doc = this.ActiveUIDocument.Document;
 doc.SaveAs(@"C:\Temp\Test API Save.rvt", options);


For an external command, you will have to modify the UIDocument and Document lines to:

 

UIApplication uiapp = commandData.Application;

Document doc = uiapp.ActiveUIDocument.Document;


And you will have to find out how to set the file save options.  (I'm assuming you probably want to detach your file from the central file.)


Steve

Message 4 of 6
techXMKH9
in reply to: jeremytammik

@jeremytammik I forgot to mention that I was able to copy the file through Windows interface. I will different settings.

Message 5 of 6
techXMKH9
in reply to: sragan

I do not want to save the Revit file but copy it to a different location.

I did not use 

File.Copy(...., ...)

because it is slow for big files. 

Message 6 of 6
techXMKH9
in reply to: techXMKH9

FileShare.ReadWrite did the trick.

@jeremytammik Thank you.

using (FileStream fsread = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, array_length))

 

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

Post to forums  

Forma Design Contest


Rail Community