Get Surface Pattern Dimensions / Count Tiles

Hi guys I wanted to share with you a workflow which helped me a lot.
It is about how to get face surface pattern from Revit. There is no direct way you can access the surface pattern of a face but with this Python code you will be able to get the dimensions of a surface pattern.

You need to run the script, select а face and hit finish.
It basically creates dimension between two vertical lines from the pattern and two horizintal lines from the pattern and reports the dimensions. I also added the selected surface to the output and the temporary dimensions origin, because I need them for my workflow.
You could check my workflow here -

I used the surface pattern to count ceiling tiles.

Here is the code:

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

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

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

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

clr.AddReference('RevitAPI')
import Autodesk



from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import *
from Autodesk.Revit.DB.Analysis import *
from Autodesk.Revit.Creation import *

from Autodesk.Revit.UI import TaskDialog
from Autodesk.Revit.UI import UIApplication
from Autodesk.Revit.UI.Selection import ObjectType

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application



faces=[]
faces.append(uidoc.Selection.PickObjects(ObjectType.Face,'Select Faces'))
for f in faces:
	for r in f:
		e = uidoc.Document.GetElement(r)
		face = e.GetGeometryObjectFromReference(r)
		mattid= e.GetGeometryObjectFromReference(r).MaterialElementId
		matt=doc.GetElement(mattid)
		gridCount=doc.GetElement(matt.SurfaceForegroundPatternId).GetFillPattern().GridCount
		StableRef=r.ConvertToStableRepresentation(doc)

_resArVER=[]
_resArHOR=[]

ip=0
while ip<2:
	indexVER=1+(ip*gridCount*2)
	indexHOR=2+(ip*gridCount*2)
	StableHatchStringVER=StableRef+'/'+str(indexVER)
	StableHatchStringHOR=StableRef+'/'+str(indexHOR)
	HatchRefVER=Reference.ParseFromStableRepresentation(doc,StableHatchStringVER)
	HatchRefHOR=Reference.ParseFromStableRepresentation(doc,StableHatchStringHOR)
	_resArVER.append(HatchRefVER)
	_resArHOR.append(HatchRefHOR)
	ip += 1
	
refArrVER=ReferenceArray()
refArrHOR=ReferenceArray()
for r in _resArVER:
	refArrVER.Append(r)
for r in _resArHOR:
	refArrHOR.Append(r)

GridDims=[]	
t=Transaction(doc)

t.Start('dim')
spoint=XYZ(0,0,0)
epoint=XYZ(1,0,0)
dimVER = doc.Create.NewDimension(doc.ActiveView,Line.CreateBound(spoint,epoint),refArrVER)
dimHOR = doc.Create.NewDimension(doc.ActiveView,Line.CreateBound(spoint,epoint),refArrHOR)
ElementTransformUtils.MoveElement(doc,dimVER.Id,XYZ(1,0,0))
ElementTransformUtils.MoveElement(doc,dimHOR.Id,XYZ(1,0,0))

GridDims=int(dimVER.ValueString),int(dimHOR.ValueString)
refPoints=dimVER.Origin.ToPoint(),dimHOR.Origin.ToPoint()
t.Commit()

t.Start('del')
doc.Delete(dimVER.Id)
doc.Delete(dimHOR.Id)
t.Commit()

OUT=refPoints,GridDims,face.ToProtoType()

_GetSurfacePatternDims.dyn (6.1 KB)

Special thanks to The Building Coder Blog - https://thebuildingcoder.typepad.com/blog/2017/06/hatch-line-dimensioning-voodoo.html#4

19 Likes

Sounds good! Thanks for sharing. Unfortunately the code was messed up when pasting and the quotes and indentations were ruined. Any chance you could fix it?

Oh, yes. Sorry about that I am not very familiar with the forum formatting. Until I find out how to fix it you can download the *dyn file.

*Edit - It should be ok now. Thanks for the remark.

1 Like

Error belowerror

Any idea?

If you are useing pre Revit 2019 version there are no foreground/background patterns and that could cause the problem

Thanks Peter, would you mind to share the full script of counting the tiles?

Cheers!

_CompletePartialPanels-Gen3.dyn (150.8 KB)

4 Likes

Thank you so much, will study it!

1 Like

Hello Peter, I get these errors when I try to run the script. Is there any way you can lend a hand? Thanks!Capture

This is caused by the Dynamo version. May be the node is not currently supported. I don’t know what is the current state. Data.Remember is node used for Refinery implementation. If you don’t want to use the script with Refinery just skip the nodeimage
and connect both ends directly to the code block node. If you want to use it with Refinery you should check Refinery site for more info about Data.Remember node

Hey petar! I skipped the Data.Remember node but ran in to some problems.

Appreciate you taking a look, thanks :slight_smile:

Hi Peter
will this work in Revit 2018.3 i tried it getting same error

can you please guide me

No, the script is working only with Revit versions which support double fill patterns (foreground and background)

1 Like

Hey!

Same problem here, have you solved it yet?

Hey Petar,

Cool script. However when I download and attempt to open it I get an error that says the file is corrupt.

Also when I run the script I get this error:image

Would it be possible for you help with this. I have a great interest in your approach for a very similar application.

Regards

Hi,

I guess is something related to your Dynamo setup. Look here - Data at the root Level is Invalid

It looks like that the error is not caused by the script I shared.
Good luck!

Hi,

Sorry for the late reply but late is better than never = )
The problem was with the list lacings and behavior - I guess it changed trough the Dynamo versions.
The graph is not optimal but it is working.
_CompletePartialPanels-Gen4.dyn (148.6 KB)

2 Likes

I posted updated graph. It should work now.

thx!

Hey Petar,

I was able to run the graph using revit 2019.

Now I have a question regarding the grid alignment.

The dynamo output bases the grid starting point at one corner of the floor it seems.

How can we modify the graph to start the grid using the location from the actual pattern lines?
This way we can manipulate the layout by way of the floor grid pattern then get the count from that.

Is it possible?

image