Get workset parameter for ParameterFilterRuleFactory

Is there a way to specify which method you want to use when the method has the same name as another. I’m trying to create a filter rule with worksets equal x. It seems to me that I would use CreateEqualsRule(ElementId, ElementId) as linked below but I’m getting an error that it is expecting a string. When I change my code to worksetValue.Name the script works but no value is entered for the filter.

rule = (ParameterFilterRuleFactory.CreateEqualsRule(needCalloutid, 1),
ParameterFilterRuleFactory.CreateEqualsRule(worksetId, worksetValue.Name))

----------Below is the old issue that I have worked out--------------------
I’m trying to create a filter the uses one of my shared parameters and a workset. I’ve been able to get the shared parameter from ParameterFilterUtilities.GetFilterableParametersInCommon but it doesn’t seem to be getting the workset parameter. I believe it should be showing up as a common parameter. Below are the categories of the filter, I don’t see anything that would rule out workset.

# Create filter category
catbuiltinList = (BuiltInCategory.OST_CableTrayFitting,BuiltInCategory.OST_CommunicationDevices,
            BuiltInCategory.OST_ConduitFitting,BuiltInCategory.OST_DataDevices,
            BuiltInCategory.OST_DuctAccessory,BuiltInCategory.OST_DuctFitting,
            BuiltInCategory.OST_DuctTerminal,BuiltInCategory.OST_ElectricalEquipment,
            BuiltInCategory.OST_ElectricalFixtures,BuiltInCategory.OST_FireAlarmDevices,
            BuiltInCategory.OST_LightingDevices,BuiltInCategory.OST_LightingFixtures,
            BuiltInCategory.OST_MechanicalControlDevices,BuiltInCategory.OST_MechanicalEquipment,
            BuiltInCategory.OST_NurseCallDevices,BuiltInCategory.OST_PipeAccessory,
            BuiltInCategory.OST_PipeFitting,BuiltInCategory.OST_PlumbingEquipment,
            BuiltInCategory.OST_PlumbingFixtures,BuiltInCategory.OST_SecurityDevices,
            BuiltInCategory.OST_Sprinklers,BuiltInCategory.OST_TelephoneDevices)
catList = []
for c in catbuiltinList:
    catList.append(Category.GetCategory(doc,c))
cat_ids = List[ElementId]([c.Id for c in catList])
filterCat = FilterCategoryRule(cat_ids)

# Get filter parameter
fparam_all = ParameterFilterUtilities.GetFilterableParametersInCommon(doc,cat_ids)
needCalloutid = []
for p in fparam_all:
    pdef = Document.GetElement(doc,p)
    if pdef:
        if pdef.Name == "Com_NeedsCallout":
            needCalloutid = p
        else:
            pass
    else:
        pass

worksetId = []
for p in fparam_all:
    pdef = Document.GetElement(doc,p)
    if pdef:
        print(pdef.Name)
        if pdef.Name == "Workset":
            worksetId = p
        else:
            pass
    else:
        pass

print(worksetId)

rule = ParameterFilterRuleFactory.CreateEqualsRule(needCalloutid, 0)
elementFilter = ElementParameterFilter(rule)

I’ve now switched to the code below, but can’t seem to get the parameter’s Id.

worksetId = []
bip_all = ParameterUtils.GetAllBuiltInParameters()
for p in bip_all:
    testpara = ParameterUtils.GetBuiltInParameter(p)
    if str(testpara) == "ELEM_PARTITION_PARAM":
        worksetId = p.Id
        print(worksetId)
    else:
        pass

Just found ElementId() in plain sight. Will see if that works for creating a filter rule.

worksetId = []
bip_all = ParameterUtils.GetAllBuiltInParameters()
for p in bip_all:
    testpara = ParameterUtils.GetBuiltInParameter(p)
    if str(testpara) == "ELEM_PARTITION_PARAM":
        worksetId = ElementId(testpara)
        print(worksetId)
    else:
        pass

hmm yeah usually the types kind of match up, I’m pretty sure there’s some automatic selecting of the best function to fit the parameters going on. And most of them have a different amount of arguments anyway.

That being said, that won’t help you I suspect.

