PDA

View Full Version : "Create Dimensions" in Revit API samples



larjia
2007-03-08, 01:39 AM
Hi all,

I tried to run the "CreateDimensions" samples in the Revit API SDK, but failed. After debugging the sample, I found the problem seems from the AddDimension() method.

1) I don't know what's the meaning of the ReferenceArray as below:

// get reference
ReferenceArray referenceArray = new ReferenceArray();

What is reference here? Do we need to do this only for creating a new dimension?

2) Why the GeoObjectArray.get_item(int) methods returns an object of type Autodesk.Revit.Geometry.Solid but not Autodesk.Revit.Geometry.GeometryObject?

Autodesk.Revit.Geometry.Element element = wallTemp.get_Geometry(options);
GeometryObjectArray geoObjectArray = element.Objects;
// enum the geometry element
for (int j = 0; j < geoObjectArray.Size; j++)
{
GeometryObject geoObject = geoObjectArray.get_Item(j);
// Here the geoObject is of type Autodesk.Revit.Geometry.Solid !!!
Curve curve = geoObject as Curve;
// curve will equals to null !!!
.....
}

Any suggestions? Thanks in advance....

Danny Polkinhorn
2007-03-08, 07:48 PM
ReferenceArray referenceArray = new ReferenceArray();

What is reference here? Do we need to do this only for creating a new dimension?
The reference array contains the elements that the witness lines will be tied to. The line you're referring to merely creates an empty reference array.
A little farther down in this line:
referenceArray.Append(curve.Reference);
populates the array with the lines. In the AddDimension code, this line:
Dimension newDimension = m_revit.Application.ActiveDocument.Create.NewDimension (m_revit.Application.ActiveDocument.ActiveView, newLine2, referenceArray);
passes the array to the new dimension.

2) Why the GeoObjectArray.get_item(int) methods returns an object of type Autodesk.Revit.Geometry.Solid but not Autodesk.Revit.Geometry.GeometryObject?GeometryObject geoObject = geoObjectArray.get_Item(j);
Curve curve = geoObject as Curve;
if (null != curve)
Some of the elements in the wall may be solids, but what it's looking for is curves. These three lines get the element, set it equal to a curve (which you can't do if it's not a curve), then the last line filters out the exceptions. It's not the right way to do it, I don't think. It should check the type, then continue.
If TypeOf geoObject is Curve then... (vb code)

Hope that helps,