project Curves to a view

project Curves to a view

Leo_CourvalKVP86
Participant Participant
206 Views
4 Replies
Message 1 of 5

project Curves to a view

Leo_CourvalKVP86
Participant
Participant

Hi,
I'am trying to project curves retrieves from the edges of a roof to the plan view above the roof. To do So I would like to use the ConvertModelToDetailCurves, however I havn't found any code snippet using that method in python.

Here is my code :

"""MAIN PROCESS"""
debug = []

roofs_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Roofs).WhereElementIsNotElementType()

views = FilteredElementCollector(doc).OfClass(View).WhereElementIsNotElementType()

for roof in roofs_collector:
    geometry_elements = roof.get_Geometry(Options())
    source_level = roof.LevelId
    next_level = get_level_above(source_level)
    next_level_view = get_view_from_level(doc,next_level)
    debug.append(next_level_view)

    for geometry_element in geometry_elements:
        for face in geometry_element.Faces:
            face_normal = face.ComputeNormal(UV(0.50.5))
        
            if face_normal.Z > 0.5:
                edgeLoops = face.GetEdgesAsCurveLoops()
            
                for curveLoop in edgeLoops:
                    curve_array = CurveArray()
                    for curve in curveLoop:
                        curve_array.Append(curve)
                
                doc.ConvertModelToDetailCurves(next_level_view, curve_array)

However the last line is certainly wrong since I got the error message : Avertissement:TypeError : No method matches given arguments for ConvertModelToDetailCurves: (<class 'Autodesk.Revit.DB.ViewPlan'>, <class 'Autodesk.Revit.DB.CurveArray'>) [' File "<string>", line 95, in <module>\n']


Does someone has any idea on how to call the ConvertModelToDetailCurves method in python ?

0 Likes
207 Views
4 Replies
Replies (4)
Message 2 of 5

ctm_mka
Collaborator
Collaborator

A few things to check. First, try converting using source_level o verify its working at all, im not seeing anything in your code that is translating the lines to the next_level. Do you you use Revit Lookup. If not, i highly recommend. I mention this as your code appears correct for a Floor element, but does a Roof behave the same/have the same properties? I work in structures, where we don't use Roofs, so i cannot confirm this. Next, have you verified your curve_array is being populated correctly? Lastly, have you considered getting the Sketch lines vs the face/edge curves? They maybe easier to get at. .

0 Likes
Message 3 of 5

Leo_CourvalKVP86
Participant
Participant

Hi, thanks for your response.

I’ve installed RevitLookup, but as a beginner with the Revit API, the tool isn’t very intuitive for me yet.

 

After rereading the warning I received, I think the error is due to passing a CurveArray to the ConvertModelToDetailCurves method, which actually expects a ModelCurveArray. So I tried converting my CurveArray accordingly, but then got another error saying the curves must lie on the same plane as the sketch— which they don’t in my case.

 

I’ll now try your suggestion of retrieving the roof sketch. However, I’m working with a FootPrintRoof, and I haven’t found a simple way to access its sketch. In this 2010 blog post https://thebuildingcoder.typepad.com/blog/2010/11/access-to-sketch-and-sketch-plane.html, Jeremy mentions deleting the roof to get the sketch ID. Since that’s a pretty old workaround, is there a better way nowadays to access the sketch of a FootPrintRoof?

0 Likes
Message 4 of 5

ctm_mka
Collaborator
Collaborator

ah ha! given that you received the error about curves on the wrong plane, please try running your code with model curve array using your "source_level". That behavior screams "needs translation" to me. By which I mean you need to translate your elements to the desired plane, probably after converting them. as far as finding the sketch of the roof, using lookup, this is what it looks like for a floor, hopefully its something similar:

ctm_mka_0-1750432886914.png

and code to access looks something like this:

 Sketch floorsketch = _doc.GetElement(testfloor.SketchId) as Sketch;
 foreach (CurveArray curvarr in floorsketch.Profile)
 {
    
 }
0 Likes
Message 5 of 5

Leo_CourvalKVP86
Participant
Participant

Alright, thanks to my highly advanced RevitLookup skills (well, sort of ;-)), I discovered that the .GetProfiles() method gives me exactly what I need—namely, the roof profile in a plane parallel to the XY plane, in the form of a ModelCurveArrArray. So that’s perfect!

I’ve now completed what I wanted to do on that front.

Just one small hiccup at the end: Revit can be quite picky sometimes. The profile loops I get from my roofs are always closed (as expected, since the roof extrusion has already been created). However, after retrieving those curves, Revit tells me it can’t recreate a closed loop from them. I believe this is due to extremely tight tolerances—an error as small as 1e-10 might be enough to prevent the loop from closing properly.

Anyway, I found a workaround to close the loops, so everything's good now.

Leo_CourvalKVP86_0-1750681410689.png

 

0 Likes