Hello there,
I have come up with an idea of a Macro and would like to know whether it could be done and how could it be done. I have been working in a project and need to detach it from central for all the partners involved in the project, it is kind of an arduous task.
Therefore, I have thought on developing a macro with macro manager where i could open the active document as detach from central and they save it into a file.
Is this possible?
Many thanks!
I don't know if you can instantly detach the current local file.
But honestly you dont want to do that. worksharing enviroment is sometimes quite delicate and if you start detatching local files you might be sending the wrong files. .
I would create it as:
1. Sync to central & close the document
2. Open the central, detach and discard all the worksets
something like this should workish...
ModelPath MyCentralFile = doc.GetWorksharingCentralModelPath(); OpenOptions openoptions = new OpenOptions(); OpenOptions.DetachFromCentralOption = DetachFromCentralOption.DetachAndDiscardWorksets; app.OpenAndActivateDocument(MyCentralFile, openoptions, false);
3. Save as a new file in folder x
4. Purge the drawing from all you dont need, save again
5. Done ?
Good luck!
We actually are going through a few network pathing changes. (IT side) That are causing our files to have to be detached ->preserved ->resaved (same name) and relinquished all worksets. Do you think your script could be adapted to do this thorughout a directory?
Hi
Some kind of below script can Help you
m_app = commandData.Application;
app = m_app.Application;
// Check worksharing mode of each document
// Open Revit projects
OpenFileDialog theDialogRevit = new OpenFileDialog();
theDialogRevit.Title = "Select Revit Project Files";
theDialogRevit.Filter = "RVT files|*.rvt";
theDialogRevit.FilterIndex = 1;
theDialogRevit.InitialDirectory = @"D:\";
theDialogRevit.Multiselect = true;
if (theDialogRevit.ShowDialog() == DialogResult.OK)
{
string mpath = "";
string mpathOnlyFilename = "";
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
folderBrowserDialog1.Description = "Select Folder Where Revit Projects to be Saved in Local";
folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK
{
mpath = folderBrowserDialog1.SelectedPath;
foreach (String projectPath in theDialogRevit.FileNames)
{
FileInfo filePath = new FileInfo(projectPath);
ModelPath mp = ModelPathUtils.ConvertUserVisiblePathToModelPath(filePath.FullName);
OpenOptions opt = new OpenOptions();
opt.DetachFromCentralOption = DetachFromCentralOption.DetachAndDiscardWorksets;
mpathOnlyFilename = filePath.Name;
Document openedDoc = app.OpenDocumentFile(mp, opt);
SaveAsOptions options = new SaveAsOptions();
options.OverwriteExistingFile = true;
ModelPath modelPathout = ModelPathUtils.ConvertUserVisiblePathToModelPath(mpath + "\\" + mpathOnlyFilename);
openedDoc.SaveAs(modelPathout, options);
openedDoc.Close(false);
}
}
}
Regards,
Thanks for sharing the code.
there is a minor typo in the second IF statement: Your code is missing the closing parenthesis - see in red
Environment.SpecialFolder.MyComputer;
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
mpath = folderBrowserDialog1.SelectedPath;
Hi!
I am trying to recreate the macro in Revit using your posted code, but have a problem with the m_app.Application as it is not defined.
for a record, there were System.IO ans System.Windows.Forms classes that were not defined in the Revit 2015 Macro SHrpDevelop.
Please, advise what is missing.
Thank you!
/*
* Created by SharpDevelop.
* User: user
* Date: 1/9/2017
* Time: 4:43 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.IO;
using System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
namespace test222
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")]
public partial class ThisDocument
{
private void Module_Startup(object sender, EventArgs e)
{
}
private void Module_Shutdown(object sender, EventArgs e)
{
}
public void exampleagain(){
ThisDocument.a
m_app = Document.Application;
app = m_app.Application;
// Check worksharing mode of each document
// Open Revit projects
OpenFileDialog theDialogRevit = new OpenFileDialog();
theDialogRevit.Title = "Select Revit Project Files";
theDialogRevit.Filter = "RVT files|*.rvt";
theDialogRevit.FilterIndex = 1;
theDialogRevit.InitialDirectory = @"D:\";
theDialogRevit.Multiselect = true;
if (theDialogRevit.ShowDialog() == DialogResult.OK)
{
string mpath = "";
string mpathOnlyFilename = "";
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
folderBrowserDialog1.Description = "Select Folder Where Revit Projects to be Saved in Local";
folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
mpath = folderBrowserDialog1.SelectedPath;
foreach (String projectPath in theDialogRevit.FileNames)
{
FileInfo filePath = new FileInfo(projectPath);
ModelPath mp = ModelPathUtils.ConvertUserVisiblePathToModelPath(filePath.FullName);
OpenOptions opt = new OpenOptions();
opt.DetachFromCentralOption = DetachFromCentralOption.DetachAndDiscardWorksets;
mpathOnlyFilename = filePath.Name;
Document openedDoc = app.OpenDocumentFile(mp, opt);
SaveAsOptions options = new SaveAsOptions();
options.OverwriteExistingFile = true;
ModelPath modelPathout = ModelPathUtils.ConvertUserVisiblePathToModelPath(mpath + "\\" + mpathOnlyFilename);
openedDoc.SaveAs(modelPathout, options);
openedDoc.Close(false);
}
}
}
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion
}
}
Hi,
Add
Autodesk.Revit.UI.UIApplication m_app;
Before
m_app = commandData.Application;
Check for following using and respected references
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.ApplicationServices;
using System.Windows.Forms;
using Autodesk.Revit;
using System.IO;
Regards,
Rajesh
here is the full solution- with some dialog for the user:
you need to add system references for the user dialog to work.
works in 2016, did not test in 2017
/*
* Created by SharpDevelop.
* User: gorina_admin
* Date: 9/30/2016
* Time: 2:09 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.ApplicationServices;
using System.IO;
using System.Windows.Forms;
namespace batch
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("30EBC375-5A4C-4917-AB07-D7212C9ED3FA")]
public partial class ThisApplication
{
private void Module_Startup(object sender, EventArgs e)
{
}
private void Module_Shutdown(object sender, EventArgs e)
{
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion
public void savenotworkshared()
{
OpenFileDialog theDialogRevit = new OpenFileDialog();
theDialogRevit.Title = "Select Revit Project Files";
theDialogRevit.Filter = "RVT files|*.rvt";
theDialogRevit.FilterIndex = 1;
theDialogRevit.InitialDirectory = @"C:\";
theDialogRevit.Multiselect = true;
if (theDialogRevit.ShowDialog() == DialogResult.OK)
{
string mpath = "";
string mpathOnlyFilename = "";
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
folderBrowserDialog1.Description = "Select Folder Where Revit Projects to be Saved in Local";
folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
mpath = folderBrowserDialog1.SelectedPath;
foreach (String projectPath in theDialogRevit.FileNames)
{
FileInfo filePath = new FileInfo(projectPath);
ModelPath mp = ModelPathUtils.ConvertUserVisiblePathToModelPath(filePath.FullName);
OpenOptions opt = new OpenOptions();
opt.DetachFromCentralOption = DetachFromCentralOption.DetachAndDiscardWorksets;
mpathOnlyFilename = filePath.Name;
Document openedDoc = Application.OpenDocumentFile(mp, opt);
SaveAsOptions options = new SaveAsOptions();
options.OverwriteExistingFile = true;
ModelPath modelPathout = ModelPathUtils.ConvertUserVisiblePathToModelPath(mpath + "\\" + mpathOnlyFilename);
openedDoc.SaveAs(modelPathout, options);
openedDoc.Close(false);
}
}
}
Helen Gorina
Perkins+Will
hey, can I get the final working macro for 2017. it will be very helpful.
thanks.
intercepting Revit messages is a herculean task where you need to know exactly what you are hunting for. Not feasible in a simple macro. My targeted use was for multiple linked room models in a gigantic hospital. Those were typical rooms with beds and other equipment, and the team for some reason used worksharing even though for each room type there was just one planner. When you have huge amount of linked workshared file, Revit performance takes a hit. After making them not workshared, performance improved significantly
I have tested in 2019- everything is working fine.
do not forget about references - you need to configure them on your system
and do not forget to re-build the solution on your machine
you need editing permissions to the folder where Revit stores Macros. Usually it is C:\ProgramData\Autodesk\Revit\Macros
Here is full code, and it works in any version of Revit from 2016 to 2019.1
/* * Created by SharpDevelop. * User: gorina_admin * Date: 9/30/2016 * Time: 2:09 PM * * To change this template use Tools | Options | Coding | Edit Standard Headers. * * rebuilt without errors for 2019.1 on 8/15/2018 * * * * * */ using System; using Autodesk.Revit.UI; using Autodesk.Revit.DB; using Autodesk.Revit.UI.Selection; using System.Collections.Generic; using System.Linq; using Autodesk.Revit.ApplicationServices; using System.IO; using System.Windows.Forms; namespace batch { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.DB.Macros.AddInId("30EBC375-5A4C-4917-AB07-D7212C9ED3FA")] public partial class ThisApplication { private void Module_Startup(object sender, EventArgs e) { } private void Module_Shutdown(object sender, EventArgs e) { } #region Revit Macros generated code private void InternalStartup() { this.Startup += new System.EventHandler(Module_Startup); this.Shutdown += new System.EventHandler(Module_Shutdown); } #endregion public void savenotworkshared() { OpenFileDialog theDialogRevit = new OpenFileDialog(); theDialogRevit.Title = "Select Revit Project Files"; theDialogRevit.Filter = "RVT files|*.rvt"; theDialogRevit.FilterIndex = 1; theDialogRevit.InitialDirectory = @"C:\"; theDialogRevit.Multiselect = true; if (theDialogRevit.ShowDialog() == DialogResult.OK) { string mpath = ""; string mpathOnlyFilename = ""; FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog(); folderBrowserDialog1.Description = "Select Folder Where Revit Projects to be Saved in Local"; folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer; if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { mpath = folderBrowserDialog1.SelectedPath; foreach (String projectPath in theDialogRevit.FileNames) { FileInfo filePath = new FileInfo(projectPath); ModelPath mp = ModelPathUtils.ConvertUserVisiblePathToModelPath(filePath.FullName); OpenOptions opt = new OpenOptions(); opt.DetachFromCentralOption = DetachFromCentralOption.DetachAndDiscardWorksets; mpathOnlyFilename = filePath.Name; Document openedDoc = Application.OpenDocumentFile(mp, opt); SaveAsOptions options = new SaveAsOptions(); options.OverwriteExistingFile = true; ModelPath modelPathout = ModelPathUtils.ConvertUserVisiblePathToModelPath(mpath + "\\" + mpathOnlyFilename); openedDoc.SaveAs(modelPathout, options); openedDoc.Close(false); } } } } } }
Hey Gorina,
I am new to Macros in Revit and I am trying your macro. Can you elaborate a little bit more on how to configure references or direct me to a source explaining those?
Thank you so much for your help!