RiR - GHPython Create ModelCurve - Revit API problem

Hi all,
I just started to use RiR and wanted to develop my knowledge in the REVIT API by using GH in order to set Dynamo out of my life :smile:

So I started by creating a GHPython Script to create Model Line…but I am stuck and the problem is that I have no clue on which is the problem.

Attached you can find the .GH file, but the problem is here


for line in revitLines:
____modelLine = RCR.ItemFactoryBase.NewModelCurve(line, sketch)
____modelLines.append(modelLine)

the error says
Runtime error (ArgumentTypeException): NewModelCurve() takes exactly 3 arguments (2 given)
(but in the API the NewModelCurve method wants 2 argument a curve and a sketch plane)

it seems that the problem concerns the Argument Type (the line element is an Autodesk.DB.Revit.Line).

Do you have any idea?

Thank you in advance
Mauro

ModelLines_GH

The problem was that NewModelCurve is not a static function and needs an instance of an ItemFactoryBase to run.

You may call it as you were trying to do but passing this as the first argument:

RCR.ItemFactoryBase.NewModelCurve(doc.Create, line, sketch)

or I personally prefer the typical OO way of doing it

doc.Create.NewModelCurve(line, sketch)

I’m far of being a Python expert, but I would recomend you to use the python with statement to manage transactions and not be in the wild side in case of an exception.

I did those changes to your script and looks like that:

import clr
clr.AddReference('System.Core')
clr.AddReference('RhinoInside.Revit')
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI')
        
from System.Linq import Enumerable
import Autodesk.Revit.DB as RDB
import Autodesk.Revit.Creation as RCR
from Rhino.Geometry import *
from RhinoInside.Revit import Revit, Convert
        
doc = Revit.ActiveDBDocument

#Create Lines

startPoint = []
endPoint = []
revitLines = []
modelLines = []

with RDB.Transaction(doc, "RiR_ModelLine") as trans:
    trans.Start()
    
    for elemento in x:
        startPoint.append(RDB.XYZ(elemento.PointAtStart.X, elemento.PointAtStart.Y, elemento.PointAtStart.Z))
        endPoint.append(RDB.XYZ(elemento.PointAtEnd.X, elemento.PointAtEnd.Y, elemento.PointAtEnd.Z))
    
    for punto in startPoint:
        revitLine = RDB.Line.CreateBound(punto, endPoint[startPoint.index(punto)])
        revitLines.append(revitLine)
    
    piano = RDB.Plane.CreateByThreePoints(RDB.XYZ(-100,-100,0), RDB.XYZ(100,-100,0), RDB.XYZ(100,100,0))
    sketch = RDB.SketchPlane.Create(doc, piano)
    
    
    for line in revitLines:
        modelLine = doc.Create.NewModelCurve(line, sketch)
        modelLines.append(modelLine)
    
    trans.Commit()

# Assegnare l'output dell'utente alla variabile OUT.
        
ModelLine = revitLines
2 Likes

Thank you Kike for all your suggestions.
This is just one of many iterations of the script.
Some had the “with” statement (like in sample7.py) then everything turned into a mess when dealing with the external API problem :slight_smile:

Thanks again