Opening a Project programmatically in Plant3d using .NET

by Fenton Webb

Currently, for Plant3d 2012 and 2013 it’s not possible to use the PlantProject.LoadProject() function. The problem is that the Project Manager does not update.

The solution is to use the command line “-OPENPROJECT”, here’s how:

// open Plant3d project.xml by Fenton Webb, DevTech, 17/9/12    [CommandMethod("OpenMyProject")]    public void OpenMyProject()    {     // select project.xml     System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();     DirectoryInfo defaultPathDI = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));          dlg.InitialDirectory = defaultPathDI.FullName;     dlg.FileName = "project.xml";     dlg.Multiselect = false;          System.Windows.Forms.DialogResult dlgResult = dlg.ShowDialog();     // if ok     if (dlgResult == System.Windows.Forms.DialogResult.OK)     {      AcadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("-_.OPENPROJECT "" + dlg.FileName + ""n", true, false, true);             }    }        If the LoadProject() was working you would use it like this…         [CommandMethod("loadMyProject")]      public void loadProject()      {       // select project.xml       System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();       DirectoryInfo defaultPathDI = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));              dlg.InitialDirectory = defaultPathDI.FullName;       dlg.FileName = "project.xml";       dlg.Multiselect = false;              System.Windows.Forms.DialogResult dlgResult = dlg.ShowDialog();       // if ok       if (dlgResult == System.Windows.Forms.DialogResult.OK)       {        PlantProject pp = PlantProject.LoadProject(dlg.FileName, true, "", "");        PlantApplication.SetCurrentProject(pp, true);       }      }

Comments

3 responses to “Opening a Project programmatically in Plant3d using .NET”

  1. This doesn’t seem to work in Plant 3d 2015.

  2. Dave,
    To use this on 2015 you’ll need the Extension 1 available on subscription. Note that SP2 does not include it (tested here), also you need to install Extension 1 before SP2
    Regards,
    Augusto Goncalves

  3. Better way OpenProjectFileNoPrompt(string projectFile) from the PnPProjectManagerUI.dll

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading