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