I’m reaching out for assistance with troubleshooting errors in a custom tool we’ve developed. We’ve begun creating our own tools, but several projects utilizing this specific tool are encountering an error. All projects are within ACC and configured identically. The error only occurs on some projects, and occasionally resolves itself.
The tool’s function is to hide all text, detail components, and symbols with “H4P” (Hide for Print) at the end of their type name. This enables us to include internal comments on construction documents that we can address during the project, while preventing these items from printing on external drawings.
Error is
“One if the elements cannot be hidden.
Parameter name: elementldSet”
Additionally, we have two separate tools: one to hide all “H4P” items and one to reveal them. Is it possible to combine these into a single tool with an indicator of its active state?
Thank you for your time and any guidance you can provide.
Here is the Hide4Print Script
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import TaskDialog
import clr
clr.AddReference(“System”)
from System.Collections.Generic import List
Access Revit document, UIDocument, and Application
doc = revit.ActiveUIDocument.Document
uidoc = revit.ActiveUIDocument
app = revit.Application
def get_elements_by_type_name(type_name):
“”"
Retrieves element IDs from the Revit document where the element type name matches type_name
.
“”"
try:
# Parameter to filter by element type name
p_type_id = ElementId(BuiltInParameter.SYMBOL_NAME_PARAM)
f_param = ParameterValueProvider(p_type_id)
evaluator = FilterStringContains()
value = type_name
# Handle version-specific differences in FilterStringRule
rvt_year = int(app.VersionNumber)
if rvt_year >= 2023:
f_rule = FilterStringRule(f_param, evaluator, value)
else:
f_rule = FilterStringRule(f_param, evaluator, value, False)
filter_type_name = ElementParameterFilter(f_rule)
# Collect and return element IDs
element_ids = FilteredElementCollector(doc).WherePasses(filter_type_name).WhereElementIsNotElementType().ToElementIds()
return element_ids
except Exception as e:
# Handle any errors that occur
TaskDialog.Show("Error", str(e))
return []
def hide_element_in_drafting_views(element_ids, doc_hide):
# Start a transaction to modify the document
t = Transaction(doc_hide, “Hide Elements in Drafting Views”)
t.Start()
try:
# Collect all drafting views
drafting_views = FilteredElementCollector(doc_hide).OfClass(ViewDrafting).ToElements()
# Collect all Sheet views
sheet_views = FilteredElementCollector(doc_hide).OfClass(ViewSheet).ToElements()
# Collect all Sheet views
plan_views = FilteredElementCollector(doc_hide).OfClass(ViewPlan).ToElements()
# Collect all legend views
legend_views = FilteredElementCollector(doc_hide).OfClass(View).ToElements()
legend_views = [v for v in legend_views if v.ViewType == ViewType.Legend]
# Iterate through each drafting view
for view in drafting_views:
# Hide the elements in the view
view.HideElements(element_ids)
# Iterate through each sheet view
for view in sheet_views:
# Hide the elements in the view
view.HideElements(element_ids)
# Iterate through each sheet view
for view in plan_views:
# Hide the elements in the view
view.HideElements(element_ids)
# Iterate through each sheet view
for view in legend_views:
# Hide the elements in the view
view.HideElements(element_ids)
t.Commit() # Commit the transaction
except Exception as e:
t.RollBack() # Rollback if there's an error
TaskDialog.Show("Error", str(e))
def select_elements(type_name):
# Get the current document and application
uiapp = revit.ActiveUIDocument.Application
doc_hide = uiapp.ActiveUIDocument.Document
# Get elements by type name
element_ids = get_elements_by_type_name(type_name)
# Call the function to hide the element
hide_element_in_drafting_views(element_ids, doc_hide)
Call function to select elements with specified type name
type_name = ‘H4P’
select_elements(type_name)
Here is the Unhide script
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import TaskDialog
import clr
clr.AddReference(“System”)
from System.Collections.Generic import List
Access Revit document, UIDocument, and Application
doc = revit.ActiveUIDocument.Document
uidoc = revit.ActiveUIDocument
app = revit.Application
def get_elements_by_type_name(type_name):
“”"
Retrieves element IDs from the Revit document where the element type name matches type_name
.
“”"
try:
# Parameter to filter by element type name
p_type_id = ElementId(BuiltInParameter.SYMBOL_NAME_PARAM)
f_param = ParameterValueProvider(p_type_id)
evaluator = FilterStringContains()
value = type_name
# Handle version-specific differences in FilterStringRule
rvt_year = int(app.VersionNumber)
if rvt_year >= 2023:
f_rule = FilterStringRule(f_param, evaluator, value)
else:
f_rule = FilterStringRule(f_param, evaluator, value, False)
filter_type_name = ElementParameterFilter(f_rule)
# Collect and return element IDs
element_ids = FilteredElementCollector(doc).WherePasses(filter_type_name).WhereElementIsNotElementType().ToElementIds()
return element_ids
except Exception as e:
# Handle any errors that occur
TaskDialog.Show("Error", str(e))
return []
def hide_element_in_drafting_views(element_ids, doc_hide):
# Start a transaction to modify the document
t = Transaction(doc_hide, “Hide Elements in Drafting Views”)
t.Start()
try:
# Collect all drafting views
drafting_views = FilteredElementCollector(doc_hide).OfClass(ViewDrafting).ToElements()
# Collect all Sheet views
sheet_views = FilteredElementCollector(doc_hide).OfClass(ViewSheet).ToElements()
# Collect all Sheet views
plan_views = FilteredElementCollector(doc_hide).OfClass(ViewPlan).ToElements()
# Collect all legend views
legend_views = FilteredElementCollector(doc_hide).OfClass(View).ToElements()
legend_views = [v for v in legend_views if v.ViewType == ViewType.Legend]
# Iterate through each drafting view
for view in drafting_views:
# Hide the elements in the view
view.UnhideElements(element_ids)
# Iterate through each sheet view
for view in sheet_views:
# Hide the elements in the view
view.UnhideElements(element_ids)
# Iterate through each sheet view
for view in plan_views:
# Hide the elements in the view
view.UnhideElements(element_ids)
# Iterate through each sheet view
for view in legend_views:
# Hide the elements in the view
view.UnhideElements(element_ids)
t.Commit() # Commit the transaction
except Exception as e:
t.RollBack() # Rollback if there's an error
TaskDialog.Show("Error", str(e))
def select_elements(type_name):
# Get the current document and application
uiapp = revit.ActiveUIDocument.Application
doc_hide = uiapp.ActiveUIDocument.Document
# Get elements by type name
element_ids = get_elements_by_type_name(type_name)
# Call the function to hide the element
hide_element_in_drafting_views(element_ids, doc_hide)
Call function to select elements with specified type name
type_name = ‘H4P’
select_elements(type_name)
Sincerely,
Matthew