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: 

Deleting a non-shared project parameter

5 REPLIES 5
Reply
Message 1 of 6
alvindragon
2659 Views, 5 Replies

Deleting a non-shared project parameter

Hi all, Not sure if this has been answered before but I couldnt find any answer to my problem. I am trying to develop a plugin to delete parameters (shared and project) from my Revit project. Shared parameters can be deleted with no problem however I have problems when I am trying to delete a project parameter. I used the following line in order to delete the parameter: Doc.ParameterBindings.Remove(definition); Two problems I am facing here are: 1) I used a loop to delete every single parameter in the project (Shared + Project). After the loop, all the Shared parameters are gone but the project parameter still remains in Snoop Document -> Parameter Bindings. 2) I tried executing the code again to delete the project parameter and this time the project parameter is no longer in the Parameter Bindings.However, in the UI in Revit (Manage -> Project Parameters), the project parameters are still there and in the properties tab, the parameters are still there as well. Anyone here have faced/solved this problem before? Your help is greatly appreciated.
5 REPLIES 5
Message 2 of 6
R.van.den.Bor
in reply to: alvindragon

Hmm, hard to say. Did you use transactions correctly ? 

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 3 of 6
marcosmateo
in reply to: alvindragon

Hi Alvindragon

My app delete share parameters from a class (Helper) containing shared parameters list for delete, this is my code, i hope help you

 

 

private void EliminarParametros(Document doc, Autodesk.Revit.ApplicationServices.Application app)

{

     foreach (KeyValuePair<string, string> elementos in Helper.Properties)

          {

            RawEraseSharedParameterBinding(app, doc, elementos.Key, ParameterType.Text);

          }

}

 

 

 

 

public static bool RawEraseSharedParameterBinding(Autodesk.Revit.ApplicationServices.Application app, Document doc, string name, ParameterType type)

{

  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, "Update Revit Type");

                transaction.Start();

                map.Remove(def);

                transaction.Commit();

          }

    }

 

  catch (Exception ex)

    {

     MessageBox.Show(ex.Message);

    }

  return false;

}

 

 

 

 

public class Helper

{

  public static string Prefix = "eBIM"; 

  public static UIDocument ActiveUIDocument;

  public static UIApplication Aplication;

 

  public static Dictionary<string, string> Properties = new Dictionary<string, string>()

    {

     { "Param1"," Generales"},

     { "Param2"," Generales"},

     { "Param3"," Texto"},

     { "Param4"," Texto"}

     };

}

 

 

In your button or event, etc, call the method

 

Autodesk.Revit.ApplicationServices.Application app = (Autodesk.Revit.ApplicationServices.Application)sender;

Document doc = e.Document;

EliminarParametros (doc,app);

 

 

 

Good luck!

 

 

Message 4 of 6

Did you ever resolve this?  I'm also having a problem deleting a project (non-shared) parameter.  Is it not possible?

Message 5 of 6
FAIR59
in reply to: michael_coffey

You need to find the associated ParameterElement. If you delete that element, the projectparameter will also be removed.

string parametername = "testparameter";
IEnumerable<ParameterElement> _params = new FilteredElementCollector(doc)
		.WhereElementIsNotElementType()
		.OfClass(typeof(ParameterElement))
		.Cast<ParameterElement>();
ParameterElement projectparameter = null;
foreach(ParameterElement pElem in _params)
	{
		if (pElem.GetDefinition().Name.Equals(parametername))
		{
			projectparameter = pElem;
			break;
		}
	}
if (projectparameter==null) return;
using (Transaction t = new Transaction(doc,"remove projectparameter"))
	{
		t.Start();
		doc.Delete(projectparameter.Id);
		t.Commit();
	}
Message 6 of 6
michael_coffey
in reply to: FAIR59

That works! Thanks!

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