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: 

Save command code

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
921 Views, 3 Replies

Save command code

Hi All,

Apologies for the very very basic question but i have never really done any coding before and i am trying to teach myself C# to program Revit API.

I have gone through the first plugin guide and the Hello world guide and both of these have helped.

 

For my next task i want to modify the hello world code to make revit do a file save before the pop up box.

Could anyone please give me an idea of what code i need to write to make Revit save?

 

After this i would like to look into doing a command which reloads all of the Revit links in the project. Do you think this would be possible?

 

Many thanks

Mike

Tags (1)
3 REPLIES 3
Message 2 of 4
akira.kudo
in reply to: Anonymous

There are some methods for saving,  you can use Document::Save() for instance like below. If you need to use the SaveAsOptions, there is a sample code in the SDK help. Please find the attached jpg.

And for reloading rvt links, you can use the RevitLinkType::Load() like below. it uses for load or reload a Revit link from disk.

 

<code_begin>

        public Result Execute(

          ExternalCommandData commandData,

          ref string message,

          ElementSet elements)

        {

            UIApplication uiapp = commandData.Application;

            UIDocument uidoc = uiapp.ActiveUIDocument;

            Application app = uiapp.Application;

            Document doc = uidoc.Document;

            View view = uidoc.ActiveView;

 

            using (Transaction tx = new Transaction(doc))

            {

                tx.Start("reload link");

 

                FilteredElementCollector collector = new FilteredElementCollector(doc);

                         IList<Element> elementos = collector.OfClass(typeof(RevitLinkType)).ToElements();

                         foreach (Element e in elementos)

                         {

                                       RevitLinkType linkType = e as RevitLinkType;

                    Debug.Print(linkType.Name);

                    // Loads or reloads the Revit link from disk. The link will be loaded from its currently-stored path. 

                    linkType.Load();

                }

 

                tx.Commit();

            }

 

            doc.Save(); //Saves the document.

            // Save(SaveOptions) // Saves the document.  

            // SaveAs(String) // Saves the document to a given file path.  

            // SaveAs(String, SaveAsOptions) // Saves the document to a given file path.  

            // SaveAs(ModelPath, SaveAsOptions) // Saves the document to a given path.  

 

            Debug.Print("Hello World");

 

            return Result.Succeeded;

        }

 

<code_end>

 

Please find an attached sample project in the zip. And please let me know if it does not match with what you want to do.

I hope this helps.

 

PS... I am working on your question for 2013 now . Please hold on.





Akira Kudo

Developer Technical Services

Autodesk Developer Network


Message 3 of 4
Anonymous
in reply to: akira.kudo

Akira,
Thanks for your support.
Look forward to the 2013 Solution!

Mike
Message 4 of 4
akira.kudo
in reply to: Anonymous

Again Mike-san,

 

I am really sorry for delay due to our events.

 

Unfortunately we do not expose any direct methods that third-party developers can reload the revit link model in Revit 2013 via API.

A workaround we have now is that you delete the Revit linked model, and its corresponding Revit link type. Then create a new Revit link type by using the updated Revit model file, and finally create a revit linked model in the same place.
However, this would be time-consuming process.

 

Please let me know if you need further assistance or if I may close this case.

 

Best Regards,

Akira Kudo





Akira Kudo

Developer Technical Services

Autodesk Developer Network


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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community