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();
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();