Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I struggle with this so much, I just don't understand how it works, I wish to know how to pass & access the UIDocument, Document from ANYWHERE.
My code below, "MySelectedElement(uidoc, doc)" has red squiggles how do I access uidoc, and doc from anywhere?
or create an object at will so I can access it.
Thanks
MySelectedElement(uidoc, doc); //<--- Method Call
namespace PreFab_AssemblyNumber
{
[TransactionAttribute(TransactionMode.Manual)]
public partial class RibbonTab_ModifyActive : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
#region !--> Load Document and UIDocument <--!
UIApplication app = commandData.Application;
UIDocument uidoc = app.ActiveUIDocument;
Document doc = app.ActiveUIDocument.Document;
#endregion Load Document and UIDocument
#region t.start
Transaction t = new Transaction(doc, "PreFab Number");
t.Start();
#endregion t.start
//-----------------------------------------------------------------------------------------
// **** CODE *******************************************************************************
//-----------------------------------------------------------------------------------------
FireEvent.PreFabEvent(uidoc, doc);
//-------------------------------------------------------------------------------------
// **** CODE ***************************************************************************
//-------------------------------------------------------------------------------------
#region t.commit
t.Commit();
#endregion t.commit
return Result.Succeeded;
}
// ----------------------------------------------------------------------------------------
// ****************************************************************************************
// ----------------------------------------------------------------------------------------
public static TaskDialogResult TD(string str)
{
return TaskDialog.Show("showTask", str);
}
public static TaskDialogResult TD(object obj)
{
return TaskDialog.Show("showTask", $"{obj}");
}
// ----------------------------------------------------------------------------------------
public class FireEvent
{
public static void PreFabEvent(UIDocument uidoc, Document doc)
{
// RibbonControl is the main Ribbon entry point, this is the Ribbon
Autodesk.Windows.RibbonControl ribbon = Autodesk.Windows.ComponentManager.Ribbon;
foreach (Autodesk.Windows.RibbonTab tab in ribbon.Tabs)
{
if (tab.Title == "Modify")
{
tab.PropertyChanged += EventMethods.PanelEvent;
break;
}
}
}
// ----------------------------------------------------------------------------------------
public class EventMethods
{
public static void PanelEvent(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
// List of Modify Tabs to trigger Event
List<string> listOfModifyTabs = new List<string>
{
"Modify | Generic Models",
"Modify | Lighting Fixtures",
"Modify | Fire Alarm Devices",
"Modify | Electrical Fixtures"
};
Autodesk.Windows.RibbonControl ribbon = Autodesk.Windows.ComponentManager.Ribbon;
if (sender is Autodesk.Windows.RibbonTab)
{
if (e.PropertyName == "Title")
{
foreach (Autodesk.Windows.RibbonTab t in ribbon.Tabs)
{
foreach (string s in listOfModifyTabs)
{
if (t.Title == s)
{
MySelectedElement(uidoc, doc); //<--- Method Call
}
}
}
}
}
}
}
// ----------------------------------------------------------------------------------------
private static void MySelectedElement(UIDocument uidoc, Document doc)
{
Guid guid = new Guid("343cc1fc-0a53-48e3-bce9-c5adcc118b0e"); //<-- Build function to return GUID from Shared Param file
if (uidoc.Selection.GetElementIds().Count() == 1)
{
Element e = doc.GetElement(uidoc.Selection.GetElementIds().ToList()[0]);
foreach (Parameter p in e.Parameters)
{
if (p.IsShared && p.GUID.Equals(guid))
{
TD(p.Definition.Name);
}
}
}
}
}
}
}
Solved! Go to Solution.