Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding a visible but read-only instance parameter to a category

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
snertillari
5084 Views, 12 Replies

Adding a visible but read-only instance parameter to a category

I am writing a Revit Add-In that adds a shared instance parameter to the built in category OST_Doors.

 

I want the parameter to be visible in the Properties panel when I select a door but I do not want the user to be able to change the value of the parameter in the Properties panel.  I can see there are some read-only type parameters for door types.

 

Is there any whay to create a read-only instance parameter for a door?  I still want to be able to modify the value of the parameter through code.

12 REPLIES 12
Message 2 of 13
Revitalizer
in reply to: snertillari

Hi,

 

parameters are readonly or not, this depends not on the person who accesses them (GUI or API).

 

But there might be a workaround:

 

Define two parameters instead of one.

The first one is visible, the other one not.

Using API, you can fill the invisible one with your values.

These values are to be copied to the visible parameter, whose values are overwritten hereby.

This overwriting process may be invoked either manually or via an IUpdater.

 

Your user will see the copied values.

He may edit them, but he cannot overwrite the original parameter's values since this parameter is invisible for him.

 

Additionally, his modifications to the copied values will be overwritten soon.

 

Hope that helps.

 

 

Cheers,

Revitalizer

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 3 of 13
jeremytammik
in reply to: Revitalizer

Hey Revitalizer,

 

Thank you for that very cool tip!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 13

How are you reading the instance type parameter?  I'm able to set the parameter via the API, but I can't see the value later through the API.  I can see that the parameter exists, but I can only see the value if the user clicks on the object directly.  Is there no way to parse through all the objects of that type in the document and report the values of the instance parameters without requiring the user to click?

 

Regards,

Glen

Message 5 of 13

Here is an example of how I get a parameters value.
famInstance is the FamilyInstance object.
"parameterName" is the name of the parameter.

Parameter param = famInstance.ParametersMap.get_Item("parameterName");
String parameterValue = param.AsString();

Message 6 of 13
snertillari
in reply to: snertillari

In the Revit API version for Revit 2015 it is now possible to define a shared parameter that is visible but read only for the user but can be modified through the API.  This can be done with the UserModifiable member of the ExternalDefinitonCreationOptions class.
ExternalDefinitonCreationOptions options = new ExternalDefinitonCreationOptions("myparameter", ParameterType.Text);
options.Visible = true;
options.UserModifiable = false;

This has solved my problem.

Message 7 of 13
Ning_Zhou
in reply to: snertillari

what if shared parameter already being used in Revit which is visible and writable, how to make it read-only or locked?

Message 8 of 13
jeremytammik
in reply to: Ning_Zhou

I do not think the API enables you to change it after it has been created.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 9 of 13
Ning_Zhou
in reply to: jeremytammik

too bad, thanks Jeremy for your confirmation!

Message 10 of 13

 So good bro

Message 11 of 13
adcdao
in reply to: snertillari

Hi,

Here's my code to create a project parameter:

 

 public static bool CreateProjectParameter(string parameterName,string sharedParemeterFileName, 
BuiltInParameterGroup parameterGroup, List<BuiltInCategory> bics, Document doc)
        {
            bool retValue = true;
            Application app = doc.Application;

            string oriFile = app.SharedParametersFilename;
            string tempFile = sharedParemeterFileName;
            app.SharedParametersFilename = tempFile;
            DefinitionFile defFile = app.OpenSharedParameterFile();
            var v = (from DefinitionGroup dg in defFile.Groups
                     from ExternalDefinition d in dg.Definitions
                     where d.Name == parameterName
                     select d);
            if (v == null || v.Count() < 1) throw new Exception("Invalid Name Input!");

            ExternalDefinition def = v.First();

            CategorySet cats = app.Create.NewCategorySet();
            foreach (BuiltInCategory bic in bics)
            {
                cats.Insert(doc.Settings.Categories.get_Item(bic));
            }

            Autodesk.Revit.DB.Binding binding = app.Create.NewInstanceBinding(cats);

            BindingMap map = (new UIApplication(app)).ActiveUIDocument.Document.ParameterBindings;
            map.Insert(def, binding, parameterGroup);

            app.SharedParametersFilename = oriFile;

            return retValue;
        }

 

Now I would like to add an option for a read only parameter using ExternalDefinitionCreationOptions but I don't know how to implement it in my code.

 

Any help?

Thanks 

Message 12 of 13
Sean_Page
in reply to: jeremytammik

You can do this, but there are a couple steps.

 

1. Remove Parameter from project (Internal and External Definition of SP)

private void DeleteParameters(Document doc)
		{
			List<string> names = new List<string>()
			{
				"Param Name 1",
				"Param Name 2",
				"Param Name 3"
			};

			using(Transaction t = new Transaction(doc))
			{
				t.Start("Delete Parameters");
				using(FilteredElementCollector fec = new FilteredElementCollector(doc).OfClass(typeof(ParameterElement)))
				{
					foreach(ParameterElement param in fec.ToElements())
					{
						try
						{
							if(names.Contains(param.Name))
							{
								doc.Delete(param.Id);
							}
						}
						catch(Exception ex)
						{
							MessageBox.Show(ex.ToString(), param.Name);
							continue;
						}
					}
				}
				t.Commit();
			}
		}

 

2. Modify Shared Parameter file to indicate Visible (0 or 1), User Modifiable (0 or 1)

# This is a Revit shared parameter file.
# Do not edit manually.
*META	VERSION	MINVERSION
META	2	1
*GROUP	ID	NAME
GROUP	1	Project Information
*PARAM	GUID	NAME	DATATYPE	DATACATEGORY	GROUP	VISIBLE	DESCRIPTION	USERMODIFIABLE	HIDEWHENNOVALUE
PARAM	92eb4500-29a8-4e46-b1ef-13852bd93911	Param Name 1	TEXT		1	1	Describe the Parameter	0	0

 

3. Add Parameter back to Project

Message 13 of 13
adcdao
in reply to: Sean_Page

Thank you,

 

Working very well and easy.

 

Thank you very much,

André

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community