Wall.Create throwing exception

Wall.Create throwing exception

Anonymous
Not applicable
547 Views
2 Replies
Message 1 of 3

Wall.Create throwing exception

Anonymous
Not applicable

I'm having trouble figuring out why the new Wall.Create method is throwing an ArgumentNullException against my curve.  What's throwing me off is that the deprecated method of creating a wall works just fine with the same curve.

 

 

I'm getting the curve from another element's location property (and previously ensuring it has a curve based location and not a locationpoint)

LocationCurve lCurve = (LocationCurve)elem.Location;

curves.Append(lCurve.Curve);

 

My curve is not null and is of type Autodesk.Revit.DB.Line (see attachment) but throws an exception when I try to create a wall using the static Wall.Create method.

     foreach (Curve c in curveArray)
     {
// This works but is deprecated Wall w = uidoc.Document.Create.NewWall(c, uidoc.ActiveView.GenLevel, false);

// This throws an ArgumentNullException (see attachment) Wall wall = Wall.Create(uidoc.Document, c, uidoc.ActiveView.GenLevel.Id, false); }

 

Is there something else that changed with the new Wall.Create method or am I missing something else?  Has anyone else seen this?

 

0 Likes
548 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Anyone?  Autodesk?

 

Here is a simple example that throws the same exception when your selection set contains a line or wall.

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
    UIDocument uiDoc = commandData.Application.ActiveUIDocument;

    Autodesk.Revit.UI.Selection.SelElementSet set = uiDoc.Selection.Elements;

    foreach (Element e in set)
    {
        Wall.Create(uiDoc.Document, (e.Location as LocationCurve).Curve, uiDoc.ActiveView.GenLevel.Id, false);
    }
    return Result.Succeeded;
}

 

If I replace Wall.Create with the code below it works fine but this method is obsolete:

uiDoc.Document.Create.NewWall((e.Location as LocationCurve).Curve, uiDoc.ActiveView.GenLevel, false);

 

0 Likes
Message 3 of 3

augusto.goncalves
Alumni
Alumni

Hi Joe,

 

Please try with Curve.Clone() instead share the same curve between two elements. The Clone() will ensure a copy is used and avoid further problems.

 

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes