NewProjecDocument usage?

NewProjecDocument usage?

Anonymous
Not applicable
1,762 Views
4 Replies
Message 1 of 5

NewProjecDocument usage?

Anonymous
Not applicable

Hi,

just learning Revit API and I am trying to do a simple test addin.

1) Open a new Document, 2) Import a CAD file 3) Save it as a rvt file 4) Close the new Dosument and return to the old one.

 

If anyone has some pointers regarding the whole procedure please let me know. Right now I am trying step 1)

 

Using the NewProjectDocument() method. This method says that it needs a template to open. I found the directory where Revit has its rte template files but is there a method which return the file path in the API? I dont want to hardcode them.

Using the New->Project user interface command there is also a <None> option how can this be provided using the above method?

 

Regarding step 2) I see that the New->Project user interface command opens immediately a new unsaved document. But this is not happening with NewProjectDocument(). I have an empty document already open when I call the addin but the new document created by NewProjectDocument() does not show up.

 

Thanks in advance

Dimi

 

 

0 Likes
Accepted solutions (1)
1,763 Views
4 Replies
Replies (4)
Message 2 of 5

gopinath.taget
Alumni
Alumni

Hello,

 

For the first requirement, the best I could find is the Application.DefaultProjectTemplate property that returns the "Full path to the default template file for new project documents".

 

For your second requirement, please take a look at the following blog post.

 

Best Regards

Gopinath

0 Likes
Message 3 of 5

gopinath.taget
Alumni
Alumni
0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution
//Create a Document based on the default template 
Autodesk.Revit.DB.Document doc = commandData.Application.Application.NewProjectDocument(commandData.Application.Application.DefaultProjectTemplate);
//Save thehis document in a temp folder
SaveAsOptions options = new SaveAsOptions(); options.OverwriteExistingFile = true; doc.SaveAs("C:/temp/new_project.rvt", options);

// Open and activate it. commandData.Application.OpenAndActivateDocument("C:/temp/new_project.rvt");

 

Hi Above is my implementation based on the blog post you mentioned. The current code opens for ma a new fresh Document in which I can mport my CAD and then do SaveAs(). I can also close now any old Document that was already open.


Thanks

Dimi