Get instance and type value for same parameter in family.

Get instance and type value for same parameter in family.

Anonymous
Not applicable
2,615 Views
8 Replies
Message 1 of 9

Get instance and type value for same parameter in family.

Anonymous
Not applicable

So I am working on a routine that will place values into door families based on width, but I am struggling with extracting the width values from the door. The problem comes back to how i built my families. My curtain panel doors have width parameter as instance because it adjust to the panel location in the wall but the remainder of my doors for standard walls have a type parameter for width. I am struggling to find a way to extract the width parameter (type and instance) to one value no matter which family i select.

public static double Doorwidth;
		public void DoorOccValues()
		{
			UIDocument uidoc=this.ActiveUIDocument;
			Document doc= uidoc.Document;
			
			using(FrmOcc frmocc= new FrmOcc())
			{
				if(frmocc.ShowDialog()==DialogResult.OK)
		      	{
					
					bool sprinkler=frmocc.Radio_Sprinkler;
					bool nonsprinkler=frmocc.Radio_NonSprinkler;
					bool swing90=frmocc.Radio_90swing;
					bool swing180=frmocc.Radio_180swing;					
		
					  try // try/catch block with PickObject is used to give the user a way to get out of the infinite loop of while (true)
				    {
				       // while (true)
				        {
			           
		
			            IList<Reference> refs=uidoc.Selection.PickObjects(ObjectType.Element,new ValidTargetFilter(), "Select a Door. ESC when finished.");
			            //retrieve the parameters of the target Reference
					  		
				            foreach(Reference r in refs)
				            {
				            	
				            	door = doc.GetElement(r);
				            	doort=door.Document.GetElement(door.GetTypeId());
				            	Parameter paramWidth=door.get_Parameter(BuiltInParameter.DOOR_WIDTH);
				            	Parameter paramWidthType=doort.get_Parameter(BuiltInParameter.DOOR_WIDTH);
				           
				            	getWidth(door,out Doorwidth);
				            	
				            	
				            	if((sprinkler=true)&&(swing90=true))
				            	{
				            		//DoorEgress(door,"test");
				            		TaskDialog.Show("tEST","Length instance is"+Doorwidth);
				            	}
				            	else if((nonsprinkler=true)&&(swing90=true))
				            	{
				            		TaskDialog.Show("tEST","Length instance is"+Doorwidth);
				            	}
				            	else if((sprinkler)&&(swing180))
				            	{
				            		TaskDialog.Show("tEST","Sprinkler+180");
				            	}
				            	else if((nonsprinkler)&&(swing180))
				            	{
				            		TaskDialog.Show("tEST","Non-Sprinkler+180");
				            	}

				            }
				        }
			        }
				  	catch(Exception)
				  	{
				  	}
				}
				uidoc.RefreshActiveView();
			}
		}
		public double getWidth(Element elem, out double result)
		{
			Parameter paramWidth=elem.get_Parameter(BuiltInParameter.DOOR_WIDTH);
        	        Parameter paramWidthType=elem.Document.GetElement(elem.GetTypeId()).get_Parameter(BuiltInParameter.DOOR_WIDTH);
        	if(null != paramWidth && !paramWidth.IsReadOnly)
        	{
        		result=paramWidth.AsDouble();
        			
        	}
        	if(null != paramWidthType && !paramWidthType.IsReadOnly)
        	{
        		result=paramWidthType.AsDouble();
        			
        	}
        	return result;
		}
0 Likes
2,616 Views
8 Replies
Replies (8)
Message 2 of 9

RPTHOMAS108
Mentor
Mentor

The built in parameter door width is a type parameter not an instance parameter and so you can't use the same BIP enum value to get from the instance, the parameter doesn't exist there.

 

If you edit your family you can set the formula of the instance parameter 'width' to '=Width'. I'm guessing the only reason it let you create an instance width parameter is because parameter names are case sensitive.

 

If you've created a non-shared instance 'width' parameter then it doesn't have a GUID and so you would only be able to get the parameter by name i.e. Element.LookupParameter. If you've created it as shared parameter then you can get it via it's shared parameter GUID (more reliable).

 

You are using the right approach for getting the built in type parameter 'Width' but you don't have to check it is readonly if you are no going to edit it. 

0 Likes
Message 3 of 9

FAIR59
Advisor
Advisor

I think you need to use the more general BuiltInParameter.FAMILY_WIDTH_PARAM

0 Likes
Message 4 of 9

RPTHOMAS108
Mentor
Mentor

Not sure the name of the enum value is considered speratetly by the API.

 

-1001301 DOOR_WIDTH
-1001301 FAMILY_WIDTH_PARAM

 

e.g. I often find ALL_MODEL_MARK to be interchangable with DOOR_NUMBER (-1001203).

0 Likes
Message 5 of 9

Anonymous
Not applicable
As Far as instance and type parameter in doors the curtain panel template has a built inwidth parameter defined in it as an instance that predefined to the planes and the other door type has it set to type.

I have tried both suggested width parameters and am not able to retrieve the type parameter from the wall based door. I even tried the string Width with no luck
0 Likes
Message 6 of 9

RPTHOMAS108
Mentor
Mentor

No because the built-in parameter (-1001301) is not an instance parameter.

 

In both families create a new instance shared parameter 'CommonWidth'

 

For curtain wall version add formula to 'CommonWidth' =Width (Linking CommonWidth to Instance Parameter)

For standard wall opening family add formula to 'CommonWidth' =Width (Linking CommonWidth to Type Parameter)

 

Then via the API you can use the GUID of CommonWidth to get the width from the instance of either family.

 

 

 -1010301 CURTAIN_WALL_PANELS_WIDTH (Not sure if this is the one you are looking for, best to use the Lookup tool).

0 Likes
Message 7 of 9

FAIR59
Advisor
Advisor

the builtinParameter  (-1001301) can be a type parameter or an instance parameter. Because of this, you will always get a resulting parameter for an instance, even though the parameter is not actually there. So you have to check if the parameter is in the ParameterMap of the instance.

 

	    double getWidth(Element elem)
		{
			Parameter paramWidth=elem.get_Parameter(BuiltInParameter.FAMILY_WIDTH_PARAM);
			if (paramWidth!=null && elem.Parameters.Contains(paramWidth)) return paramWidth.AsDouble();
			if (elem.GetTypeId() == ElementId.InvalidElementId) return 0;
			Element elemtype = elem.Document.GetElement( elem.GetTypeId());
            		Parameter paramWidthType=elemtype.get_Parameter(BuiltInParameter.FAMILY_WIDTH_PARAM);
            		if(null != paramWidthType)	return paramWidthType.AsDouble();
        		return 0;
	    }

 

 

0 Likes
Message 8 of 9

FAIR59
Advisor
Advisor

in my previous post

replace:

if (paramWidth!=null && elem.Parameters.Contains(paramWidth)) return paramWidth.AsDouble();
with

if (paramWidth!=null && elem.ParametersMap.Contains(paramWidth.Definition.Name)) return paramWidth.AsDouble();
              

0 Likes
Message 9 of 9

jeremytammik
Autodesk
Autodesk

One important aspect that has not been pointed out yet is that you can use RevitLookup to explore your own model yourself.

 

That will show you interactively which parameters are present on which elements, and what built-in parameter enum value you can use to access them.



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