Placing a Family Instance on a face of an element

Placing a Family Instance on a face of an element

Anonymous
Not applicable
511 Views
3 Replies
Message 1 of 4

Placing a Family Instance on a face of an element

Anonymous
Not applicable

Hi All,

I am currently trying to write a very simple code to place a face-based void on the face of an element (in the family environment - no in a project), it seems pretty simple and straight forward but still have so much trouble doing that:

1. I am selecting the face of the element by:

face = PickObject(ObjectType.Face)

2. I am trying to place the family by using this method which requires "face" and not "reference" : 

familyInst = doc.FamilyCreate.NewFamilyInstance(face, location, direction, familysymbol)

it gives me this error: requires "face", got "reference"

3. So I checked the PickObject method and it seems that the returned object is a reference. Now I am trying to retrieve the "face" itself from the "reference" by:

id = face.ElementId
element = doc.GetElement(id)

4. When I run the program it gives me this error:

expected "face", got "form"

5. So now it seems that the doc.GetElement() gives me the solid object which contains that face! but I want the face itself!

Any help is much appreciated.

0 Likes
512 Views
3 Replies
Replies (3)
Message 2 of 4

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

I think pickobject method helps you to select the whole element.

In pickobject , object type helps you to select the element based on face or edge or element.

The point here is it helps you to select the whole element and when you try to get the element from the Reference.ElementId, an element is returned not the face.

To get the face from the element try using the below code

Reference R = uidoc.Selection.PickObject(ObjectType.Face);
                   ElementId eid = R.ElementId;
                   GeometryObject GO = doc.GetElement(R).GetGeometryObjectFromReference(R);
                   PlanarFace PF = GO as PlanarFace;

I am looking forward to your reply.

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 4

Anonymous
Not applicable

Hi Naveen,

Thanks for the response. I appreciate it.

I tried to implement the code that you wrote for me. Well, I needed to do a couple of extra things like setting Compute References to True and you know the rest... The problem was that when I tried to run the code, an error popped up saying: "if you are trying to access geometry, set the ComputeReference to True" !

So Instead of using the face itself, I decided to use reference by using ref = PlanarFace.Reference,

This one gave me this error: "ref is null" !

 

I think all of this happened because I failed to set "ComputeReferences to True" correctly! And I really don't know how to do that for this line of code:

GeometryObject GO = doc.GetElement(R).GetGeometryObjectFromReference(R)

I tried to write something like this but didn't work:

opt = Options()

opt.ComputeReferences = True

GO = doc.GetElement(r).GetGeometryObjectFromReference(r).get_Geometry(opt)

 

I would be grateful if you can help me solve the above issue.

 

Anyway, the code below works fine (it is in Python):

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document

symbName = 'Void'
familyid_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).OfClass(
FamilySymbol).ToElementIds()


ref = uidoc.Selection.PickObject(ObjectType.Face, "Please pick a face")


t = Transaction(doc, "F")
t.Start()

 

for id in familyid_collector:
f_id = id
f_symb = doc.GetElement(f_id)
if f_symb.Family.Name == symbName:
familyInst = doc.FamilyCreate.NewFamilyInstance(ref, XYZ(0,0,0), XYZ(0,0,0), f_symb)


t.Commit()

 

 

 

0 Likes
Message 4 of 4

BenoitE&A
Collaborator
Collaborator

Classical topic, which you could solve by typing "ComputeReference" in the forum.

Use this (I believe inside your transaction).

Options opt = app.Create.NewGeometryOptions();

    opt.ComputeReferences = true;

 

 


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes