Hello, is there any way to remove shared parameter definition from shared parameter file?
This code remove parameter only from project parameters (binding) but in shared parameters still is.
Guid myGuid = new Guid("10000000-ffff-0000-ffff-000000000008"); // GUID of shared parameter
SharedParameterElement sParamElement = SharedParameterElement.Lookup(doc, myGuid);
doc.Delete(sParamElement.Id);
// or
public static bool RawEraseSharedParameterBinding(Autodesk.Revit.ApplicationServices.Application app, Document doc, string name)
{
try
{
BindingMap map = (new UIApplication(app)).ActiveUIDocument.Document.ParameterBindings;
DefinitionBindingMapIterator it = map.ForwardIterator();
it.Reset();
Definition def = null;
while (it.MoveNext())
{
if (it.Key != null && it.Key.Name.Equals(name))// && type.Equals(it.Key.ParameterType))
{
def = it.Key;
break;
}
}
if (def != null)
{
Transaction transaction = new Transaction(doc, "remove");
transaction.Start();
map.Remove(def);
transaction.Commit();
}
}
catch (Exception ex)
{
Main.logger.logException(ex, NLog.LogLevel.Warn);
}
return false;
}
Not that I can see but probably easier to iterate the lines using a stream reader and write to file with stream writer omitting the lines containing the GUID to be removed.
They are all one line definitions so that is how I would have thought to do it in the first place to be honest.
Groups are a bit more complicated to remove because you would have to first check which parameters used a group you wanted to remove via id then decide what to do with those before removing and possibly needing to renumber ids (depending on Revits tolerance for gaps in group id numbering).
Can't find what you're looking for? Ask the community or share your knowledge.