Invalid number of references

Invalid number of references

mr.engineer.aec
Advocate Advocate
1,119 Views
8 Replies
Message 1 of 9

Invalid number of references

mr.engineer.aec
Advocate
Advocate

 Hi guys,

I try to create dimension from references planar face of Beam.

But i can't. Warning "Invalid number of references".

dimension References. Size = 4.
How can i solve this issue ?
 Thank in advanced.

Code:

 

var beamFaces = GetSolids(beamInstance)
                    .SelectMany(x => x.Faces.OfType<PlanarFace>())
                    .ToList();
                
                var verticalFace1 = beamFaces
                    .Where(x => x.ComputeNormal(UV.Zero).IsAlmostEqualTo(-1 * Doc.ActiveView.RightDirection)).ToList();
                var verticalFace2 = beamFaces
                    .Where(x => x.ComputeNormal(UV.Zero).IsAlmostEqualTo(1 * Doc.ActiveView.RightDirection)).ToList();

                foreach (PlanarFace pl in verticalFace1)
                {
                    dimensionReferences.Append(pl.Reference);
                }
                foreach (PlanarFace pl in verticalFace2)
                {
                    dimensionReferences.Append(pl.Reference);
                }
                //MessageBox.Show(dimensionReferences.Size.ToString(),"Test");
                XYZ pickpoint = UiDoc.Selection.PickPoint(ObjectSnapTypes.Points, "Pick point");

                Line dimensionLine = Line.CreateUnbound(pickpoint, Doc.ActiveView.RightDirection);
                using (Transaction transaction = new Transaction(Doc, "create dimension"))
                {
                    transaction.Start();

                    Doc.Create.NewDimension(Doc.ActiveView, dimensionLine, dimensionReferences);

                    transaction.Commit();
                }

 

 

 

0 Likes
1,120 Views
8 Replies
Replies (8)
Message 2 of 9

mr.engineer.aec
Advocate
Advocate

Picture
planarFace.jpg

0 Likes
Message 3 of 9

jeremytammik
Autodesk
Autodesk

Well, four seems like rather a lot.

 

Don't you just want two faces to define the dimension between them?

 

If so, you might want to filter your four faces further to determine which of the two you want to dimension and which two to ignore.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 4 of 9

mr.engineer.aec
Advocate
Advocate

 Hi Mr. @jeremytammik 

Thank for your reply my topic

I want to get all faces (4) to dimension.
Can Revit API retreive them ?
Many thanks for your reply.


0 Likes
Message 5 of 9

jeremytammik
Autodesk
Autodesk
Message 6 of 9

CJModis
Advocate
Advocate

The fact that you have 4 elements in the array does not mean that you have 4 reference in the array. Here in this line, null may well get into the array:

dimensionReferences.Append(pl.Reference);

Did you remember to specify the property ComputeReferences = true; when you received the geometry?

Message 7 of 9

mr.engineer.aec
Advocate
Advocate

Thank for your suggestions, Mr. @jeremytammik 

0 Likes
Message 8 of 9

mr.engineer.aec
Advocate
Advocate

 Hi @CJModis 
It is as you say. I have a problem about append Refferences to RefferenceArray.
Many thanks for your suggestion. 

0 Likes
Message 9 of 9

ryuzaki2005
Explorer
Explorer

i did nit try. But you can try like this :

string sam1 = planarFace.Reference.ConvertToStableRepresentation(Doc);

string Refer1 = sam1.Replace("SURFACE", "LINEAR");

Reference pl = Reference.ParseFromStableRepresentation(Doc, Refer1);

which each Reference. Because Reference of PlanarFace is REFERENCE_TYPE_SURFACE not REFERENCE_TYPE_NONE or _LINEAR.

 

0 Likes