Add shared parameters failing if parameter already exists

Using DanEDU.FamilyDocument.AddSharedParameter I can successfully add shared parameters and values BUT if the shared parameter already exists it fails.

How to check if a parameter exits first?

In addition to this I want to add a value to the shared parameter without overwriting any existing value - is this possible?

Sending a screenshot of your graph will help to quickly see what can be improved in your workflow…

Graph added to original post above.

Ok, I have solved the first issue, addapting the python script in the “AddSharedParameter” as follows:

	#core data processing
	for item in params:
		try:
			eDef = defFile(spfile, group, item)
			doc.FamilyManager.AddParameter(eDef, paramGroup, instance)
			log = 'Shared parameter added successfully'
		except:
			log = 'error'

It needs a bit of improvement as the above will only ever produce an error if it occurs in the last parameter it is trying to add.

1 Like

The best in this case is probably to reach the author directly like so: @erfajo :slight_smile:

@erfajo I have tried to update to your latest version and hit a few issues. it was failing to open and close the documents so I removed that section and ran it on the open document, it appears to run correctly:

But the parameters listed are not added to the family :frowning:

The result I get trying to run from the file path is:

Almost as though the family get swallowed by the AddSharedParameter script!

Ah, after a lot of testing I believe I have found the issue, if all the parameters are already in the family it exits the script with a null meaning it hangs as the rest of the blocks never run.

Is this an easy thing to correct?

Yes I have the latest version (2017.1129.0).

Just to confirm the node works fine if there is at least one parameter to add but the process hangs if all the parameters you are trying to add already exist.

This is because in this case the output is an error message rather than the original document so the following nodes have nothing to work with and of course the Application.CloseDocument node fails as there is no document to close.

I got round it by commenting out the final if statement:

if error_log:

# docs = error_log

Doing this the node works fine.