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: 

Can't hide group using view.HideElements

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
CADdaddy.com
3227 Views, 13 Replies

Can't hide group using view.HideElements

I get the following error when attempting to programatically hide a group.  I can hide a group manually so I don't understand why this wouldn't work.

 

This is my code (which works for other types of elements...just not groups):

 

view.HideElements(m_elemSet);

 

Here is the error:

 

Autodesk.Revit.Exceptions.ArgumentException was unhandled by user code
HResult=-2146233088
Message=One of the elements cannot be hidden.
Parameter name: elementIdSet
Source=RevitAPI
ParamName=elementIdSet
StackTrace:
at Autodesk.Revit.DB.View.HideElements(ICollection`1 elementIdSet)
at DADY.HideInViews.HideInViewsForm.btnOK_Click(Object sender, EventArgs e) in Q:\CADcoop\source\CADdaddy Tools for Revit 2014\CADdaddy Revit Tools Application\HideInViewsForm.cs:line 180
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at DADY.HideInViews.Command.Execute(ExternalCommandData cData, String& msg1, ElementSet elems) in Q:\CADcoop\source\CADdaddy Tools for Revit 2014\CADdaddy Revit Tools Application\HideInViews.cs:line 54
at apiManagedExecuteCommand(AString* assemblyName, AString* className, AString* vendorDescription, MFCApp* pMFCApp, DBView* pDBView, AString* message, Set<ElementId\,std::less<ElementId>\,tnallc<ElementId> >* ids, Map<AString\,AString\,std::less<AString>\,tnallc<AString> >* data, AString* exceptionName, AString* exceptionMessage)
InnerException:

13 REPLIES 13
Message 2 of 14
Ning_Zhou
in reply to: CADdaddy.com

maybe it's because of curtain wall or stacked wall instead of group? perhaps you can try ungroup one instance and using API to hide these ungrouped members.
some inconsistencies exist in API graphics/overrides, curtain/stacked wall are the ones i encountered before.
Message 3 of 14
CADdaddy.com
in reply to: CADdaddy.com

I don't think that is it.  I am hiding a group that I created myself out of families that I created myself.  It also occurs when I make a group out of furniture families in a completely different model.  I debugged and it is pretty clear that if the elementset contains the elementID of a group then it crashes.  Do I really have to remove all the elementIDs that belong to groups from my elementset and then find all the elementID contained in each group and then add those IDs to my element set?  And then you also have to worry about groups inside of other groups.  I can manually hide a group that contains a nested group with no problem.  It seems there is a whole lotta hassle going on here when it should just work the same way as it does manually.

 

I guess I now must ask...what is the best way to aquire the elementIDs of the elements contained in a group?

 

I found Jeremy's post http://thebuildingcoder.typepad.com/blog/2010/08/editing-elements-inside-groups.html which seems to say that element properties cannot be changed in groups.  The post is pretty old but let's assume that this is still the case.  Does that mean I have to ungroup the group, acquire all the elementIDs, hide the elements, then re-group?  It still sounds crazy and I still don't understand why, if it can be done easily manually, we can't be offered the same functionality in the API.

 

James LeVieux

Message 4 of 14
Ning_Zhou
in reply to: CADdaddy.com

right, group editing in API still remains very limited, means you still have to ungroup / regroup it which makes editing nested groups almost impossible.
Message 5 of 14
Joe.Ye
in reply to: CADdaddy.com

Groups cannot be hidden or overridde like ordinary elements. In order to hide a group, we need to hide the element set in that group by HideElements() method. The good aspect is that we can hide part of a group.

Here is the code to hide the whole group.

public void hidegroup()
{
Document doc = this.ActiveUIDocument.Document;

Selection sel = this.ActiveUIDocument.Selection;

Reference ref1 = sel.PickObject(ObjectType.Element,"Please pick a group");

Element elem = doc.GetElement(ref1);

IList<ElementId> lists = new List<ElementId>();

Group g = elem as Group;

IList<ElementId> ids = g.GetMemberIds();

Transaction trans = new Transaction(doc);

trans.Start("hidegroup");

this.ActiveUIDocument.ActiveView.HideElements(ids);

trans.Commit ();

}



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Message 6 of 14
CADdaddy.com
in reply to: Joe.Ye

Thanks Joe,  I'll try that out next week!

 

james

Message 7 of 14
Anonymous
in reply to: Joe.Ye

Hello,Joe! I have a question in using your code compiled in visual studio2010 c# class environment : "this.ActiveUIDocument" have not difined in command.
Message 8 of 14
R.van.den.Bor
in reply to: Anonymous

Another danger I would like to point out is that by ungrouping and regrouping, Revit will give the new group an unique new ID. So if you have some data export/import tools that rely on the elemt ID, this can be a showstopper. 

 

Remy.

 

Kind regards,
Remy van den Bor
ICN Solutions B.V.
Liked this post or found it usefull, don't forget the Kudo It won't hurt (at least not me).
Message 9 of 14
Joe.Ye
in reply to: Anonymous

Hi This code is the SharpDevelop code. When you use it in Visual Studio, please replace this.ActiveUIDocument with the target document variable.


Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Message 10 of 14
Anonymous
in reply to: Joe.Ye

hi,how about my following code,it does not work in my rvt 

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)
{

//Here is the code to hide the whole group.
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element, "Please pick a group");
Element elem = doc.GetElement(ref1);
IList<ElementId> lists = new List<ElementId>();
Group g = elem as Group;
IList<ElementId> ids = g.GetMemberIds();
Transaction trans = new Transaction(doc);
trans.Start("hidegroup");
uidoc.ActiveView.HideElements(ids);
trans.Commit();
return Autodesk.Revit.UI.Result.Succeeded;
}

}
}

Message 11 of 14
Joe.Ye
in reply to: Anonymous

 

what's the problem when you run this command? Just cannot hide group members? or error/warning message?

 

I can run this command in my side without problem. It can hide element in the picked group.



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Message 12 of 14
Anonymous
in reply to: Joe.Ye

I can run this command in my side without problem. But it can't hide element .

I check my rvt file carefully once more, maybe their elements had been defined with family class, can you look at my file and try my code again? 

Message 13 of 14
Joe.Ye
in reply to: Anonymous

 

There is no group in your uploaded model.



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Message 14 of 14
Anonymous
in reply to: Joe.Ye

Thanks!

But i wonder how to hide all walls in my rvt file with codes just a first step.

Abstracting structural info is my ultimate aim with a command

Could you give me a hand and tell me how to realize it

The following is my code : 

public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
ref string message, Autodesk.Revit.DB.ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection selection = uidoc.Selection;
ElementSet collection = selection.Elements;
try
{
FilteredElementCollector collector = new FilteredElementCollector(doc);// Apply the filter to the elements in the active document
collector.OfClass(typeof(Element));//apply a filter to get all elements in the document
FilteredElementIterator eItr = collector.GetElementIterator();// Get results as Element iterator
eItr.Reset();
while (eItr.MoveNext())
{
Element el = eItr.Current as Element;
Family fm = el as Family;
if (fm != null)
{
}
catch (Exception e)
{
message = e.Message;
return Autodesk.Revit.UI.Result.Failed;
}
return Autodesk.Revit.UI.Result.Succeeded;
}

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community