Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I get a list of open viewports of open projects?

1 REPLY 1
SOLVED
Reply
Message 1 of 2
ankofl
146 Views, 1 Reply

How do I get a list of open viewports of open projects?

I want to change their color depending on the belonging to the project. I have already managed to assign a color in this way for the custom button panels being created:

 

 

 

 

foreach (var item in AW.ComponentManager.Ribbon.Tabs.Where(t => t.Name != null && t.Name.Contains(UpdaterButtonData.TabName)).First().Panels)
{
	item.CustomPanelBackground = UpdaterApplication.GetRandomBrush();
	item.CustomPanelTitleBarBackground = UpdaterApplication.GetRandomBrush();
}

 

 

 

 

 

ankofl_1-1719229465801.png
but I can't figure out how to get a similar list of open viewports panels for open projects.

 

 

 

 

[Transaction(TransactionMode.Manual)]
public class CommandColor : IExternalCommand
{
	public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
	{
		var ribbon = AW.ComponentManager.Ribbon;
		Border p1 = (Border)ribbon.Parent;
		StackPanel p2 = (StackPanel)p1.Parent;
		Grid p3 = (Grid)p2.Parent;
		Grid p4 = (Grid)p3.Parent;
		MainWindow mainWindow = (MainWindow)p4.Parent;

		return Result.Succeeded;
	}
}

 

 

 

 

Inside the debugger, I see the following set of UI elements
ankofl_0-1719229188685.png

Thanks!

UPD:
It's funny that the following code:

 

 

foreach (AW.RibbonTab ribbonTab in listDelTab)
{
	AW.ComponentManager.Ribbon.Tabs.Remove(ribbonTab);
}	

 

 

in verbs removes the Tab from the Ribbon, but does it only visually, because all the deleted Tabs still remain somewhere inside the Ribbon.

If you try to add a Tab with the same name after deleting the Tab, you will get an exception, saying that a Tab with the same name already exists, despite the fact that you have already "deleted" it and it has even disappeared from Ribbon!

And moreover, if you try to add your Tabs a large number of times (I have 19), then you will get exceptions like:

Снимок экрана 2024-06-24 150515.jpg

 

 

1 REPLY 1
Message 2 of 2
Mohamed_Arshad
in reply to: ankofl

HI @ankofl 

 

    To Get List of Opened View, you need to use GetOpenUIViews() method.

 

IList<UIView> views= commandData.Application.ActiveUIDocument.GetOpenUIViews();

 

   For Color Changing of the ViewTab you need to refer the @Moustafa_K post he clearly documented how to change color of the ViewTab.

 

MoustafaK Post URL: https://forums.autodesk.com/t5/revit-api-forum/how-to-change-revit-ribbon-tab-color/td-p/9761734 

https://sharpbim.hashnode.dev/styling-revit-ui 

 

Hope this will Helps 🙂

 

Thanks & Regards,
Mohamed Arshad K

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report