Unable to hide element category in a view in Revit file - revit-api

I want to hide certain elements in the view.
I managed to hid (with view..HideCategoryTemporary) all the elements I wanted except the marked one in the picture attached.
3D_House_before_hide
Element snoop
This element is a building section of category OST_Viewers.
Manually hiding the element category via the view works, but fetching all OST_Viewers in the code and hiding them does not work.
The following code contain the building section elements in addition to the grids,
FilteredElementCollector viewers_sections = new FilteredElementCollector(doc, v_id).OfCategory(BuiltInCategory.OST_Viewers);
FilteredElementCollector grids = new FilteredElementCollector(doc, v_id).OfCategory(BuiltInCategory.OST_Grids);
FilteredElementCollector elements_to_be_hidden = new FilteredElementCollector(doc, v_id);
elements_to_be_hidden.UnionWith(viewers_sections).UnionWith(grids)
foreach (Element e in elements_to_be_hidden)
{
cur_view.HideCategoryTemporary(e.Category.Id);
}
I've checked that viewers_sections contains the mentioned building sections however it is not hidden from the view.
After hide
How do I hide these building sections?

Please use View#SetCategoryHidden instead to turn off the visibility of the category, the result of the View#HideCategoryTemporary will be reset after closing the file. Here is the working example:
var gridCate = this.Document.Settings.Categories.get_Item(BuiltInCategory.OST_Grids);
var sectionsCate = this.Document.Settings.Categories.get_Item(BuiltInCategory.OST_Sections);
using(var trans = new Transaction(this.Document))
{
trans.Start("Hide Grids & Secions");
this.ActiveView.SetCategoryHidden(gridCate.Id, true);
this.ActiveView.SetCategoryHidden(sectionsCate.Id, true);
trans.Commit();
}

Related

MFC MDI dynamically changing tab style from a property dialog

It has been 10 months since I worked on my app due to a death in the family, just started looking at it again and still not sure how to solve the problem.
The project inquires/help started here:
MFC MDI Collecting control states for the "apply" button routine
Since this is a specific focused question, I didn't want to muck up my other thread, so what I'd like to do is change the documents tab styles after the view is loaded. I know that this can be done because the master repository from Microsoft with all the code examples has a project called VCSamples-master\VCSamples-master\VC2010Samples\MFC\Visual C++ 2008 Feature Pack\TabControl which I have looked at. It dawns on me that even though I can follow its code, the calls are from within the MDI window itself where my issue is I'm trying to do this via a property page dialog using OnApply which changes things.
I was able to do part of this properly with the help of the thread above to the OutputPane successfully because I was able to get the Pane handle and execute. I was told that for the MDI tabs after creation that I need to parse the tabs, count them, and then execute. So my issue here is after I capture the tabs......how to change their styles.
Here is the code as it stands:
BOOL CSettingsUserTabs::OnApply()
{
BOOL bResult = CMFCPropertyPage::OnApply();
if (bResult)
{
// Update Output Pane Tab Styles (Works 100%)
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("UserTabStyle"), m_style_tabs); // Save value to registry
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.RecalcLayout();
//Get the open file tabs in the MDI
for (POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition(); pos != NULL; )
{
CDocTemplate* pTempl = AfxGetApp()->GetNextDocTemplate(pos);
for (POSITION pos1 = pTempl->GetFirstDocPosition(); pos1 != NULL; )
{
CDocument* pDoc = pTempl->GetNextDoc(pos1);
for (POSITION pos2 = pDoc->GetFirstViewPosition(); pos2 != NULL; )
{
CView* pView = pDoc->GetNextView(pos2);
if (pView->IsKindOf(RUNTIME_CLASS(CTrainView)))
{
// THIS IS WHERE MY ISSUE IS, NOW THAT ALL THE TABS ARE
// CAPTURED, HOW DO I ADDRESS THEM LIKE WHAT IS SHOWN
// ABOVE:
//((CMainFrame*)AfxGetMainWnd())->xxxxxx.yyyyyy.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
}
}
}
}
}
return bResult;
}
If I can figure this last piece out, I'll be basically finished, I just can't seem to find a solution on how to do this via property sheet via OnApply.
Any suggestions or actual code examples I can see to solve my problem?
FYI: No, I haven't had any time to take additional OOP to solve this. I'm hoping someone can provide some guidance so I can move on after getting this sorted.
Thanks,
Chris
EDIT 1:
So I took a closer look at Constantine's suggestion and here is what I came up with:
BOOL CSettingsUserTabs::OnApply()
{
BOOL bResult = CMFCPropertyPage::OnApply();
if (bResult)
{
// Update Output Pane Tab Styles
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("UserTabStyle"), m_style_tabs); // Save value to registry
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.RecalcLayout();
CMFCTabCtrl& MDI_STYLES = ((CMainFrame*)AfxGetMainWnd())->GetMDITabs();
MDI_STYLES.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
MDI_STYLES.RecalcLayout();
CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());
pMainFrame->SetFocus();
pMainFrame->RecalcLayout();
}
return bResult;
}
The m_styles_tabs is getting the index value of 0-8 when I select the radio button. The code compiles and runs and I see the index value change when I break on it, but the tabs for the MDI are still not updating. Does the edited code make sense based on the members shown here:
https://learn.microsoft.com/en-us/cpp/mfc/reference/cmfctabctrl-class?view=msvc-170#modifytabstyle
I think this the right direction, am I missing something?

