Create a Midplane from 2 named faces

Create a Midplane from 2 named faces

mfoster9TD82
Advocate Advocate
459 Views
3 Replies
Message 1 of 4

Create a Midplane from 2 named faces

mfoster9TD82
Advocate
Advocate

I'm trying to make a midplane between 2 faces on an ipt that I have right clicked>assign name. I keep getting an error when adding a new plane. I've never used named faces before so let me know what I'm missing.

 

Thanks!

 

Sub ModelSub() 

' Set a reference to the active document. 
Dim oDoc As PartDocument 
Set oDoc = ThisApplication.ActiveDocument 

' Set a reference to the component definition. 
Dim oDef As PartComponentDefinition 
Set oDef = oDoc.ComponentDefinition 

'set named faces as objects 
Dim oObj(1) As Object 
Set oObj(0) = oDoc.AttributeManager.FindObjects("*", "*", "TOP") 
Set oObj(1) = oDoc.AttributeManager.FindObjects("*", "*", "BOTTOM") 

'create midplane
Dim oPlane As WorkPlane 
Set oPlane = oDef.WorkPlanes.AddByTwoPlanes(oObj(0), oObj(1)) 
End Sub

 

 

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

WCrihfield
Mentor
Mentor
Accepted solution

Hi @mfoster9TD82.  It looks to me like you are using VBA here, so I'll provide a VBA code as a possible solution.  Finding 'named' entities from a VBA macro requires more work and complication that finding them from an iLogic rule, but it can still be done a couple ways.  Since I don't know what version of Inventor you are using, I will stick to the older way of doing it, just to be sure (finding them by their attributes directly).  The AttributeSet.Name will be "iLogicEntityNameSet", and the Attribute.Name will be "iLogicEntityName", and the Attribute.ValueType will be 'kStringType', so the Attribute.Value will be a String (the name you gave the face).  Here is one way of finding them for your situation.  Since you mentioned that they were Face objects, I am not checking what type of objects they are ahead of time, and I am also not checking whether they are Planar faces, because I assume we don't need to in this case.

Sub ModelSub()
    ' Set a reference to the active document.
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    ' Set a reference to the component definition.
    Dim oDef As PartComponentDefinition
    Set oDef = oDoc.ComponentDefinition
    
    Dim oTopFace As Face
    Dim oBottomFace As Face
    Dim oSet1 As ObjectCollection
    Dim oSet2 As ObjectCollection
    Set oSet1 = oDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", "TOP")
    Set oSet2 = oDoc.AttributeManager.FindObjects("iLogicEntityNameSet", "iLogicEntityName", "BOTTOM")
    If oSet1.Count > 0 Then
        Set oTopFace = oSet1.Item(1)
    End If
    If oSet2.Count > 0 Then
        Set oBottomFace = oSet2.Item(1)
    End If
    
    'create midplane
    Dim oPlane As WorkPlane
    If oTopFace Is Nothing Or oBottomFace Is Nothing Then Exit Sub
    Set oPlane = oDef.WorkPlanes.AddByTwoPlanes(oTopFace, oBottomFace)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

mfoster9TD82
Advocate
Advocate
Thanks! This is exactly what I need. Out of curiosity, how is it different in iLogic?
0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

When they created the user interface for naming entities by right-clicking on them in the model screen and choosing 'Assign Name...' (Inventor 2019.1, I believe), they also added some really nice 'shortcut' iLogic snippets 'behind the scene' for us to be able to access those named entities in our iLogic rules.  It is an 'Interface' called 'NamedEntities'.  Technically, you can still access this from a VBA Macro, but it is very clunky and not recognized by the Object Browser, so you don't have any help, and just have to know what you are doing to make it work.  The quickest & simplest way to get this object from an iLogic rule is to use 'iLogicVb.Automation.GetNamedEntities(oDoc)', where oDoc is the variable representing the PartDocument in which those entities were named.  Here is one iLogic version of the VBA Macro I posted above.  As you can see, it is extremely condensed in comparison.  You can checkout additional information about them at the two links above.

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
oNE = iLogicVb.Automation.GetNamedEntities(oDoc)
Dim oTopFace As Face = oNE.TryGetEntity("TOP")
Dim oBottomFace As Face = oNE.TryGetEntity("BOTTOM")
If oTopFace Is Nothing Or oBottomFace Is Nothing Then Exit Sub
oPlane = oDoc.ComponentDefinition.WorkPlanes.AddByTwoPlanes(oTopFace, oBottomFace)

 

Before that, to name entities, we had use a more complicated process involving the Inventor API to add an Attribute to the selected entities, to set a name.  Then we had to use another similar process involving the Inventor API to find those entities, but we had to know the names of the AttributeSet, and Attribute, and the name that we assigned to the entity, to find them.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)