- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello i am currently working on a Macro that takes the Central model path and places it on a shared parameter on the title block label. At this stage i just need to read a central on our server i am aware that BIM360 needs more work but i just need something simple right now.
Here is the code:
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.DB.Events;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.ApplicationServices;
using System.Text;
namespace TestMacro5
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("44DC398D-02D1-4883-9F4C-CA13E178BA72")]
public partial class ThisDocument
{
private void Module_Startup(object sender, EventArgs e)
{
this.Application.Application.FileExporting += new EventHandler<Autodesk.Revit.DB.Events.FileExportingEventArgs>(CENTRALPATH_TO_CentralSTRG);
}
private void Module_Shutdown(object sender, EventArgs e)
{
this.Application.Application.FileExporting -= new EventHandler<Autodesk.Revit.DB.Events.FileExportingEventArgs>(CENTRALPATH_TO_CentralSTRG);
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion
internal void CENTRALPATH_TO_CentralSTRG(object sender, FileExportingEventArgs args)
{
UIDocument uidoc = this;
View view = uidoc.ActiveView;
// collect the titleblock and the parameter used
string VisiblePath = ModelPath.GetWorksharingCentralModelPath();
string titleBlockFamilyTypeName = "D 22 x 34 Horizontal";
string parameterName = "CentralSTRG";
FamilyInstance titleBlock = new FilteredElementCollector(uidoc.Document, view.Id)
.OfCategory(BuiltInCategory.OST_TitleBlocks)
.OfClass(typeof(FamilyInstance))
.Cast<FamilyInstance>()
.Where(f => f.Name == titleBlockFamilyTypeName)
.FirstOrDefault();
//set the parameter to central file path.
using (Transaction tr = new Transaction(uidoc.Document))
{
tr.Start("setting titleblock parameter");
titleBlock.GetParameters(parameterName).FirstOrDefault().Set(VisiblePath);
tr.Commit();
}
}
}}
I cannot seem to figure out why i get error CS0117, Autodesk.Revit.DB.ModelPath. reading the documentation seems to indicate the method is part of the class. So i dont know if i am missing a call to a namespace?
As you can probably tell i am very new at this and this code above is a result of asking question on other forums and reading the web.
I have asked this question on other forums with a different line of code and some background given here: https://www.revitforum.org/node/450494#post450506
Udpate i got this to work following some advice from this forum: https://forums.autodesk.com/t5/revit-api-forum/file-based-central-model-path/td-p/6946021
However the output is blank i dont know if i have everything set up correctly.
Here is the new Code:
using System;
using System.Diagnostics;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.ApplicationServices;
using System.Text;
namespace TestMacro5
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("44DC398D-02D1-4883-9F4C-CA13E178BA72")]
public partial class ThisDocument
{
private void Module_Startup(object sender, EventArgs e)
{
this.Application.Application.FileExporting += new EventHandler<Autodesk.Revit.DB.Events.FileExportingEventArgs>(CENTRALPATH_TO_CentralSTRG);
}
private void Module_Shutdown(object sender, EventArgs e)
{
this.Application.Application.FileExporting -= new EventHandler<Autodesk.Revit.DB.Events.FileExportingEventArgs>(CENTRALPATH_TO_CentralSTRG);
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion
internal void CENTRALPATH_TO_CentralSTRG(object sender, FileExportingEventArgs args)
{
UIDocument uidoc = this;
View view = uidoc.ActiveView;
// collect the titleblock and the parameter extract central path
var ModelPath = Document.GetWorksharingCentralModelPath();
var CentralServerPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(ModelPath);
string titleBlockFamilyTypeName = "D 22 x 34 Horizontal";
string parameterName = "CentralSTRG";
FamilyInstance titleBlock = new FilteredElementCollector(uidoc.Document, view.Id)
.OfCategory(BuiltInCategory.OST_TitleBlocks)
.OfClass(typeof(FamilyInstance))
.Cast<FamilyInstance>()
.Where(f => f.Name == titleBlockFamilyTypeName)
.FirstOrDefault();
//set the parameter to central file path.
using (Transaction tr = new Transaction(uidoc.Document))
{
tr.Start("setting titleblock parameter");
titleBlock.GetParameters(parameterName).FirstOrDefault().Set(CentralServerPath);
tr.Commit();
}
}
}}
Solved! Go to Solution.