- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm looking to explode objects generated as a result of a SAT (or DWG) import into a family document.
I found some code from many years ago suggesting UI automation is the way to achieve this. Is there a better way? (I couldn't find anything).
The code suggested something like this, trouble is the explode button is null. How do you determine the code to detect the explode button (I suspect the button might have subsequently changed).
Thanks,
Jon
Element el = famDoc.GetElement(famDoc.Import(filename, options, view));
if(el != null)
{
UIDocument uiDoc = (new UIApplication(famDoc.Application)).ActiveUIDocument;
SelElementSet seleset = SelElementSet.Create();
SelElementSet selements = uiDoc.Selection.Elements;
seleset.Insert(el);
selements.Clear();
uiDoc.Selection.Elements = seleset;
famDoc.Regenerate();
Process[] processes = Process.GetProcessesByName( "Revit" );
if (processes.Length > 0)
{
PropertyCondition aidCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, "2288");
AutomationElement ae = AutomationElement.FromHandle(processes[0].MainWindowHandle);
AutomationElement explodeButton = ae.FindFirst(TreeScope.Children, aidCondition);
if (explodeButton != null)
{
try
{
InvokePattern invPattern = explodeButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
invPattern.Invoke();
}
catch (Exception) { }
}
}
}
Solved! Go to Solution.