Removing menu in MFC

In MFC how to remove a menu-item of POPUP type. RemoveMenu() either take ID or position. Since, there is no ID for POPUP menu, option left is by using position.
But I am not getting how and where I can call RemoveMenu().
File Edit Test
Test_submenu_1
Test_submenu_2
Test_submenu_3 > submenu_3_item_1
Test_submenu_4
Test_submenu_5
I want to remove Test_submenu_3? I am not getting how do find CMenu object for Test so that I can call RemoveMenu() by passing position "2" for submenu_3_item_1.
Any suggestion for doing this will be greatly appreciated.
Thanks!
You cannot use LoadMenu, since this function does just that.
After modifying loaded menu it is killed when menu object used to load it goes out of scope. You have to modify menu that is currently used.
Your menu is a popup part of the main menu, second in position. It contains 5 items and second one is another popup. To my understanding, you want to remove this item and popup of this item.
To make it work you will have to ask main window for the current menu:
CMenu* pMenu = GetMenu(); // get the main menu
CMenu* pPopupMenu = pMenu->GetSubMenu(2);//(Test menu with item....)
pPopupMenu->RemoveMenu(2, MF_BYPOSITION);
Of course, this code is from the main frame. If you want to use it elsewhere, you will have to access all using pointer to the main frame.
Try the below. You get the Test sub-menu first (index 2), then once you have that you tell it to remove its Test_submenu_3 submenu by position (also 2).
CMenu topMenu;
topMenu.LoadMenu(IDR_YOUR_MENU);
CMenu& testSubMenu = *topMenu.GetSubMenu(2);
testSubMenu.RemoveMenu(2,MF_BYPOSITION);
'Test' is the 3rd menu item (by position) on the top level menu. It's just been rendered horizontally rather than vertically. Assuming you have a handle to the top level menu use the same code you'd use to the get the sub menus as you would to get the 'Test' menu.
You can use this below code to remove the submenu, by comparing name
bool RemoveSubmenu(CMenu * pMenu) {
for (int pos = 0; pos < pMenu->GetMenuItemCount(); pos++) {
wchar_t *name = new wchar_t[mf.cch + 1];
MENUITEMINFO mf;
ZeroMemory(&mf, sizeof(mf));
mf.cbSize = sizeof(mf);
mf.fMask = MIIM_SUBMENU | MIIM_FTYPE | MIIM_STRING;
mf.fType = MIIM_STRING;
mf.dwTypeData = NULL;
if (!GetMenuItemInfo(pMenu->m_hMenu, pos, TRUE, &mf))
break;
if (mf.hSubMenu != NULL){
mf.fMask = MIIM_TYPE;
mf.fType = MFT_STRING;
++mf.cch;
mf.dwTypeData = (LPSTR)name;
if (!GetMenuItemInfo(pMenu->m_hMenu, pos, TRUE, &mf)){
bRet = false;
break;
}
//
// compare sub menu name (i.e mf.dwTypeData) here, do the required
// modifications
//
pMenu->RemoveMenu(pos, MF_BYPOSITION);
bRet = true;
break;
}
}
}

