Reference of a Wall Face

Reference of a Wall Face

Anonymous
Not applicable
1,624 Views
9 Replies
Message 1 of 10

Reference of a Wall Face

Anonymous
Not applicable

Hi there,

After extracting a Face Class object from a wall, it seems that the reference property of a Face returns null.

Actually I am trying to use the resulting Reference in creating a DivisionSurface Class object. Isn't it possible?

 

FR=Face.Reference
DivSur=DB.DividedSurface.Create(doc, FR)

0 Likes
1,625 Views
9 Replies
Replies (9)
Message 2 of 10

jeremytammik
Autodesk
Autodesk

To access the wall face, I assume that you call the wall's Geometry property:

 

https://www.revitapidocs.com/2020/d8a55a5b-2a69-d5ab-3e1f-6cf1ee43c8ec.htm

 

In doing so, you need to supply Options. In the options you provide, you need to specify ComputeReferences = true:

 

https://www.revitapidocs.com/2020/d7da6de4-74a9-60e2-826f-698a5730d0a8.htm

 

Determines whether or not references to geometric objects are computed.
 


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

0 Likes
Message 3 of 10

Anonymous
Not applicable

Hi thanks

Actually I have set the ComputeReferences to True, yet, it still does not work. A window pops upon executing the command. It asks me to delete the element and once I let it delete another window pops up. Screenshots are attached.

 

 

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;
            Reference pickObj = uidoc.Selection.PickObject(ObjectType.Element);

            try
            {
                if (pickObj != null)
                {
                    Options opt = new Options();
                    opt.ComputeReferences = true;
                    ElementId elemid = pickObj.ElementId;
                    Element elemt = doc.GetElement(elemid);
                    GeometryElement geo = elemt.get_Geometry(opt);
                    foreach (Solid sol in geo)
                    {
                        Solid geSolid = sol as Solid;
                        FaceArray fcA = geSolid.Faces;
                        foreach(Face f in fcA)
                        {
                            Transaction trans = new Transaction(doc, "DivideSurface");
                            trans.Start();
                            Reference fr = f.Reference;
                            DividedSurface ds = DividedSurface.Create(doc, fr);
                            trans.Commit();
                            
                        }
                    }


                }
                return Result.Succeeded;
            }
            catch(Exception e)
            {
                message = e.Message;
                return Result.Failed;
            }
        }

 

 

0 Likes
Message 4 of 10

jeremytammik
Autodesk
Autodesk

You code is very badly structured.

 

Refactor it.

 

  • First, pick your element.
  • Secondly, iterate over the geometry and extract the data you need, e.g., references.
  • Third, start a transaction and do the job

 

These three steps can and should be cleanly separated!

 



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

0 Likes
Message 5 of 10

zhongding_cui
Contributor
Contributor

Encountering similar problem where the

face.Reference == null

despite the: 

opt.ComputeReferences = true;

when capturing the face from the GeometryElement. The Face I am working with is a valid HermiteFace. 

 

Is this a known bug? Can we ask for a bug fix ticket on it?

0 Likes
Message 6 of 10

zhongding_cui
Contributor
Contributor

When defining the option, I tried:

 

Options opt = new Options();

 

Also tried:

 

Options opt2 = app.Application.Create.NewGeometryOptions();

 

Neither of them returns a valid reference for the HermiteFace inside of 

GeometryElement geo = elemt.get_Geometry(opt);

 

Are we missing something other than the ComputeReference = true setting?

0 Likes
Message 7 of 10

Moustafa_K
Collaborator
Collaborator

you need to set computeReferences to True

 

not sure if this post would also be in a help in your case

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 8 of 10

jeremy_tammik
Alumni
Alumni

HermiteFace... interesting. What do you want the reference for? Dimensioning? If so, can you create the dimensioning you have in mind manually through the end user interface? Maybe there are limitations on references to HermiteFace objects. Maybe there is something else less complex and more stable in your model geometry that you can use as a reference instead.

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 9 of 10

zhongding_cui
Contributor
Contributor

@jeremy_tammik wrote:

Maybe there are limitations on references to HermiteFace objects. 

   


Yeah this is exactly what I am trying to figure out by posting here. We are trying to use Revit on some unconventional projects, so the use of HermiteFace is inevitable. 

Any further suggestions Jeremy? Thanks a lot. 

0 Likes
Message 10 of 10

jeremy_tammik
Alumni
Alumni

Yes, definitely. This forum is for discussing programming issues. The API is more or less a wrapper around the UI functionality. To discuss unconventional projects, I recommend solving all questions manually through the end user interface first, before trying to address them programmatically. The best place to discuss optimal workflow and best practice issues in the UI is generally the larger and more generic architectural forum.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes