Intro to Revit API - Create Wall from Location Line OR XYZ data

Intro to Revit API - Create Wall from Location Line OR XYZ data

Anonymous
Not applicable
10,443 Views
8 Replies
Message 1 of 9

Intro to Revit API - Create Wall from Location Line OR XYZ data

Anonymous
Not applicable

Hello,

 

I'm new to Revit's API.

I have a small problem to solve, which is to draw the walls of a room from either:

a) XYZ coordinates for the ends of the wall centerlines (from a txt or csv file)

b) existing sketched lines in the Revit document

 

There will probably be more requirements later, such as the nesting of windows and doors, but I'm ignoring that for now, and just want to create the walls. It would also prompt the user to select a level to set the walls on.

 

Are there any examples available online?

Or is this something that is easy to write and a generous soul here is willing to help me out with?

If I keep this simple, I think it can be a nice intro to Revit's API.

 

Thanks!

0 Likes
Accepted solutions (2)
10,444 Views
8 Replies
Replies (8)
Message 2 of 9

Joe.Ye
Alumni
Alumni

 

Hi,

 

Revit walls can simply created by Wall.Create(Curve curve, WallType type) method.

 

Here is the code snippet to create a wall.

Transaction act = new Transaction(m_myDocument.Document);

act.Start(Guid.NewGuid().GetHashCode().ToString());
Wall wall = Wall.Create(m_myDocument.Document, baseline, m_selectedWallType.Id,
m_selectedView.GenLevel.Id, 20, 0, false, false);
act.Commit()

 

You can use Form and add level list control to it. And uses can select target level through the form.

 

As you are new to Revit API, 

We have the My First Revit Plug-in tutorial: http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=16777469

 

And some DevTV video for beginner in this page: http://usa.autodesk.com/adsk/servlet/index?id=2484975&siteID=123112

 

 


______________________________________________________________

If my post answers your question, please click the "Accept as Solution" button. This helps everyone find answers more quickly!



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 9

Anonymous
Not applicable

Hello Joe,

 

I'm using the CreateWallsUnderBeams sample from the SDK as a starting point.

I got an error with the code you gave me when running it from a 3D View. I assumed that it was because of the argument:

m_selectedView.GenLevel.Id

 

And instead I used:

 

            StringBuilder levelInformation = new StringBuilder();
            FilteredElementCollector collector = new FilteredElementCollector(project.Document);
            ICollection<Element> collection = collector.OfClass(typeof(Level)).ToElements();

            // Get the level which will be used in create method
            m_level = collector.OfClass(typeof(Level)).FirstElement() as Level;

  

Which apparently worked on the modified SDK sample.

But now I am modifying it so that instead of selecting beams and creating walls under each, I am selecting Model Lines to accomplish the same.

 

                Transaction t = new Transaction(project, Guid.NewGuid().GetHashCode().ToString());
                t.Start();
                Wall createdWall = Wall.Create(project, l1.GeometryCurve, m_selectedWallType.Id, m_level.Id, 10, 0, true, m_isStructural);

Where "l1" is each ModelLine in an ArrayList.

While debugging, I get a "null" value for l1.GeometryCurve, even though the ArrayList shows having, in this case, 21 values.

 

Am I wrong to use "GeometryCurve" from the ModelLine as an argument for Wall.Create?

 

 

Thanks Joe,

 

Santiago

 

0 Likes
Message 4 of 9

Anonymous
Not applicable

And here's a the detailed error:

 

Autodesk.Revit.Exceptions.ArgumentNullException was unhandled by user code
Message=Null argument
Parameter name: curve
Source=RevitAPI
ParamName=curve
StackTrace:
at Autodesk.Revit.DB.Wall.Create(Document document, Curve curve, ElementId wallTypeId, ElementId levelId, Double height, Double offset, Boolean flip, Boolean structural)
at Revit.SDK.Samples.CreateWallsUnderBeams.CS.CreateWallsUnderBeams.BeginCreate(Document project) in C:\Revit 2013 SDK\Samples\CreateWallsUnderBeams\CS\CreateWallsUnderBeams.cs:line 210
at Revit.SDK.Samples.CreateWallsUnderBeams.CS.CreateWallsUnderBeams.Execute(ExternalCommandData commandData, String& message, ElementSet elements) in C:\Revit 2013 SDK\Samples\CreateWallsUnderBeams\CS\CreateWallsUnderBeams.cs:line 163
at apiManagedExecuteCommand(AString* assemblyName, AString* className, AString* vendorDescription, MFCApp* pMFCApp, DBView* pDBView, AString* message, Set<ElementId\,std::less<ElementId>\,tnallc<ElementId> >* ids, Map<AString\,AString\,std::less<AString>\,tnallc<AString> >* data, AString* exceptionName, AString* exceptionMessage)
InnerException:

 

 

 

Any help is much appreciated.

 

Santiago

0 Likes
Message 5 of 9

jeremytammik
Autodesk
Autodesk

Hi Santiago,

 

Well, have you checked the argument that you are passing in?

 

Maybe it really is null?

 

From a model curve, you can easily obtain the geometry in some way, either through GeometryCurve or other means.

 

That geometry you can easily pass in to the wall creation method.

 

Just check that it is not null in between.

 

Are you aware of the RevitLookup tool?

 

If not, read about it on the blog, install it, and use it before doing anything else whatsoever.

 

It will enable you to look at the contents of the GeometryCurve property interactively thorugh the user interface.

 

You might even be interested in exploring the use of the Revit Ruby or Python shells. They enable completely interactive use and exploration of all aspects and functionality of the Revit API, individual statements, call by call.

 

Cheers

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 6 of 9

Anonymous
Not applicable

Thanks Jeremy,

 

The curve argument (wallLine) shows as not being null (see image attached below).

I also tried using a CurveArray to ensure that the object being passed as a curve argument was actually a curve.

'wallLine' appears in Locals as an Autodesk.Revit.DB.Line, which is supposed to inherit the Curve class.

This threw the same exception (attached image) that modelLine.GeometryCurve threw.

 

So, why will Wall.Create not accept my curve (wallLine) object?

Or am I reading the ArgumentNullException incorrectly?

 

error_capture 2.gif

0 Likes
Message 7 of 9

Joe.Ye
Alumni
Alumni

 

Hi Santiago

 

From what you described, l1 just cannot return a valid curve. This is strange.

ModelLine should be able to return a valid curve by GeometryCurve property.

 

It seems that l1 may by a null object. Would you please debug and check if l1 is null or invalid object?

 

 



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 8 of 9

conoves
Autodesk
Autodesk
Accepted solution

Hello -

 

For Revit 2013, there was a bug with the Wall.Create() method. 

 

Try doing the following instead:

 

Wall createdWall = Wall.Create(project, l1.GeometryCurve.Clone(), m_selectedWallType.Id, m_level.Id, 10, 0, true, m_isStructural);


Scott Conover

Senior Engineering Manager, Revit

Message 9 of 9

Anonymous
Not applicable
Accepted solution

Super! Yes, I am using Revit 2013. Problem solved.

Thanks Scott!

Next time I'll remember to mention the revit version I'm working with.

 

Santiago

0 Likes