How to set the wall height?

How to set the wall height?

Anonymous
Not applicable
4,215 Views
5 Replies
Message 1 of 6

How to set the wall height?

Anonymous
Not applicable

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;
}
}

0 Likes
Accepted solutions (1)
4,216 Views
5 Replies
Replies (5)
Message 2 of 6

thannaingoo.api
Advocate
Advocate
Accepted solution

Hi,

 

You can try with below code for walls creation.  You can set the height directly.

 

http://www.revitapidocs.com/2015/0ce4c555-4cee-f5fd-2e84-43cacf34ac5c.htm

 

public static Wall Create(
	Document document,
	Curve curve,
	ElementId wallTypeId,
	ElementId levelId,
	double height,
	double offset,
	bool flip,
	bool structural
)

 

Please refer the below link for walls creation. We can find a lot of solution in thebuildingcoder.

 

http://thebuildingcoder.typepad.com/blog/2017/11/automatic-wall-creation.html

 

Thanks,

Eden Oo

 

 

 

0 Likes
Message 3 of 6

zhong_wu
Autodesk Support
Autodesk Support

Firstly, I just checked your code and run it on my side, it seems good to set the offset & height correctly to the new created wall, please see the following screenshot as I got.

Create a wallCreate a wallAlso, there are some other parameters you can use to set the height in different way, for example, set the top constraint by "WALL_HEIGHT_TYPE" to any level, and set the top offset with "WALL_TOP_OFFSET". 

 

Check the API doc at http://www.revitapidocs.com/2018.1/3ef7e31c-b41b-c8cc-2713-8f098954613d.htm for details.


John Wu
Developer Technical Services
Autodesk Developer Network


Message 4 of 6

Anonymous
Not applicable

Hi,

Thank you for your reply.

I can set the height of the wall now, but the result puzzle me a little. That is, I set the height to 100 in VS, but the result is 30480 in revit. screenshot attached as below. 11.png22.png

0 Likes
Message 5 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous,

In code what you are giving is in feet (i.e)100 feet

but in Revit it is showing the units in millimeter(mm).

If you want everything in feet you can change the unit settings in Revit


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 6 of 6

Anonymous
Not applicable

Got it, thank you very much !

0 Likes