Get Parameter from Definition

Get Parameter from Definition

sofia_feist
Enthusiast Enthusiast
2,130 Views
2 Replies
Message 1 of 3

Get Parameter from Definition

sofia_feist
Enthusiast
Enthusiast

Hello,

 

I'm creating a Shared Parameter like so:

 

 

 

ExternalDefinitionCreationOptions option = new ExternalDefinitionCreationOptions(paramName, paramType);
option.Description = description;
ExternalDefinition externalDefinition = paramGroup.Definitions.Create(option) as ExternalDefinition;
                
Category category = Category.GetCategory(doc, builtcategory);
CategorySet categorySet = app.Application.Create.NewCategorySet();
categorySet.Insert(category);
InstanceBinding newIB = app.Application.Create.NewInstanceBinding(categorySet);
doc.ParameterBindings.Insert(externalDefinition, newIB, BuiltInParameterGroup.PG_DATA);

 

 

 

My question is: Can I get the Parameter created with that ExternalDefinition? I don't have any Element in my doc with that parameter yet so I can't just do element.LookUpParameter(paramName). Is there another way?

0 Likes
Accepted solutions (1)
2,131 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni
Accepted solution

No, sorry.

 

A Parameter is the value assigned to a parameter definition, attached to a specific element.

 

You cannot create such a value with no element to attach it to.

 

You can create a temporary placeholder element in a temporary transaction, retrieve the parameter definition from that, and roll back the transaction without committing.

 

It is much more reliable to use the language independent parameter definition or the parameter GUID for a shared parameter than the language dependent LookupParameter method. The latter just looks for a matching display name. There may be several identical display names, so I would avoid using that method completely, unless you are extremely lazy and laid back, and don't worry at all about possibly retrieving the wrong parameter.

  

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

sofia_feist
Enthusiast
Enthusiast

Thank you Jeremy for your answer! I'll look into the methods you mentioned.

 

Best wishes,

Sofia

0 Likes