Get Sheet ID and SHeet name from View

Trying to get Python to give me the #Sheet Number or #SHEET_NUMBER / Name with
VID = view object…

	SNUM=VID.get_Parameter(BuiltInParameter.SHEET_NUMBER)
	#SNAME=VID.get_ParameterValueByName(BuiltInParameter.SHEET_NAME)

But the darn thing won’t fly. I can get the same effect in a #Codeblock

PY here for quick reference:

# Simplified version by Ron.Allen to just text in views - Apsis0215@gmail.com 2019-01-02
# Deduced from from Konrad K Sobon @arch_laboratory, http://archi-lab.net Get function  2015
# Derived from Jeremy Tammick's bip function work in C#

import clr
# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import System

##IN[0] for elements
if isinstance(IN[0], list):
	objList = []
	for i in IN[0]:
		objList.append(UnwrapElement(i))
else:
	objList = IN[0]

elements = []
for i in objList:
	elements.append(UnwrapElement(i))

##Export values of objects - the TEXT_TEXT built in parameter is the VALUE of the instance of text.
OUT=[]

for obj in objList:
	##
	SNUM=""
	SNAME=""
	VID= None
	VName="nil"
	PVAL=""

			
	##View ID and Name
	if hasattr(obj, "OwnerViewId"): 
		#Get object View ID
		VID=obj.Document.GetElement(obj.OwnerViewId)
		#Get Object View Name
		Vname=VID.Name
		
		SNUM=VID.get_Parameter(BuiltInParameter.SHEET_NUMBER)
		#SNAME=objView ##.get_Parameter(BuiltInParameter.SHEET_NAME).AsString()

	##String Valiue of note from BuiltInParameter
	PVAL=obj.get_Parameter(BuiltInParameter.TEXT_TEXT).AsString()
	

	##Append values to list
	OUT.append((SNUM,SNAME,VID,Vname,PVAL))

I tried similar approaches and kept getting the same result. This post on the Autodesk forums was never fully solved so not sure how to fix it.

If you really need it done in Python, the alternative is to import dynamo nodes into python and use the same flow in your codeblock, as shown below:

import clr
# Import Element wrapper extension methods
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

# Import RevitAPI
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import System
clr.AddReference('DSCoreNodes') #Imports Dynamo Nodes into Python
from DSCore import *

if isinstance(IN[0], list):
objList = UnwrapElement(IN[0])
else:
objList = [UnwrapElement(IN[0])]

OUT = []
for obj in objList:
    if hasattr(obj, "OwnerViewId"):
        VID = obj.Document.GetElement(obj.OwnerViewId)
        Vname = VID.Name
        DVID = VID.ToDSType(True)
        SNUM = DVID.GetParameterValueByName("Sheet Number")
        SNAME = DVID.GetParameterValueByName("Sheet Name")
        PVAL = obj.Text

        OUT.append((SNUM, SNAME, VID, Vname, PVAL))

I didn’t add in an else condition so you will have to put it in.

Reasonable approximation with Codeblocks to shore up the gaps…
dyn-extract-notes-v00.90.dyn (16.4 KB)

You also need to add the add reference and import for DSCoreNodes, as that allows you to use Dynamo nodes inside Python (using design script syntax).

Working DYN here:


dyn-extract-notes-v00.96.dyn (9.4 KB)

# Simplified version by Ron.Allen to just text in views - Apsis0215 at gmail.com 2019-01-02
# Deduced from from Konrad K Sobon @arch_laboratory, http://archi-lab.net Get function  2015
# Derived from Jeremy Tammick's bip function work in C#

import clr
# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
clr.AddReference("DSCoreNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import System

##IN[0] for elements
if isinstance(IN[0], list):
	objList = []
	for i in IN[0]:
		objList.append(UnwrapElement(i))
else:
	objList = IN[0]

elements = []
for i in objList:
	elements.append(UnwrapElement(i))

##Export values of objects - the TEXT_TEXT built in parameter is the VALUE of the instance of text.
OUT=[]
#OUT.append(("Sheet Number","Sheet Name","DetailID","View Type","View ID","View Name","Text Note","Object GUID","Revit Select ID"))
OUT.append(("Sheet Number","Sheet Name","DetailID","View Type","View Name","Title on Sheet", "Text Note","GUID","RevitID"))
for obj in objList:
	##
	SNUM=""
	SNAME=""
	SDtlID = ""
	VType = ""
	VID= None
	DVID=None
	VName="nil"
	strTxtVal=""
	strViewTitle=""

	
				
	##View ID and Name
	if hasattr(obj, "OwnerViewId"): 
		#Get object View ID
		VID=obj.Document.GetElement(obj.OwnerViewId)
		#Get Object View Name
		Vname=VID.Name
		DVID = VID.ToDSType(True)
		SNUM = DVID.GetParameterValueByName("Sheet Number")
		SNAME = DVID.GetParameterValueByName("Sheet Name")
		SDtlID = DVID.GetParameterValueByName("Detail Number")
		VType = DVID.GetParameterValueByName("Type").Name
		strViewTitle = DVID.GetParameterValueByName("Title on Sheet")

	##String Valiue of note from BuiltInParameter
	strTxtVal=obj.get_Parameter(BuiltInParameter.TEXT_TEXT).AsString()

	#Get GUID
	objGUID=obj.UniqueId	#Get by ID: #obj = doc.GetElement(objGUID);
	EleID=obj.Id
	##Append values to list
	#OUT.append((SNUM,SNAME,VID,Vname,strTxtVal))
	OUT.append((SNUM, SNAME, SDtlID, VType, Vname, strViewTitle, strTxtVal, objGUID,EleID))

OUT = map(None, *OUT)
1 Like

Update to PY: *Not sure about the PVAL=Obj,name in the end but… for 2.0:

import clr
import Revit                                                            ##Import Revit References                                                         

if isinstance(IN[0], list):                                             ##For dingle-element list 
	objList = UnwrapElement(IN[0])                                      ##Add it to the object list as Revit elements with unwrap
else:
	objList = [UnwrapElement(IN[0])]                                    ##Otherwise convert whole list

OUT = []                                                                ##Defin OUT as a list
for obj in objList:                                                     ##For each element in the list
    if hasattr(obj, "OwnerViewId"):                                     ##IF it has the OwnerViewID attributea
        ViewID = obj.Document.GetElement(obj.OwnerViewId)               ##Get owner's View's ID
        ViewName = ViewID.Name                                          ##Get View's name        
        DViewID = ViewID.ToDSType(True)                                 ##Convert to dynamo script type for easier handling
        SheetNumber = DViewID.GetParameterValueByName("Sheet Number")   ##Get sheet number
        SheetName = DViewID.GetParameterValueByName("Sheet Name")       ##Get sheet name
        if hasattr(obj, "Text"):
            PVAL = obj.Text                                             ##Get name of object - fails in V2_0
        elif hasattr(obj, "Name"):
            PVAL=obj.Name
        else:
            PVAL="n/a"
#Output Position ref.:       00         01      02        03    04
        OUT.append((SheetNumber, SheetName, ViewID, ViewName, PVAL)) ##Append values for each item as a sublist