Python - extract parameter from sheet - works unreliably

Hi,

I’ve put together some code which looks through all the Sheets in a project and extracts a parameter value - which it uses to create a list. This code is part of a larger routine.

The code extracts any parameter value, but is set to extract the ‘Sheet Number’ parameter (as shown in the string node.

Get sheet parameter 01.dyn (6.0 KB)

In my sample project I have 5 sheets created:

When I run the code it extracts some of the sheet numbers, but strangely not all of them:

You can see the circled one is blank.

If I re-run the code (by toggling the boolean node to ensure it runs) it get a different result:

This time, you can see two of the values are blank.

Each time I run the code I get a different result.

Any idea why this is happening?

Cheers.

Just notice you do not have input to IN[1]?

What’s that Python script?

@4bimfercesp - Yes, I know, its not connected to anything. The code doesn’t use it and I was to lazy to remove it!

@Konrad_K_Sobon, this is the code from the Python node:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

from System.Collections.Generic import *

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
adoc = doc.ActiveView

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

allsheets = UnwrapElement(IN[0])		# List of all sheets in the project

sheetparamext = IN[2]	# Sheet instance parameter name to extract value from 

check = []

#Look through each sheet
for s in allsheets:

	#Add the current sheet name to the output list
	check.append(s)

	#sheettouse = Autodesk.Revit.DB.ElementId(s.Id)
	sheettouse = s.Id
	
	#Get the Sheet parameter
	sheetobject		= doc.GetElement(sheettouse)
	sheetparams = sheetobject.Parameters

	foundsheetvalue = "Not Found!!"
	checkpresent = 0
	for p in sheetparams:
		if p.Definition.Name == sheetparamext:
			foundsheetvalue = p.AsString()
			checkpresent = 1
	
	check.append(checkpresent)
	check.append(foundsheetvalue)

#Assign your output to the OUT variable.
OUT = check

You are using parameter name. It’s a known issue: https://github.com/DynamoDS/DynamoRevit/issues/1234

Since you are not using the OOTB dynamo nodes to get the parameter but instead opted to get them yourself via Python script, i would suggest that you check out how they are handling it now, and make sure you do the same.

As an idea i would say this:

  • if parameter name is that of shared parameter, it’s perfectly fine to get it by name
  • if parameter name is that of system parameter (sheet name), i would use built in parameters to get them instead
  • you can also add extra check. instead of just checking parameter name, check if storage type matches what you expect it to be, or even better check if parameter is readonly.

Again, this is an issue with multiple parameters stored in database under the same name.

Konrad - Thanks for your help. I’ve decided to use the OOTB nodes.

Its good to know that my routine was correct nonetheless.