Quantcast
Channel: All Revit API Forum posts
Viewing all articles
Browse latest Browse all 67020

Re: Revit 2017 Add-In using Macro API

$
0
0

I am using it via an addin and not in a macro.

 

1) External Command that loads form that batch open/closes documents. Once the form has completed running the batch process (Steps 2 and 3 below), it starts the ThreadPool.QueueUserWorkItem and calls the method ClosePlaceHolder.

 

    public class BatchProcess : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
        {
            try
            {
                BatchForm batchForm = new BatchForm(commandData.Application);
                if (batchForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(ClosePlaceholder));
                }
                return Result.Succeeded;
            }
            catch(Exception e)
            {
                TaskDialog.Show("Error", e.Message);
                return Result.Failed;
            }
        }

        private void ClosePlaceholder(object state)
        {
            try
            {
                SendKeys.SendWait("^{F4}");
            }
            catch
            {

            }
        }

    }

 

2) Some code from my batch process that opens placeholder model

 

uiapp.OpenAndActivateDocument(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\Placeholder.rvt");
Document placeholderDoc = uiapp.ActiveUIDocument.Document;

3) During the batch process, I open and close models using code like this. Once the batch is done I only have the Placeholder.rvt model open.

 

Document doc = uiapp.Application.OpenDocumentFile(modelPathOpen, openOptions);

doc.Close(false); // I use false to save because I already saved the model using doc.SaveAs() before closing

 

 


Viewing all articles
Browse latest Browse all 67020

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>