Define face

Define face

Anonymous
Not applicable
1,123 Views
3 Replies
Message 1 of 4

Define face

Anonymous
Not applicable

Is there a way to place some sort of marker (maybe a name) on a planar face to reference it in code. I want to reference a specific face but can't do it using the item number (see below) as the quantity of faces change.

 

Dim oFace As Face
oFace = oCompDef.SurfaceBodies.Item(1).Faces.Item(1)

 

Open to other suggestions also.

 

 

0 Likes
Accepted solutions (1)
1,124 Views
3 Replies
Replies (3)
Message 2 of 4

YuhanZhang
Autodesk
Autodesk
Accepted solution

There are two ways to get the Face object you need, you can choose which you like:

 

1. Use the Face.GetReferenceKey to get the reference-key for a Face, and then when you need to find the Face you can use the ReferenceKeyManager.BindKeyToObject  to retrieve the Face. Below VBA sample demonstrates how to use the reference key:

 

Public Sub CreateReferenceKey()
    'Set a reference to the active document
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument

    Dim refKeyMgr As ReferenceKeyManager
    Set refKeyMgr = oDoc.ReferenceKeyManager

    ' Create a key context (required to obtain ref keys for BRep entities)
    Dim keyContext As Long
    keyContext = refKeyMgr.CreateKeyContext
    
    Dim keyCollection As New Collection
    Dim oFace As Face
    
    For Each oFace In oDoc.ComponentDefinition.SurfaceBodies(1).Faces

        ' Get a reference key
        Dim refKey() As Byte
        Call oFace.GetReferenceKey(refKey, keyContext)
        
        ' Store all the ref keys
        keyCollection.Add refKey
    Next
    
    ' Save KeyContext as a byte array for future use
    Dim ContextData() As Byte
    Call oDoc.ReferenceKeyManager.SaveContextToArray(keyContext, ContextData)
    
    ' Load the saved KeyContext 
    Dim savedKeyContext As Long
    savedKeyContext = oDoc.ReferenceKeyManager.LoadContextFromArray(ContextData)
    
    Dim tempKey As Variant, key() As Byte, retObj As Object
    ' Bind back the objects
    For Each tempKey In keyCollection
        key = tempKey
        Set retObj = oDoc.ReferenceKeyManager.BindKeyToObject(key, savedKeyContext)
        oDoc.SelectSet.Select retObj
    Next
End Sub

 

2. Add attribute to a Face and then you can retrieve it using the AttributeManager.FindObjects. You can add a special value(GUID or other unique value) to the attribute so you can retrieve the unique Face.

 

Hope the above helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 4

Anonymous
Not applicable

Perfect! went with adding an attribute to the face. Thanks for your help.

0 Likes
Message 4 of 4

Anonymous
Not applicable

Hi! I am having the problem with the planar face to create a pipe connector. I am using Revit Python Shell for this.

my code:

 

ConnectorElement.CreatePipeConnector(doc, DomesticColdWater, planar face)

 

How can I get the planar face? I need to create a connector next to the pipe. Or how can I extract the face from the pipe? Thank you!

0 Likes