Editing wall profile

Hi there,

I’m trying to edit the profile of a wall using the newly introduced API methods in Revit 2022 and I’m having a weird crash issue. Before I get to that, I know there’s a component for creating a wall by profile but that’s not what I want to do. I need to create the wall by curve and then edit its profile.

So at the moment I have the following code:

import clr

from System import Enum, Action

import rhinoscriptsyntax as rs
import Rhino
import RhinoInside
import Grasshopper
from RhinoInside.Revit import Revit, Convert
from Autodesk.Revit import DB

import RhinoInside.Revit.Convert.Geometry

from Autodesk.Revit import DB

doc = Revit.ActiveDBDocument
def EditWallProfile(doc, wall, profileSegments):
    with DB.Transaction(doc, 'get the sketch') as t:
        sketch = wall.CreateProfileSketch()
    skEditScope = DB.SketchEditScope(doc, "edit the wall profile")
    skEditScope.Start(sketch.Id) # 
    with DB.Transaction(doc, 'delete the existing sketch and create new sketch') as t:
        exElems = sketch.GetAllElements()
        for elId in exElems:
            el = doc.GetElement(elId)
            #if el is DB.ModelLine:
        # create model lines
        for item in profileSegments:
            revitCurve = item.ToCurve()
            c = doc.Create.NewModelCurve(revitCurve, sketch.SketchPlane)        
    # close the sketch editor

class FailuresPreprocessor(DB.IFailuresPreprocessor):
    def PreprocessFailures(self, failuresAccessor):
        return FailureProcessingResult.Continue

if Trigger:
    EditWallProfile(doc, wall, profileSegments)

wall is a wall create by location line.
and profileSegments is a list consisting of line-like curves that are in the same plane as the wall.

What happens in the first try is that sometimes I get a “managed exception by Revit or a third party” error (paraphrasing). If I re-trigger the python component it’ll run then it goes in sketch editing mode and shows my desired sketch in the sketch mode. However it won’t close the sketch mode. And when I click on the UI it closes the sketch mode without applying the new sketch. After a couple of tries then Revit crashes.

I’ve done the same thing through Revit’s Macro manager and it works fine so the code does not seem to be the problem.

My guess is Rhino Inside somehow is stopping Revit to come out of the sketch mode gracefully. And Revit doesn’t know how to handle it.

Any ideas how to fix this? Sample Rhino and gh files attached.

EditRevitWallProfile_.gh (9.3 KB)
EditRevitWallProfile_.3dm (25.0 KB)

Hi @hzamani,

Does not ‘Host Boundary Profile’ work for you?

Since Revit 2022 it works with with any HostObject like Walls.

Thanks @kike. This is close but not exactly giving me what I want.

I think with a little improvement in the component this will also work though.

So at the moment if you input a wall (created using a location curve) which it’s profile hasn’t been edited before, the component will start drawing the Revit model curves outside of the sketch edit mode. So what I’ll get is just a bunch of model lines in the shape of profile that I need. Also the wall will be deleted. I think this is probably not what you’ve intended for this component to do. On the other hand, if I edit the profile of my wall manually, then input it as the host element, then I can edit it’s profile.

Probably the part that’s missing in the component is wall.CreateProfileSketch() if the host element is a wall. Because otherwise the wall will not have a Sketch.

@hzamani you are right there was a bug when the wall does not have already a sketch.

It’s fixed now on 1,14 and will be on 1.13 next Tuesday.

1 Like