Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get slot face by selecting an edge

2 REPLIES 2
Reply
Message 1 of 3
dlunaEVTVX
207 Views, 2 Replies

Get slot face by selecting an edge

dlunaEVTVX
Participant
Participant

I want to select the planar face of a slot by selecting one of its non-circular edges.

dlunaEVTVX_0-1691516686332.png

 

This is the code I am using, this selects an edge and evaluates which one of all the faces in the part is normal to that edge. Then I can filter to check which one of the normal faces contains that specific edge (which I haven't coded in this example yet).

Dim oEdge As Edge
Dim oFace As Face
Dim FaceParams(3) As Double
Dim FaceNormals(2) As Double
Dim oUnitNormal As UnitVector = Nothing
oTransGeom = ThisApplication.TransientGeometry
oEdge = ThisApplication.CommandManager.Pick(kPartEdgeFilter, "Select the slot")

For i = 1 To oEdge.Parent.Faces.Count
	oFace = oEdge.Parent.Faces(i)
	oFace.Evaluator.GetNormal(FaceParams, FaceNormals)
	oUnitNormal = ThisApplication.TransientGeometry.CreateUnitVector(FaceNormals(0), FaceNormals(1), FaceNormals(2))
	MsgBox("Face X: " & oUnitNormal.X _
	& vbLf & "Face Y: " & oUnitNormal.Y _
	& vbLf & "Face Z: " & oUnitNormal.Z)
Next i

 

The problem is that there are two faces that contain that edge and are also normal to it.

dlunaEVTVX_1-1691517990244.png

 

How can I filter to get that slot internal face and not the external one?
Thank you in advance


 

0 Likes

Get slot face by selecting an edge

I want to select the planar face of a slot by selecting one of its non-circular edges.

dlunaEVTVX_0-1691516686332.png

 

This is the code I am using, this selects an edge and evaluates which one of all the faces in the part is normal to that edge. Then I can filter to check which one of the normal faces contains that specific edge (which I haven't coded in this example yet).

Dim oEdge As Edge
Dim oFace As Face
Dim FaceParams(3) As Double
Dim FaceNormals(2) As Double
Dim oUnitNormal As UnitVector = Nothing
oTransGeom = ThisApplication.TransientGeometry
oEdge = ThisApplication.CommandManager.Pick(kPartEdgeFilter, "Select the slot")

For i = 1 To oEdge.Parent.Faces.Count
	oFace = oEdge.Parent.Faces(i)
	oFace.Evaluator.GetNormal(FaceParams, FaceNormals)
	oUnitNormal = ThisApplication.TransientGeometry.CreateUnitVector(FaceNormals(0), FaceNormals(1), FaceNormals(2))
	MsgBox("Face X: " & oUnitNormal.X _
	& vbLf & "Face Y: " & oUnitNormal.Y _
	& vbLf & "Face Z: " & oUnitNormal.Z)
Next i

 

The problem is that there are two faces that contain that edge and are also normal to it.

dlunaEVTVX_1-1691517990244.png

 

How can I filter to get that slot internal face and not the external one?
Thank you in advance


 

2 REPLIES 2
Message 2 of 3
WCrihfield
in reply to: dlunaEVTVX

WCrihfield
Mentor
Mentor

This is just a conceptual thought, but if the Edge belongs to an ExtrudeFeature, you could find the ExtrudeFeature that it belongs to by looping through all the ExtrudeFeatures, looping the ExtrudeFeature.SideFaces collection, and checking their Edges against the one you selected (using 'Is', not '=') and when you find a match, you will also have the feature's side face.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

This is just a conceptual thought, but if the Edge belongs to an ExtrudeFeature, you could find the ExtrudeFeature that it belongs to by looping through all the ExtrudeFeatures, looping the ExtrudeFeature.SideFaces collection, and checking their Edges against the one you selected (using 'Is', not '=') and when you find a match, you will also have the feature's side face.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3
Michael.Navara
in reply to: dlunaEVTVX

Michael.Navara
Advisor
Advisor

I don't understand which face you want to get from the edge, but you can try this code sample

 

Dim part As PartDocument = ThisDoc.Document

'Select an edge
Dim edge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeLinearFilter, "Select edge")

'Iterate faces which belongs to the edge
For Each connectedFace As Face In edge.Faces
	'Slot feature has exactly 4 tangentially connected faces
	If connectedFace.TangentiallyConnectedFaces.Count <> 3 Then Continue For

	'Slot feature has exactly 2 planar faces and 2 cylinder faces
	'Variable connectedFace is one of the planar faces
	Dim planarFacesCount As Integer
	Dim cylinderFacesCount As Integer
	For Each tangentFace As Face In connectedFace.TangentiallyConnectedFaces
		If tangentFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then cylinderFacesCount += 1
		If tangentFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then planarFacesCount += 1
	Next

	'Check tangentially connecte faces count by its type
	If planarFacesCount = 1 And cylinderFacesCount = 2 Then
		'Variable connectedFace is candidate for slot feature
		part.SelectSet.Select(connectedFace)
		Return
	End If
Next

MsgBox("This is not a slot feature edge")

 

I don't understand which face you want to get from the edge, but you can try this code sample

 

Dim part As PartDocument = ThisDoc.Document

'Select an edge
Dim edge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeLinearFilter, "Select edge")

'Iterate faces which belongs to the edge
For Each connectedFace As Face In edge.Faces
	'Slot feature has exactly 4 tangentially connected faces
	If connectedFace.TangentiallyConnectedFaces.Count <> 3 Then Continue For

	'Slot feature has exactly 2 planar faces and 2 cylinder faces
	'Variable connectedFace is one of the planar faces
	Dim planarFacesCount As Integer
	Dim cylinderFacesCount As Integer
	For Each tangentFace As Face In connectedFace.TangentiallyConnectedFaces
		If tangentFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then cylinderFacesCount += 1
		If tangentFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then planarFacesCount += 1
	Next

	'Check tangentially connecte faces count by its type
	If planarFacesCount = 1 And cylinderFacesCount = 2 Then
		'Variable connectedFace is candidate for slot feature
		part.SelectSet.Select(connectedFace)
		Return
	End If
Next

MsgBox("This is not a slot feature edge")

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report