Hi @BlakeEZJTXL. I understand that you do not want to have to manually select the edges. You essentially want a way to assign names to specific entities (like a Face, Edge, or vertex), but without manually selecting it, then you want to be able to use that iLogic shortcut snippet to add a constraints between those named entities, by it simply recognizing those names you have assigned to them.
The problem is that none of us know your models, your preferences for naming, or which entities should be named what names, like you do. So one of us would not be able to write a complete working code solution for you to do this, exactly the way you would want, without knowing all that you know about those things. Generally, the first steps in these types of processes is usually that the same person who will be writing the code for creating the constraints by code, will be the one who manually selects, and manually assigns specific, meaningful names to the entities that they are interested in using for their specific constraints. Then they will know what names to specify within their code for the constraints.
One alternative would be to simply assign a relatively generic name to every entity in the model that can be assigned a name with that 'NamedEntities' system. Then just familiarize yourself with which names are assigned to which entities before writing the code for the constraints, so you know which names to specify. Below is one possible example iLogic rule that will attempt to assign a somewhat generic name to all those types of entities. But beware, this code solution was designed to be used either on a new model (no names assigned yet), or to clear all existing names, then rename all entities again, like a fresh start. Doing it this way eliminates the possibility of naming any one entity the same as any another entity, and avoids those potential errors. If it was not done this way, then more robust naming conventions (and the additional code to support their functionality) would be needed to ensure that any entities found without a name in a follow-up run, would not be named the same as any previous entity's name.
You will also notice that all of these entities are being assigned names without any manual selection involved, but that also means that specific entities may not be assigned the exact name that you may have wanted. These names can be changed manually later, if you wanted. You are likely already aware of this, but just in case, on the iLogic tab (where the Rules, Forms, Global Forms sub tabs are), a new sub tab will appear named 'Entities' after you have assigned names to entities using either that manual system, or this 'NamedEntities' system. When that 'Entities' tab is activated, you will see the list of named entities, and you can turn their 'tags' on or off from there, as well as rename them from there.
Sub Main
Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, Inventor.PartDocument)
If oPDoc Is Nothing Then Return
Dim oTrans As Inventor.Transaction
oTrans = ThisApplication.TransactionManager.StartTransaction(oPDoc, "Assign Name To All Faces, Edges, Vertices - iLogic")
AssignGenericNames(oPDoc)
oTrans.End
End Sub
Sub AssignGenericNames(oDoc As Inventor.Document)
If oDoc Is Nothing Then Return
If oDoc.IsModifiable = False Then
Logger.Debug("AssignGenericNames - Supplied Document Is Not Modifiable!")
Return
End If
If (Not TypeOf oDoc Is PartDocument) Then
Logger.Debug("AssignGenericNames - Supplied Document Is Not A PartDocument!")
Return
End If
Dim oPDoc As PartDocument = oDoc
Dim oBodies As SurfaceBodies = oPDoc.ComponentDefinition.SurfaceBodies
If oBodies.Count = 0 Then Return
Dim oNEs As NamedEntities = iLogicVb.Automation.GetNamedEntities(oPDoc)
'<<< CLEAR ALL EXISTING NAMES, IF ANY (to avoid reusing existing names) >>>
If oNEs.Entities IsNot Nothing AndAlso oNEs.Entities.Count > 0 Then
oNEs.Entities.Clear
End If
oDoc.Update2(True)
For Each oBody As SurfaceBody In oBodies
Dim sBodyName As String = oBody.Name
Dim oFaces As Faces = oBody.Faces
If oFaces.Count > 0 Then
Dim sFaceBaseName As String = sBodyName & "-Face"
Dim iFace As Integer = 0
For Each oFace As Face In oFaces
iFace = iFace + 1
Dim sNewFaceName As String = sFaceBaseName & iFace.ToString
Try
'this will fail if this name is already being used
oNEs.SetName(oFace, sNewFaceName)
Catch
Logger.Error("Error renaming Face to '" & sNewFaceName & "'!")
End Try
Next 'oFace
End If
Dim oEdges As Edges = oBody.Edges
If oEdges.Count > 0 Then
Dim sEdgeBaseName As String = sBodyName & "-Edge"
Dim iEdge As Integer = 0
For Each oEdge As Edge In oEdges
iEdge = iEdge + 1
Dim sNewEdgeName As String = sEdgeBaseName & iEdge.ToString
Try
'this will fail if this name is already being used
oNEs.SetName(oEdge, sNewEdgeName)
Catch
Logger.Error("Error renaming Edge to '" & sNewEdgeName & "'!")
End Try
Next 'oEdge
End If
Dim oVertices As Vertices = oBody.Vertices
If oVertices.Count > 0 Then
Dim sVertexBaseName As String = sBodyName & "-Vertex"
Dim iVertex As Integer = 0
For Each oVertex As Vertex In oVertices
iVertex = iVertex + 1
Dim sNewVertexName As String = sVertexBaseName & iVertex.ToString
Try
'this will fail if this name is already being used
oNEs.SetName(oVertex, sNewVertexName)
Catch
Logger.Error("Error renaming Vertex to '" & sNewVertexName & "'!")
End Try
Next 'oVertex
End If
Next 'oBody
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) 👍.
Wesley Crihfield

(Not an Autodesk Employee)