Failed to Edit the sketches of the walls using C#

Failed to Edit the sketches of the walls using C#

ahmadkhalaf7892
Advocate Advocate
311 Views
1 Reply
Message 1 of 2

Failed to Edit the sketches of the walls using C#

ahmadkhalaf7892
Advocate
Advocate

Hi Revit users. 
I was trying to see how can I create walls and edit their sketches(Profile)  via C# . I have written this code .

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// Get Document and UIDocument
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;
FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType();
Level lev = collector.Where(e => e.Name.Contains("1")).First() as Level;
IList<Curve> curves = new List<Curve>();
XYZ p1 = new XYZ(0, 0, 0);
XYZ p2 = new XYZ(50, 50, 0);
XYZ p3 = new XYZ(0, 0, 20);
XYZ p4 = new XYZ(50, 50, 10);
XYZ referencevector = new XYZ(0, 0, 1);
Curve l1 = Line.CreateBound(p1, p2);
Curve l2 = Line.CreateBound(p2, p3);
Curve l3 = Line.CreateBound(p3, p4);
Curve l4 = Line.CreateBound(p4, p3);
curves.Add(l1);
curves.Add(l2);
curves.Add(l3);
curves.Add(l4);

Transaction transaction1 = new Transaction(doc);
transaction1.Start("Create Wall");
Wall w1 = Wall.Create(doc, curves, true);
transaction1.Commit();

return Result.Succeeded;
}
}
I am getting this error

Failed Wall.PNG

 What am I doing wrong ? and how can I edit these sketches. I'd appreciate any answer.

Wall Profile Shape.PNG

0 Likes
312 Views
1 Reply
Reply (1)
Message 2 of 2

ahmadkhalaf7892
Advocate
Advocate

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// Get Document and UIDocument
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;
FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType();
Level lev = collector.Where(e => e.Name.Contains("1")).First() as Level;
// create an ilist for the curevs
IList<Curve> curves = new List<Curve>();
XYZ p1 = new XYZ(0, 0, 0);
XYZ p2 = new XYZ(50, 50, 0);
XYZ p3 = new XYZ(50, 50, 500);
XYZ p4 = new XYZ(0, 0, 20);

// create the curves
XYZ referencevector = new XYZ(0, 0, 1);
Curve l1 = Line.CreateBound(p1, p2);
Curve l2 = Line.CreateBound(p2, p3);
Curve l3 = Line.CreateBound(p3, p4);
Curve l4 = Line.CreateBound(p4, p1);
curves.Add(l1);
curves.Add(l2);
curves.Add(l3);
curves.Add(l4);

Transaction transaction1 = new Transaction(doc);
transaction1.Start("Create Wall");
Wall w1 = Wall.Create(doc, curves, true);
transaction1.Commit();

return Result.Succeeded;
}
Apparently I was using a wrong Command and list of points

0 Likes