Parameter Service: how to disable re-import of already existing parameters

Parameter Service: how to disable re-import of already existing parameters

lejla.s
Autodesk Autodesk
1,287 Views
11 Replies
Message 1 of 12

Parameter Service: how to disable re-import of already existing parameters

lejla.s
Autodesk
Autodesk

Our plugin automatically creates shared parameters with a pre-defined (fixed) GUID for all categories in the Revit model. The expectation would be that the Revit parameter service recognizes that these elements are already present in the model, which is not the case. 

The parameter allows the re-import of the parameters, which makes them editable. 

Is there any way to prevent this and force the parameter service to recognize parameters with the same GUID as already present in the model and disable to re-import? 

 

 

Lejla Secerbegovic
Product Manager - Data Exchange
Autodesk Data Exchange - Link Collection
0 Likes
1,288 Views
11 Replies
Replies (11)
Message 2 of 12

jeremy_tammik
Alumni
Alumni

Dear Lejla,

  

nice to see you here. Welcome to the Revit API forum. I'll ask around and see what I can discover for you.

  

Cheers

  

Jeremy

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 12

Lorenz_BeyerEWQ5E
Observer
Observer

Thank you Lejla for creating this thread for us and thank you Jeremy for investigating! Great to finally have my own forum post after using this resource quite a lot when developing our plugin. 😉

 

To give you some more background on implementation details: We are using a modified version of the “CreateMyRoomSharedParameter()” method from the RoomSchedule-Project in the SDKSamples Solution provided by Autodesk (I can provide code if this helps). On every DocumentOpened event, we check if our shared parameter file exists. If not, we create it and use it to create a shared parameter and attach it to all instances and all types of all categories which allow bound parameters in the project. Later, the user can select elements in the document via the GUI and assign values to the parameter via our business logic. But – and this is important – the user can ONLY do this via our business logic to make shure that values are validated before assigned. To that end we have set the parameter to UserModifiable = false.

Lejla, to answer the question, you kindly send me by mail:

Kindly clarify for me, Are you using the parameters api that we hosted at https://github.com/autodesk-platform-services/revit-parameters-export-addin/Or you developed your own Addin that creates parameters independently that are then uploaded to the parameters API service using the inbuilt Revit parameters service

The latter. We are using our own plugin, that creates parameters independently as described above, upload parameters and reimport them via the Revit GUI. In the german GUI, to export we use: "Verwalten > Parameterdienst" and export all parameters in the project from there. After that, we close the document, and open another document while our plugin is active. Our parameters are added automatically by the method similar to “CreateMyRoomSharedParameter()” as describe above. After that, we import our parameter from the shared parameter service via the GUI. The procedure is: "Verwalten > Projektparameter > Parameter aus Kategorie" hinzufügen, after that we select our parameter via checkbox and add it to the document. The expected behaviour would be, that the parameter is shown as “Im Modell” (“Already in model”), which would prevent a reimport. Instead, it is shown as “Bereit” (“ready).

0 Likes
Message 4 of 12

jeremy_tammik
Alumni
Alumni

Aha. Welcome to the forum and thank you for the clarification. We have contacted George, the Revit Parameters Import developer. He will probably add functionality to his sample app to handle the use case you describe, and then you can see there how he implements that and copy his technique.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 5 of 12

Lorenz_BeyerEWQ5E
Observer
Observer

Nice, thanks for getting back so quickly. I'm looking forward to his solution.

0 Likes
Message 6 of 12

moturi.magati.george
Autodesk
Autodesk

Hi @Lorenz_BeyerEWQ5E,

I had a look at the sample you were talking about. You indicated that you want to avoid duplication of parameters added to the document if they are already existing from the parameters service?

You can use the new DownloadParameter method as described https://www.revitapidocs.com/2024/6449c1fe-90af-e6d4-e852-91f6eeae5c97.htm which uses the ForgeTypeI...

This will check if the parameter exists on the document before attempting to create another one.

Have a look at the implementation we made and try to upgrade your sample
https://github.com/autodesk-platform-services/revit-parameters-export-addin/blob/main/Services/AddSh...

  Moturi George,     Developer Advocacy and Support,  ADN Open
0 Likes
Message 7 of 12

Lorenz_BeyerEWQ5E
Observer
Observer

Thanks George, I'm having licensing issues at the moment but will check the provided solution as soon as possible.

0 Likes
Message 8 of 12

plugInJ5L7A
Community Visitor
Community Visitor

Hi Georg, it's Lorenz again. Back to your post. You were asking: "You indicated that you want to avoid duplication of parameters added to the document if they are already existing from the parameters service?"

 

That is almost, what I meant. I am adding a parameter via sourcecode using a shared parameters file. I want to avoid overwriting my original parameter, if I try to add the same parameter again from shared parameter service via the Revit GUI.

 

I was able to resolve my licencing issues and looked at the samples you provided. Thanks again for your help.

 

- The DownloadParameter Method is probably not needed in my project, because we do not intend to download parameters from the shared parameter service programmatically. We just want to make shure that our business logic is not perturbed if the user downloads a parameter from the shared parameter service via the Revit GUI as described above.

- The implementations you provided in AddSharedParameter.cs are pretty similar to our codebase. Unfortunately, I was not able to resolve the issue. Please check the attached source code to verify, that I didn't overlook anything.

 

void IRevitSharedParameterManager.CreateSharedParametersInFileIfDontExist<T>(UIApplication app,
	IReadOnlyCollection<SharedParameterCreationOptions> parametersstring fileName,
	string groupName)
{
	var document = app.ActiveUIDocument.Document;
 
	try
	{
 
		// check whether all shared parameters exist
		if (parameters.All(param => DoesSharedParameterExist<T>(param.Name, document)))
		{
			return;
		}
 
		// create shared parameter file
		String modulePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		String paramFile = modulePath + fileName;
		if (File.Exists(paramFile))
		{
			File.Delete(paramFile);
		}
 
		FileStream fs = File.Create(paramFile);
		fs.Close();
 
		// cache application handle
		var revitApp = app.Application;
 
		// prepare shared parameter file
		revitApp.SharedParametersFilename = paramFile;
 
		// open shared parameter file
		DefinitionFile parafile = revitApp.OpenSharedParameterFile();
		
		// create a group
		DefinitionGroup apiGroup = parafile.Groups.Create(groupName);
 
		// get all categories which can be bound to
		CategorySet categories = revitApp.Create.NewCategorySet();
		var categoriesEnumerator = app.ActiveUIDocument.Document.Settings.Categories.GetEnumerator();
 
		while (categoriesEnumerator.MoveNext())
		{
			if (categoriesEnumerator.Current is Category category && category.AllowsBoundParameters)
			{
				categories.Insert(category);
			}
		}
 
		foreach (var param in parameters)
		{
			// create a parameter of url type.
			ExternalDefinitionCreationOptions options =
				new ExternalDefinitionCreationOptions(param.Name, param.Type);
			options.UserModifiable = param.UserModifiable;
			options.Visible = param.Visible;
			Definition paramDef = apiGroup.Definitions.Create(options);
 
 
			if (typeof(T) == typeof(InstanceBinding))
			{
				var instanceBinding = revitApp.Create.NewInstanceBinding(categories);
				app.ActiveUIDocument.Document.ParameterBindings.Insert(paramDef, instanceBinding,
					GroupTypeId.IdentityData);
			} else if (typeof(T) == typeof(TypeBinding))
			{
				var typeBinding = revitApp.Create.NewTypeBinding(categories);
				app.ActiveUIDocument.Document.ParameterBindings.Insert(paramDef, typeBinding,
					GroupTypeId.IdentityData);
			}
		}
	}
	catch (Exception ex)
	{
		mLogger.Error("Failed to create shared parameters: " + ex.Message);
		throw new Exception("Failed to create shared parameters: " + ex.Message);
	}
}

 

