Shared Parameter : Set default value

Shared Parameter : Set default value

nicolas.calvi
Participant Participant
798 Views
2 Replies
Message 1 of 3

Shared Parameter : Set default value

nicolas.calvi
Participant
Participant

Hi,

 

I have created un shared parameter on a type with API, but I don't found how set the parameter with a default value.

This is my code :

 

 

using (Transaction transaction = new Transaction(doc, "Some operations"))
{
	transaction.Start();

	ElementType duplicate = type.Duplicate("Test - " + type.Name);

	// Récupération des paramètres partagées

	GlobalApp.Instance.CreateSharedFile();
	this._application.Application.SharedParametersFilename = GlobalApp.Instance.CurrentDocumentRoot + "-PIMSharedParameters.txt";

	DefinitionFile file = this._application.Application.OpenSharedParameterFile();

	if (file == null)
		return;

	DefinitionGroup group = file.Groups.get_Item("MyGroup");

	if (group == null)
		group = file.Groups.Create("MyGroup");

	Definition def;

	if (group.Definitions.Contains(group.Definitions.get_Item("My Param")))
		def = group.Definitions.get_Item("My Param");
	else
	{
		ExternalDefinitionCreationOptions options = new ExternalDefinitionCreationOptions("My Param", ParameterType.Text);
		options.Visible = true;
		options.HideWhenNoValue = false;
		options.UserModifiable = true;

		def = group.Definitions.Create(options);
	}

	BuiltInCategory builtInCategory = (BuiltInCategory)Enum.ToObject(typeof(BuiltInCategory), duplicate.Category.Id.IntegerValue);

	CategorySet cats = this._application.Application.Create.NewCategorySet();
	cats.Insert(doc.Settings.Categories.get_Item(builtInCategory));

	TypeBinding bind = this._application.Application.Create.NewTypeBinding(cats);


	bool result = doc.ParameterBindings.Insert(def, bind, BuiltInParameterGroup.PG_DATA);

	// Default value
	// ???

	transaction.Commit();
}

 

 

Can someone help me ?

 

Thnaks.

0 Likes
799 Views
2 Replies
Replies (2)
Message 2 of 3

lukaskohout
Advocate
Advocate

Since you cannot do this in UI manually you cannot do this with API.

 

You have to get all the elements with that parameter assigned and set the value directly to them. 


Hitting Accepted Answer is a Community Contribution from me as well as from you.
======================================================================
0 Likes
Message 3 of 3

Revitalizer
Advisor
Advisor

Hi,

 

which means that he needs to implement an IUpdater to intercept newly created elements, setting the default value.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes