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:

thanks @Yna_Db for the link :slight_smile:

Hi @KM_Springfield,
You are certainly right, that I should include a test for existing parameters. However, as you might have seen, have I been updating the code and my coding environment seriously (check the new DanEDU Dynamo package) and totally rebuild the way I work with nodes. That work has taken some time. Besides, I have also refactored all my code to support the PEP8 guidelines for Python code.
http://www.python.org/dev/peps/pep-0008/
http://pep8online.com

On my todo list as the next is nodes for FEM-design and Robot. As soon as this is released will I look into the performance of my existing nodes.

edition:
It was rather easy to implement your request in my new environment, so nodes are hereby updated :slight_smile:

2 Likes

@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?

what version did you install? the latest version is 2017.1129.0 (from yesterday), please install that version. there was a bug in 2017.1127.0 I hopefully has solved yesterday.
the issue is concerning where packages are installed, so if you could give me that address also, then I could try to see if the problem you have, also is like the other problem from yesterday (with another node).

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.

Thanks, this is really valuable information :slight_smile:
I did not think about the situation that all parameters exist in advance, but you are right, as a user you could end in that situation if you open a directory with families.
Thanks a lot for this feedback :slight_smile:

I will work on a solution asap.