Rhino Inside create railing revit API python

Hello!
does anybody have any clue how to create a railhand in Revit using Rhino.Inside?

It throws an error that doesnt allow me to generate the railhand

thanks in advance

1 Like

Hello Rickson,

thanks for the help, it seems to be a work around, only, if you could tell me how to translate it to python. I have little understanding of C#…

as far as I understood I need to add the RhinoInside.Revit.Rhinoceros.InvokeInHostContext. Nevertheless something is missing cause I added up to the code but still not working.

thanks in advance!

I don’t think you need that. I believe it needs

doc
railing type.id
level.id
curves as iList[ElementId]()

i’ll see if i can get something working, learning here myself.

1 Like

Ok, got this to work, barely…

the curve to List[Curve] to List[CurveLoop] is certainly not the ideal way. Hopefully a py pro will comment with the right way.

RiR-CreateRailing_Py.gh (9.4 KB)


import clr
clr.AddReference('System.Core')
clr.AddReference('RhinoInside.Revit')
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI')
clr.AddReference('System')

from System.Collections.Generic import List

from System import Enum

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

clr.ImportExtensions(RhinoInside.Revit.Convert.Geometry)

# active Revit verison
REVIT_VERSION = Revit.ActiveUIApplication.Application.VersionNumber

# access the active document object
doc = Revit.ActiveDBDocument

def show_warning(msg):
    ghenv.Component.AddRuntimeMessage(RML.Warning, msg)

def show_error(msg):
    ghenv.Component.AddRuntimeMessage(RML.Error, msg)

def show_remark(msg):
    ghenv.Component.AddRuntimeMessage(RML.Remark, msg)

curves = List[DB.Curve]()
curves.Add(Curve.ToCurve())

clc = DB.CurveLoop.Create(curves)

# create and start the transaction
t = DB.Transaction(doc, 'Create Railing')
t.Start()
try:


    railing = DB.Architecture.Railing.Create(doc, clc, Type.Id, Level.Id)

    t.Commit()
except Exception as txn_err:
    # if any errors happen while changing the document, an exception is thrown
    # make sure to print the exception message for debugging
    show_error(str(txn_err))
    # and rollback the changes made before error
    t.RollBack()

edit (you probably want to throw the data dam back in there or it will create again and throw an error)

1 Like

hello Rickson,

Thanks a lot for the effort! It is really nice from you to spend some time on my issue. Nevertheless I am not sure why i continue having the same problem thant I had with my code.

maybe a third person can try your code and say if for him/her works, cause maybe there is something wrong with my revit.

Cheers.

Igperma, I believe the error is due to creating another instance on top of the previous.

If i open up a clean file, select railing type and level then activate i get no errors, if i change the radius, reactivate it works fine. If i hit a GH refresh it throws the warning (still creating the object)

No worries, they are adding in a Railing by Curve component on the next release…

image

Latest RiR with Add Railing Component…