C# TableLayoutPanel replace control?

I was wondering if it was possible to replace one control in a TableLayoutPanel with another at runtime. I have a combo box and a button which are dynamically added to the TableLayoutPanel at runtime, and when the user selects an item in the combo box and hits the button, I'd like to replace the combobox with a label containing the text of the selected combo box item.
Basically, if I could simply remove the control and insert another at it's index, that would work for me. However I don't see an option like "splice" or "insert" on the Controls collection of the TableLayoutPanel, and I was wondering if there was a simple way to insert a control at a specific index. Thanks in advance.
Fixed this by populating a panel with the two controls I wanted to swap and putting that into the TableLayoutPanel. Then I set their visibility according to which I wanted to see at what time.
This is what I've been able to come up with for what I needed. It gets the position of the ComboBox and makes a new label using the selected value.
// Replaces a drop down menu with a label of the same value
private void lockDropMenu(ComboBox dropControl)
{
TableLayoutPanelCellPosition pos = myTable.GetCellPosition(dropControl);
Label lblValue = new Label();
myTable.Controls.Remove(dropControl);
if (dropControl.SelectedItem != null)
{
lblValue.Text = dropControl.SelectedItem.ToString();
lblValue.Font = lblValue.Font = dropControl.Font;
// Just my preferred formatting
lblValue.AutoSize = true;
lblValue.Dock = System.Windows.Forms.DockStyle.Fill;
lblValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
myTable.Controls.Add(lblValue, pos.Column, pos.Row);
}
}

Putting LinearLayout Inside Of ListView (Android)

I'm trying to programmatically put a LinearLayout inside of a ListView and am having some trouble. I want to do this so that I can insert horizontal columns inside each ListView cell. Here's the relevant snippet of code:
LinearLayout listArray[] = new LinearLayout[routeTable.GetTableHeight()];
for (int i = 0; i < routeTable.GetTableHeight(); i++) {
listArray[i] = new LinearLayout(this);
TextView view = new TextView(this);
view.setText(strList[i]);
listArray[i].addView(view);
}
// Create list
ListView list = new ListView(this);
list.setAdapter(new ArrayAdapter<LinearLayout>(this,
android.R.layout.simple_list_item_1, listArray));
layout.addView(list, new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
This compiles, but the resulting list that is displayed does not display any of the strings in strList[]. Instead, the list elements that are displayed appear something like "android.widget.LinearLayout#47b63c0". Does anybody know how I could fix this so that the appropriate TextViews that are inside of listArray[] would be displayed?
ArrayAdapter just calls .toString() method on each object in the list and displays the resulting string in each list item. In your case, .toString() is called on LinearLayout, that is what you see as list element. It is also not clear what are the elements of routeTable.
You should subclass BaseAdapter so that you can construct necessary View for each list item yourself.

Grouping custom tool parts in with other custom properties

I have a webpart. I have a list of items (schools) that I must pick from. This list comes from another Sharepoint list. I made a tool part. This tool part creates a drop down list and populates it with the correct data. When I went to edit the web part properties, the drop down list is sitting outside of any other group. I want to add that drop down list into the "Miscellaneous" group. If I can't put it there, I want to create a custom group.
How do I do this?
To add other groups, you will need some client manipulations (jquery).
Or you can just create extra groups:
protected override void CreateChildControls() {
Panel panel = new Panel();
panel.CssClass = "ms-ToolPartSpacing";
Table table = new Table();
table.CellPadding = 0;
table.CellSpacing = 0;
table.Style["border-collapse"] = "collapse";
table.Attributes.Add("width", "100%");
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Controls.Add(new LiteralControl("<div class=\"UserSectionHead\"><b>Your Other Group:</b></div>"));
cell.Controls.Add(new LiteralControl("<div class=\"UserSectionBody\"><div class=\"UserControlGroup\">"));
Table innertable = new Table();
//build your innertable
cell.Controls.Add(innertable);
cell.Controls.Add(new LiteralControl("</div></div>"));
cell.Controls.Add(new LiteralControl("<div style='width:100%' class='UserDottedLine'></div>"));
row.Cells.Add(cell);
table.Rows.Add(row);
panel.Controls.Add(table);
this.Controls.Add(panel);
base.CreateChildControls();
}

Resources