Roof Slope script

in Revit2016 with python 1.3, the code
ftprintRoof.set_DefinesSlope( line , true )
returns an error

File "<string>", line 45, in <module>
AttributeError: 'ModelNurbSpline' object has no attribute 'ftprintRoof'

and the expresion:

ftprintRoof.set_SlopeAngle( line , 0.2 )

returns this error

File "<string>", line 47, in <module>
Exception: Property 'SlopeAngle' is disabled.

in DLL it suggest this syntax:

public double SlopeAngle(Autodesk.Revit.DB.ModelCurve pCurve) { get; set; }

this is because of the version difference, although, I’ve checked the both RevitAPI.chm of 2016 and 2019 and the syntax is same.
Any idea how it should look like in 2016 ?

@kennyb6 Looking at it a bit more, because we just want to get a single edge,I think it can be simplified to this…

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

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

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

#The inputs to this node will be stored as a list in the IN variables.
lines = IN[0].ToRevitType()
level = UnwrapElement(IN[1])
type = UnwrapElement(IN[2])
curveNo = IN[3]

doc = DocumentManager.Instance.CurrentDBDocument

footprint = CurveArray()
for o in lines:
footprint.Append(o)
TransactionManager.Instance.EnsureInTransaction(doc)

roofCurves = StrongBox[ModelCurveArray](ModelCurveArray() )

type = UnwrapElement(IN[2])
footprintRoof = doc.Create.NewFootPrintRoof(footprint, level, type, roofCurves)

int = roofCurves.Item[curveNo]
footprintRoof.set_DefinesSlope( int, True )
footprintRoof.set_SlopeAngle( int, 0.2 )

TransactionManager.Instance.TransactionTaskDone()
#The value is a &quot;slope&quot; measurement. For example, 0.5 is one unit of rise for each 2 units of run.
#This creates a slope of 26.57 degrees (the arctangent of 0.5).
OUT = footprintRoof.ToDSType(False), roofCurves.Value, int,

@TeoBlack Unfortunately I don’t have 2016 any more so I can’t help, sorry :frowning:

1 Like

I guess it is a matter of curve type and ability of revit to read them as model line.
this is a snap how the curves look like in roof edit footprint mode.


pay attention the Define Slope check box is inactive

That’s very interesting, I’ve never made roofs from Splines, does it work with a Line?

also doesn’t work
Line Based Roof with slope.dyn (19.2 KB)

Hmm… so now we’re dealing with a list of curves, rather than a single polygon…

The downside to python, is that this means we need to edit the code to a deal with a list… There’s also the possibility that the curves are not being read in the correct order.

Try this…

Line Based Roof with slope-LinesList-MKA.dyn (20 KB)

image

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

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

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

#The inputs to this node will be stored as a list in the IN variables.
lines =IN[0]

level = UnwrapElement(IN[1])
type = UnwrapElement(IN[2])
curveNo = IN[3]

doc = DocumentManager.Instance.CurrentDBDocument

footprint = CurveArray()
for o in lines:
    footprint.Append(o.ToRevitType())
TransactionManager.Instance.EnsureInTransaction(doc)

roofCurves = StrongBox[ModelCurveArray](ModelCurveArray() )

type = UnwrapElement(IN[2])
footprintRoof = doc.Create.NewFootPrintRoof(footprint, level, type, roofCurves)

int = roofCurves.Item[curveNo]
footprintRoof.set_DefinesSlope( int, True )
footprintRoof.set_SlopeAngle( int, 0.2 )

TransactionManager.Instance.TransactionTaskDone()
#The value is a &amp;quot;slope&amp;quot; measurement. For example, 0.5 is one unit of rise for each 2 units of run.
#This creates a slope of 26.57 degrees (the arctangent of 0.5).
OUT = footprintRoof.ToDSType(False), roofCurves.Value, int,
1 Like

I had a thought about the Spline problem, if you’re lucky and the opposite edge is a Line, you can set that to a negative slope…

1 Like

Mark, you are Legend, you did it, I am sooo happy, Thank you a lot!!!

1 Like

No worries, thanks mainly to @Jonathan.Olesen & @kennyb6 :slight_smile: I’ll perhaps upload it to @solamour’s github repro for python after a bit of tidying…

2 Likes

Please do Mark! The more contributions the better :slight_smile: Please have a look at the Contributing article too!