Due to the version problem of Revit, the code for the generated wall element found on the web, compiled in Revit 2016 on my machine, was not able to pass through multiple debugs and finally found the code to generate the wall elements using the API in Revit 2016, which is now posted.
The following code is passed in the context of Revit + VS2013.
Class Createwall:iexternalcommand {public static Document Revitdoc; public static Autodesk.Revit.ApplicationServices.Application Revitapp; Public Autodesk.Revit.UI.Result Execute (externalcommanddata commanddata, ref string message, Autodesk.Revit.DB. ElementSet elements) {Revitapp = commandData.Application.Application; var uidoc = commandData.Application.ActiveUIDocument; if (Uidoc = = null) {message = "Please open a document"; return result.failed; } Revitdoc = CommandData.Application.ActiveUIDocument.Document; var uisel = commandData.Application.ActiveUIDocument.Selection; Transaction Transaction = new Transaction (Revitdoc, "Testscript.createnewinstancewithnewtype"); Transaction. Start (); try {var typeFilter = new Elementclassfilter (typeof (Walltype)); FilTeredelementcollector walltypes = new Filteredelementcollector (Revitdoc); Walltypes = walltypes.wherepasses (TypeFilter); Walltype walltype = null; foreach (Walltype walltype in walltypes) {walltype = Walltype; Break if (walltype! = null) {//Create new wall type, use duplicate method var NE Wtype = Walltype. Duplicate (Walltype. Name + "_new"); You can modify the parameters of the wall type here, such as modifying the absorption rate var para = walltype.get_parameter (builtinparameter.analytical_absorptance); IF (para! = NULL && para. Storagetype = = Storagetype.double && para. IsReadOnly = = false) {para. Set (2.0); }//Find an elevation level level = NULL; var levelfilter = new Elementclassfilter (typeof (level)); Filteredelementcollector levels = new Filteredelementcollector (Revitdoc); levels = levels. Wherepasses (Levelfilter); foreach (level element in levels) {level = element; Break }//Create wall var wall = Wall.create (Revitdoc, Line.createbound (new XYZ (0, 0, 0), new XYZ (Ten, 0, 0), Newtype. Id, level. Id, 0, False, false); Taskdialog.show ("Wall creation", "wall created, id =" + wall. ID); } transaction.commit (); } catch (Exception ex) {message = ex. ToString (); Transaction. RollBack (); return result.failed; } return result.succeeded; } }
Revit API generates wall elements