What's new

Can you get the faces that an edge connects?

albie0803

Alibre Super User
face.GetEdges() works but is there a way to do the opposite?
edge.GetFaces() is what I want to achieve.
 

bolsover

Senior Member
I can't see any easy way to GetFaces from an edge using AlibreScript API. It is easy using the AlibreX API.

You might solve by using Part.GetFaces and then iterating through the resultant list calling face.GetEdges and look to see if this list contains the edge of interest - but long winded!

Pseudocode..

Part part
Edge edge
List edgeFaces = new List()

List faces = part.GetFaces

for (Face face to faces)
List edges = face.GetEdges
for (Edge e to edges)
if e == edge
edgeFaces.Add(face)
endif
endfor
endfor

I could do in C# - I think you can call C# routines from Python..

David
 
Last edited:

NateLiquidGravity

Alibre Super User
As David says Faces is right there on an Edge using the Alibre Design API.
I couldn't resist. Here is some undocumented things AlibreScript can do:
Python:
def FacesFromEdge(thisEdge):
    AD_edge = thisEdge.SelectableObject() # get an Alibre Design API edge object from the AlibreScript edge Object
    AD_faces = AD_edge.Faces # get the faces
    theseFaces = [] # empty list
    for x in range(0, AD_faces.Count): # loop thru faces
        thisFace = Face(AD_faces.Item(x)) # get an AlibreScript face Object from the Alibre Design API face object
        theseFaces.append(thisFace) # add to the list
    return theseFaces # return the list


assem = CurrentAssembly()
prt = assem.GetPart('New Part (1)<1>')
myEdge = prt.GetEdge('Edge<1>')
myEdgefaces = FacesFromEdge(myEdge)
for myFace in myEdgefaces:
    print(myFace)

Or you could do it in AlibreScript by looping all faces looking for the edge.
 

idslk

Alibre Super User
I couldn't resist.
me too :) . "jumping" between API and AlibreScript should enable it...
So i got to the following:
Python:
options = []
values = []
options.append(['Select edge:', WindowsInputTypes.Edge, None]) # 0
values = Windows().OptionsDialog('Select an Edge', options, 180)
if values == None:
  print 'Canceled'
  sys.exit()

#print dir(values[0]),("\n")#prints a list of all attributes and methods of the selected edge object...

mySelectedEdge = values[0].SelectableObject()
myEdgeFaces =  mySelectedEdge.Faces
for x in range(myEdgeFaces.Count):
  print Face(myEdgeFaces.Item(x)).Name
runs in parts as well in assemblies...
Regards
Stefan
 

NateLiquidGravity

Alibre Super User
me too :) . "jumping" between API and AlibreScript should enable it...
So i got to the following:
Python:
options = []
values = []
options.append(['Select edge:', WindowsInputTypes.Edge, None]) # 0
values = Windows().OptionsDialog('Select an Edge', options, 180)
if values == None:
  print 'Canceled'
  sys.exit()

#print dir(values[0]),("\n")#prints a list of all attributes and methods of the selected edge object...

mySelectedEdge = values[0].SelectableObject()
myEdgeFaces =  mySelectedEdge.Faces
for x in range(myEdgeFaces.Count):
  print Face(myEdgeFaces.Item(x)).Name
runs in parts as well in assemblies...
Regards
Stefan
My function does the same thing and works for assemblies and parts too. Everything outside the function was just an example usage.
 

albie0803

Alibre Super User
Thanks for the coding, I really appreciate it.
All this is for trying to simplify and reduce the number of clicks needed in my script for inserting fastener subassemblies into unpatternable hole groups.
As I will always get 2 faces for an edge, I can get the face that has more than 2 edges, which should be my flat face.

Time for some more ruminating.

Sadly, measuring the distance between faces of different parts is not implemented and the add fastener constraint seems to be broken (in script).
It works for a zero gap constraint, but the offset option doesn't work and the limit option allows numbers that doing it manually does not. Support is looking into this one. See my separate post about this if you are interested.
 

NateLiquidGravity

Alibre Super User
These two sample scripts might have some things you could use. They are found in the examples in the Alibre Script Library but I linked their help articles as well.

They actually use the long way to get faces from an edge by looping every face - Simple for simple models but potentially a long process if lots of faces.
Python:
def GetFacesFromEdge(Prt, Ege):
  Faces = []
  PartEdge = [[Ege.Vertices[0].X, Ege.Vertices[0].Y, Ege.Vertices[0].Z], [Ege.Vertices[1].X, Ege.Vertices[1].Y, Ege.Vertices[1].Z]]
  for Fce in Prt.Faces:
    for Edg in Fce.GetEdges():
      EdgeVertices = Edg.GetVertices()
      V1 = [EdgeVertices[0].X, EdgeVertices[0].Y, EdgeVertices[0].Z]
      V2 = [EdgeVertices[1].X, EdgeVertices[1].Y, EdgeVertices[1].Z]
      if ((PointsAreEqual(V1, PartEdge[0]) and PointsAreEqual(V2, PartEdge[1])) or
          (PointsAreEqual(V2, PartEdge[0]) and PointsAreEqual(V1, PartEdge[1]))):
         Faces.append(Fce)
  return Faces

Also in there are functions for dealing with multiple parts and shared edges. Potentially you could climb your way thru all parts by going something like this:
Part1 edge matching diameter on flat face -> Part1 get other Face -> Part1 get other edge (still matching diameter)-> Find a Part2 with a shared edge (still matching diameter) -> Part2 get other face -> Part2 get other edge (still matching diameter) ->... and so on. Also a long process. Or let user decide length.
 

idslk

Alibre Super User
Sadly, measuring the distance between faces of different parts is not implemented
have you tried it recently?
Python:
win = Windows()
ca = CurrentAssembly()
options = []
values = []
options.append(['Select face 1' , WindowsInputTypes.Face , None])
options.append(['Select face 2' , WindowsInputTypes.Face , None])
values = win.OptionsDialog( 'Select Faces to measure distance', options , 250 )
if values == None:
  sys.exit('Script Aborted')
if values[0].IsParallel(values[1]):
  win.InfoDialog("Distance is: "+str(values[0].DistanceTo(values[1])),"Measurement Info")
else:
  win.InfoDialog("Faces are not parallel...","Measurement Info")

Regards
Stefan
 

albie0803

Alibre Super User
Nice, thanks! I wish we were notified of all script function fixes and additions with each release.

Now all I need is the Offset function in the Fastener constraint to be repaired and one of my other ideas for fastener sets into unpatternable hole sets will work.

I was working on inserting fastener sets item by item, each additional item offset by the thickness of the previous one.
Select a washer and a hole set.
Auto place a washer on each hole
Select a bolt and the washer
determine the the offset for the bolt from the distance between the original hole surface and the new washer surface.
auto place a bolt on each hole offset to sit correctly.

rerun for washer and nut on the other side of required.
 
Last edited:
Top