
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need export a wall, and then import and create the same wall.
I find the height related parameters are null or readonly, for the parameter which is not readonly, e.g. "Unconnected Height", the result is not the value I set, so how can I set the height of a wall ?
here is my code as below:
[Transaction(TransactionMode.Manual)]
public class CreateWallCmd : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
XYZ pt1 = new XYZ(0, 0, 0);
XYZ pt2 = new XYZ(10, 0, 0);
Line line = Line.CreateBound(pt1, pt2);
Level level= new FilteredElementCollector(doc)
.OfClass(typeof(Level))
.First<Element>(e => e.Name.Equals("Level 1")) as Level;
Transaction act = new Transaction(doc, "Wall.Create");
act.Start();
try
{
Wall wall = Wall.Create(doc, line, level.Id, true);
Parameter WALL_ATTR_HEIGHT_PARAM = wall.get_Parameter(BuiltInParameter.WALL_ATTR_HEIGHT_PARAM);
if (WALL_ATTR_HEIGHT_PARAM != null)
{
if (!WALL_ATTR_HEIGHT_PARAM.IsReadOnly)
{
WALL_ATTR_HEIGHT_PARAM.Set(100);
}
}
Parameter WALL_BASE_HEIGHT_PARAM = wall.get_Parameter(BuiltInParameter.WALL_BASE_HEIGHT_PARAM);
if (WALL_BASE_HEIGHT_PARAM != null)
{
if (!WALL_BASE_HEIGHT_PARAM.IsReadOnly)
{
WALL_BASE_HEIGHT_PARAM.Set(100);
}
}
Parameter WALL_BASE_OFFSET = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
if (WALL_BASE_OFFSET != null)
{
if (!WALL_BASE_OFFSET.IsReadOnly)
{
WALL_BASE_OFFSET.Set(50);
}
}
Parameter WALL_TOP_OFFSET = wall.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET);
if (WALL_TOP_OFFSET != null)
{
if (!WALL_TOP_OFFSET.IsReadOnly)
{
WALL_TOP_OFFSET.Set(100);
}
}
IList<Parameter> UnconnectedHeigth_Params = wall.GetParameters("Unconnected Height");
if (UnconnectedHeigth_Params.Count > 0)
{
if (!UnconnectedHeigth_Params[0].IsReadOnly)
{
// can set, but the result is not 100
UnconnectedHeigth_Params[0].Set(100);
}
}
}
catch (System.Exception e)
{
TaskDialog.Show("Exception", e.Message);
}
act.Commit();
return Result.Succeeded;
}
}
Solved! Go to Solution.