PDA

View Full Version : Just trying to make a simple beam!!!



mpruna
2008-03-24, 01:34 PM
Please see the code below. I checked the variables and they all appear to be the right thing.
Except that the location of the beam is a point, and trying to assign a line to the location results in the variable "beamcurve" being null. (Without the "if" statement , I get the "object reference not being set to an instance of the object).
What I get when I run the program is a beam with a 0 length.

The code below is similar to the one in the "create beams column braces" sample in the Revit SDK.

Trying to use the NewFamilyInstance command with a curve argument does not work at all either.


Code below:

double heightop = topLevel.Elevation;
double heighbot = baseLevel.Elevation;
XYZ startPoint = new XYZ(point2D1.U, point2D1.V, heightop+topoffset);
XYZ endPoint = new XYZ(point2D2.U, point2D2.V, heighbot+botoffset);
app.ActiveDocument.BeginTransaction();
Autodesk.Revit.Structural.Enums.StructuralType structuralType = Autodesk.Revit.Structural.Enums.StructuralType.Beam;

FamilyInstance beam = app.ActiveDocument.Create.NewFamilyInstance(ref startPoint, beamtype, topLevel, structuralType);
Autodesk.Revit.Location blocation = beam.Location;
LocationCurve beamCurve = blocation as LocationCurve;
if (null != beamCurve)
{
Autodesk.Revit.Geometry.Line line = app.Create.NewLineBound(ref startPoint, ref endPoint);
MessageBox.Show(beamCurve.Curve.ApproximateLength.ToString());
beamCurve.Curve = line;
}
app.ActiveDocument.EndTransaction();

mpruna
2008-03-24, 03:22 PM
for comparison, here's the code from the API SDK Sample:


private void PlaceBeam(UV point2D1, UV point2D2, Level baseLevel, Level topLevel, FamilySymbol beamType)
{
double height = topLevel.Elevation;
XYZ startPoint = new XYZ(point2D1.U, point2D1.V, height);
XYZ endPoint = new XYZ(point2D2.U, point2D2.V, height);
ElementId topLevelId = topLevel.Id;

STRUCTURALTYPE structuralType = Autodesk.Revit.Structural.Enums.StructuralType.Beam;
FamilyInstance beam = m_revit.ActiveDocument.Create.NewFamilyInstance(ref startPoint, beamType, topLevel, structuralType);

LocationCurve beamCurve = beam.Location as LocationCurve;
if (null != beamCurve)
{
Line line = m_revit.Create.NewLineBound(ref startPoint, ref endPoint);
beamCurve.Curve = line;
}
}

Elizabeth Shulok
2008-03-24, 03:54 PM
It looks like it should work - I've used similar code myself. In your code, have you stepped through to make sure blocation is not null before you try to cast it to a LocationCurve?

mpruna
2008-03-24, 04:03 PM
thanks for the reply, I figured out what I was doing wrong: I wasn't checking that the category of the family symbol I was loading was in fact a beam. Therefore, I was loading a column symbol and thus the point location when generating a new family instance
:)