I'm a API beginner following "revit API training labs", I'm learing how to use API to create a family. I'm puzzling over this error, can anyone help?
I labeled a dimension using the method provided in training lab, while the totally same method don't apply to another dimmention.
The extrusion was created by API and alignments between faces and reference planes were added successfully.
here is the code:
void addDimensions(Document doc) { View pViewPlan = findElement(typeof(ViewPlan), "Lower Ref. Level",doc) as View; ReferencePlane refLeft = findElement(typeof(ReferencePlane), "Left",doc) as ReferencePlane; ReferencePlane refFront = findElement(typeof(ReferencePlane), "Front",doc) as ReferencePlane; ReferencePlane refOffsetV = findElement(typeof(ReferencePlane), "OffsetV",doc) as ReferencePlane; ReferencePlane refOffsetH = findElement(typeof(ReferencePlane), "OffsetH",doc) as ReferencePlane; XYZ p0 = refLeft.FreeEnd; XYZ p1 = p0 + new XYZ(100, 0, 0); Line pline = Line.CreateBound(p0, p1); ReferenceArray pRefArray = new ReferenceArray(); pRefArray.Append(refOffsetV.GetReference()); pRefArray.Append(refLeft.GetReference()); Dimension pDimTw = doc.FamilyCreate.NewDimension(pViewPlan, pline, pRefArray); FamilyParameter paramTw = doc.FamilyManager.get_Parameter("Tw"); pDimTw.FamilyLabel = paramTw; //**Succeeded!! p0 = refOffsetH.FreeEnd; p1 = p0 + new XYZ(0, 100, 0); pline = Line.CreateBound(p0, p1); pRefArray.Append(refOffsetH.GetReference()); pRefArray.Append(refFront.GetReference()); Dimension pDimTd = doc.FamilyCreate.NewDimension(pViewPlan, pline, pRefArray); FamilyParameter paramTd = doc.FamilyManager.get_Parameter("Td"); pDimTd.FamilyLabel = paramTd; //**failed!! Both paramTd and pDimTd are not null. } //InvalidOperationException:the dimension can not be labeled
I think the way to add alignments and labels were the same, why it didn't work?!
Besides,I failed to add new types after deleting the last line above.There are there kinds of errors:(1) constraints are not satisfied (2)Line is too short (3)Dimension refernces are or have became invalid I guess (1) and (3) are due to the label error, but not sure about (2).
It's a little hard to learn API by myself. Thanks to you friendly and enthusiastic guys' help so that I can make a little progress.
Thank you!