Errors when import library to Python Script - Rebar from Curves

Errors when import library to Python Script - Rebar from Curves

Anonymous
Not applicable
2,292 Views
2 Replies
Message 1 of 3

Errors when import library to Python Script - Rebar from Curves

Anonymous
Not applicable

I'm studying about Python in Revit and trying to use RebarFromCurves method to add Rebar to my drawing.

 

But why my script can not find __revit__ or Structure (like in the picture)? I searched Google and copy exactly the same code (when import Revit DB at the beginning) but it won't show any suggestions. I am new and trying to learn Python in Revit so I need suggestion to help me.

Ex: Structure.Rebar.CreateFromCurves

 

Is there any way for me to get rid of this?

 

Thank you in advanced.

 

0 Likes
Accepted solutions (1)
2,293 Views
2 Replies
Replies (2)
Message 2 of 3

architect.bim
Collaborator
Collaborator
Accepted solution

Hi!

__revit__ is a predefined name which refers to an istance of UIApplication class. You can use it only if you run your code in Revit Python Shell. If you do so - there is no problem, you can add # noqa comment in VS Code to ignore it.

To use Structure namespace you must first import it. Furthermore creation of new elements in Revit must be inside an open transaction. And also to use CreateFromCurves method you must pass a plenty of arguments to it (I don't see any argument on your picture).

You can start from this scratch and add necessary arguments to method:

 

 

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit import DB
from Autodesk.Revit.DB import Structure

uidoc = __revit__.ActiveUIDocument         # noqa
doc = __revit__.ActiveUIDocument.Document  # noqa

with DB.Transaction(doc, 'New Rebar') as t:
    t.Start()
    rebar = Structure.Rebar.CreateFromCurves()  # pass arguments to this method
    t.Commit()

 

 

 


Maxim Stepannikov | Architect, BIM Manager, Instructor
Message 3 of 3

Anonymous
Not applicable

I have just started learning about programming in REVIT. Things' got very complicated for me.

 

I think I have problems with setting up Python in Revit, I used PyRevit. Since it doesn't work as the way people use it. 

 

But thank you. It does help me a lot.