0 Likes
Message 9 of 12

moturi.magati.george
Autodesk
Autodesk

Hi @Lorenz_BeyerEWQ5E,

On checking whether a shared parameter exists before adding, can you try something like below

private bool ShareParameterExists(String paramName)
{
    FilteredElementCollector collector = new FilteredElementCollector(m_document)
        .WhereElementIsNotElementType()
        .OfClass(typeof(SharedParameterElement));
    //List<Element> sharedParameters = collector.ToList();
    //sharedParams.Any(item => item.Name.Equals(paramName));
    foreach (Element e in collector)
    {
        SharedParameterElement param = e as SharedParameterElement;
        Definition def = param.GetDefinition();
        //Console.WriteLine("[" + e.Id + "]\t" + def.Name + "\t(" + param.GuidValue + ")");
        if (def.Name.Equals(paramName))
        {
            return true;
        }
    }
    return false;
}

 

 

You can check by def.Name or GuidValue

  Moturi George,     Developer Advocacy and Support,  ADN Open
0 Likes
Message 10 of 12

plugInJ5L7A
Community Visitor
Community Visitor

Thanks for your suggestion George. But that would mean I need to find some kind of lifecycle hook that is triggered when the user imports a shared parameter via the Revit GUI. Inside the hook I would need to cancel the default import behavior and reimplement it in the way you propose.

 

But our plugin actually does not use shared parameter service. The problem is caused by the default behavior of Revit when importing a parameter from the service. Because of this I was hoping, there would be another solution.

 

Here are some steps to reproduce my problem:

1. Download https://apps.autodesk.com/RVT/en/Detail/Index?id=8706727659248635120&appLang=de&os=Win64

2. Open a new document. The code I sent you is executed.

3. Add an element to the document, e.g. a wall. You can verify that the parameter has been created by the code by selecting the element and finding "AUSSCHREIBEN.DE" in the parameter window in the group "ID-Daten" (probably "Id Data" in english).

4. Click on "Verwalten" (probably "Manage" in english)

5. Click on "Parameterdienst" (probably "Parameterservice" in english)

6. Click on the upload icon. Tooltip: "In Parameterdienst hochladen" (probably "Upload to parameter service" in english)

7. Select "Aktives Modell" (probably "active model") in radio button list, click on "Parameter hochladen" ("upload parameters"). All parameters from the current document are uploaded.

8. Close the document.

9. Open a new document. The code I sent you is executed again.

10. Add an element to the document, e.g. a wall. You can verify that the parameter has been created by the code by selecting the element and finding "AUSSCHREIBEN.DE" in the parameter window in the group "ID-Daten" (probably "Id Data" in english).

11. Click on "Verwalten" (probably "Manage" in english)

12. Click on "Projektparameter" (probably "Projectparameters" in english)

13. Click on the icon with the document and the cloud with Tooltip "Parameter aus Kategorie hinzufügen" (probably "Add parameter from category" in english)

14. In the list of parameters, "AUSSCHREIBEN.DE" is shown as "bereit" ("ready") and can be reimported into the project. If you reimport the parameter, it becomes user editable. We do not want that. Instead we expected the parameter to be shown as "Im Modell" ("in model") and to not be importable.

(Short sidenote: don't worry if you see the AUSSCHREIBEN.DE parameter twice in the shared paremter service window. This is intentional. One is an instance parameter, the other is a type parameter. Both have different guids.)

 

If you need more information to better understand my problem, I will be glad to provide more information.

 

0 Likes
Message 11 of 12

moturi.magati.george
Autodesk
Autodesk

Hi @Lorenz_BeyerEWQ5E,

I raised your issue and it was taken up by the engineering team under ticket RVTUP-1905.

I will keep you posted on any updates pertaining to the same.

  Moturi George,     Developer Advocacy and Support,  ADN Open
0 Likes
Message 12 of 12

Lorenz_BeyerEWQ5E
Observer
Observer

@moturi.magati.george Thanks, that's great news.

0 Likes