Now I’m not sure which type that worksetId is supposed to be. But the function requires it to be an elementId to the parameter. But the name ‘worksetId’ sort of implies it’s the value of a worksetid.
Are you 100% sure that it is an elementId? Because I don’t think that function allows worksetids.

If that’s not it then it might be a longshot but… maybe a clr.Strongbox can help you out here?
Usually a strongbox is used for use in ‘out’ parameters for C# methods, but maybe (because it’s typed) you can also use it for those specific function calls?

Creating a strongbox is easy:

from clr import StrongBox
workset_id = StrongBox[DB.ElementId]()

I suspect you can set a value for it as well.

I haven’t used it for years, but you can try:

METHOD.Overloads.Functions[XXX](args) where XXX is 0..N (number of overloads)

so

> CreateEqualsRule.Overloads.Functions[0](ElemenId1,ElemenId2)
> CreateEqualsRule.Overloads.Functions[1](ElemenId1,ElemenId2)
> CreateEqualsRule.Overloads.Functions[2](ElemenId1,ElemenId2)
> CreateEqualsRule.Overloads.Functions[3](ElemenId1,ElemenId2)

one of above should work

Do you think that those function indexes are going to be reliable?

Here is a larger snippet of the filter code. I don’t think it has anything to do with my worsetId variable because if I set the value to of “CreateEqualsRule” to “worksetValue.Name” it works but with no value entered for the rule.

# Create filter category
catbuiltinList = (BuiltInCategory.OST_CableTrayFitting,BuiltInCategory.OST_CommunicationDevices,
            BuiltInCategory.OST_ConduitFitting,BuiltInCategory.OST_DataDevices,
            BuiltInCategory.OST_DuctAccessory,BuiltInCategory.OST_DuctFitting,
            BuiltInCategory.OST_DuctTerminal,BuiltInCategory.OST_ElectricalEquipment,
            BuiltInCategory.OST_ElectricalFixtures,BuiltInCategory.OST_FireAlarmDevices,
            BuiltInCategory.OST_LightingDevices,BuiltInCategory.OST_LightingFixtures,
            BuiltInCategory.OST_MechanicalControlDevices,BuiltInCategory.OST_MechanicalEquipment,
            BuiltInCategory.OST_NurseCallDevices,BuiltInCategory.OST_PipeAccessory,
            BuiltInCategory.OST_PipeFitting,BuiltInCategory.OST_PlumbingEquipment,
            BuiltInCategory.OST_PlumbingFixtures,BuiltInCategory.OST_SecurityDevices,
            BuiltInCategory.OST_Sprinklers,BuiltInCategory.OST_TelephoneDevices)
catList = []
for c in catbuiltinList:
    catList.append(Category.GetCategory(doc,c))
cat_ids = List[ElementId]([c.Id for c in catList])
filterCat = FilterCategoryRule(cat_ids)

# Get filter parameter
fparam_all = ParameterFilterUtilities.GetFilterableParametersInCommon(doc,cat_ids)
needCalloutid = []
for p in fparam_all:
    pdef = Document.GetElement(doc,p)
    if pdef:
        if pdef.Name == "Com_NeedsCallout":
            needCalloutid = p
        else:
            pass
    else:
        pass

worksetId = []
bip_all = ParameterUtils.GetAllBuiltInParameters()
for p in bip_all:
    testpara = ParameterUtils.GetBuiltInParameter(p)
    if str(testpara) == "ELEM_PARTITION_PARAM":
        worksetId = ElementId(testpara)
    else:
        pass

workset_all = FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset)
worksetValue = []
for w in workset_all:
    if w.Name == discChosen.worksets[0]:
        worksetValue = w
    else:
        pass
print(worksetValue.Id)

rule = (ParameterFilterRuleFactory.CreateEqualsRule(needCalloutid, 1),
        ParameterFilterRuleFactory.CreateEqualsRule(worksetId, worksetValue.Name))
elementFilter = ElementParameterFilter(rule)

t = Transaction(doc, "pyR - filter")
t.Start()
filter = DB.ParameterFilterElement.Create(doc,"zAnno - Elem - Needs Callout", cat_ids, elementFilter)
t.Commit()