Close All Hidden by API

Close All Hidden by API

Dale.Bartlett
Collaborator Collaborator
2,120 Views
10 Replies
Message 1 of 11

Close All Hidden by API

Dale.Bartlett
Collaborator
Collaborator

Hi All, I have exhausted the usual sources... Can anyone supply sample code to cause a "Close All Hidden" action? Or how do I call a native Revit command in code? 2011 or 2012. It seems so simple, all help gratefully appreciated. Dale 




______________
Yes, I'm Satoshi.
0 Likes
2,121 Views
10 Replies
Replies (10)
Message 2 of 11

jeremytammik
Autodesk
Autodesk

Dear Dale,

I am afraid there is no official API solution to access the "Close All Hidden" functionality, and definitely not to call a native Revit command.

All that I can suggest is to explore using the Windows API or porobably better and easier the UI Automation libraries as described in various examples by Rudolf Honke:

http://thebuildingcoder.typepad.com/blog/automation


Completely unsupported and at your own risk!

 

Best regards,

Jeremy
--
Jeremy Tammik
Autodesk Developer Network -- http://www.autodesk.com/joinadn
The Building Coder -- http://thebuildingcoder.typepad.com




Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 11

Dale.Bartlett
Collaborator
Collaborator

Hi Jeremy, Thanks for the reply. Pleased I wasn't tooo dumb, but surprised there isn't a function; I'll investigate your suggestions. I guess the API has a way to go to catch up to AutoCAD. My project was to be a "Close to Default View" function to leave Revit projects on the same view. Seemed so simple. I know with 2012 I can set the View. Regards, Dale  




______________
Yes, I'm Satoshi.
0 Likes
Message 4 of 11

RevitArkitek
Enthusiast
Enthusiast

In case anyone is interested, in 2014 there is a Close() method.  I used it like this:

 

// get open views to close all except the active view
IList<UIView> openViews = uidoc.GetOpenUIViews();
foreach (UIView uiv in openViews)
{
    if (uiv.ViewId != uidoc.ActiveView.Id)
    {
        uiv.Close();
    }
}

 It only works on the active document.  I'm not sure if you could close views in other documents by switching the active uidoc/document.



Message 5 of 11

Anonymous
Not applicable

hello, It is not worked in my rvt file with your code. Check my code if there is any problem. pls using System;
using System.Linq; using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
namespace command2
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
[Journaling(JournalingMode.NoCommandData)]
public class command2 : IExternalCommand
{
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
ref string message, Autodesk.Revit.DB.ElementSet elements)
{
Document doc = commandData.Application.ActiveUIDocument.Document;
UIDocument uidoc = commandData.Application.ActiveUIDocument;
// Selection sel = uidoc.Selection;

// get open views to close all except the active view
IList<UIView> openViews = uidoc.GetOpenUIViews();
foreach (UIView uiv in openViews)
{
if (uiv.ViewId != uidoc.ActiveView.Id)
{
uiv.Close();
}
}
return Autodesk.Revit.UI.Result.Succeeded;


}

}
}

0 Likes
Message 6 of 11

RevitArkitek
Enthusiast
Enthusiast
I was merely providing a code snippet, not entire external command. But congrats on achieving that.
0 Likes
Message 7 of 11

Anonymous
Not applicable
pyrosim

Your code works for me.

Does it error out or just not do anything?

If error, can you post the dialog?

Did you register properly in the *.addin file?
0 Likes
Message 8 of 11

RevitArkitek
Enthusiast
Enthusiast

Sorry, I misread your reply.  I thought you had it working as an external command.  

0 Likes
Message 9 of 11

Anonymous
Not applicable

ye,I had it working as an external command .  does it wrong seriously?

Becouse It does nothing when I put this externalcommand to rvt file.

My revit version is 2014 and vs is 2010

And my rvt file is too big, give a email address ,I will send it to you have a look

Thanks for your support!

 

0 Likes
Message 10 of 11

Anonymous
Not applicable

hi peter,
It does nothing when I put my above externalcommand to rvt file.
I don't know how to check my *.addin file , could you tell me the register method , my revit version is 2014 and vs is 2010
Thanks for your support,let's make it work together!
my rvt file is too big, give a email address ,I will send it to you

0 Likes
Message 11 of 11

Anonymous
Not applicable
No need to send the Revit file. You can test your command on any file.

How are you telling Revit to find and run your command? Is it a macro?
0 Likes