Getting Point Details through face proxy - VBA

Getting Point Details through face proxy - VBA

gopinathmY575P
Advocate Advocate
363 Views
7 Replies
Message 1 of 8

Getting Point Details through face proxy - VBA

gopinathmY575P
Advocate
Advocate

I'm selecting part's face in assembly environment through vba, after selecting face. I want to get the centre of the slot

 

If fac.Edges.count = 2 Then 'consider as hole

Set holeCenter2 = assyDoc.ComponentDefinition.WorkPoints.AddFixed(fac.Edges.item(1).Geometry.Center, True)

ElseIf fac.Edges.count = 4 Then 'consider as slot hole
Dim pt1 As Point

Set pt1 = fac.Edges.item(1).Geometry.Center

Set holeCenter2 = assyDoc.ComponentDefinition.WorkPoints.AddFixed(pt1, True)   (here point A , i'm getting, but i want to get Point B as shown in image ) 

End If

 

 

gopinathmY575P_0-1750832297467.png

 

0 Likes
364 Views
7 Replies
Replies (7)
Message 2 of 8

tim11_manhhieu
Advocate
Advocate

B point is midpoint of AA', i think you need to pick two faces, face for point A and face for point A'.

 

tim11_manhhieu_1-1750835871016.png

 

0 Likes
Message 3 of 8

gopinathmY575P
Advocate
Advocate

in ideal case, I will pick always one face only (for both hole features and slot hole features). may be fac.createdbyfeature will help... from that i can able to access that B point i'm thinking of that.

0 Likes
Message 4 of 8

tim11_manhhieu
Advocate
Advocate

Because the slot hole has an additional variable of hole length,

I think it is impossible to distinguish between a regular hole and a slot hole from just one face.

In fact, if you want to draw a slot hole, you also need to have the length of both ends of the hole.

0 Likes
Message 5 of 8

gopinathmY575P
Advocate
Advocate

edge's count value is 2 for normal clearance hole whereas 4 for slotted hole

0 Likes
Message 6 of 8

tim11_manhhieu
Advocate
Advocate

you was right, but not enough data to find the desired point B position.

Because the position of point B will depend on the position of the other end of the slot hole.

 

I think the sequence should be like this,

1) pick any 1 face

2) if that face is a regular hole face then do something
if that face is a slot hole face then pick the face of the other end.

0 Likes
Message 7 of 8

gopinathmY575P
Advocate
Advocate

okie tim11 as of now i will consider this as last option.. If i get any other workaround method..  i will update you here..

 

 

0 Likes
Message 8 of 8

WCrihfield
Mentor
Mentor

If the hole or slot was created as a single feature, and not just one of many in a single feature, then there is another route that you could consider for finding the center point of the slot.  I have seen (and likely participated in) multiple other forum discussions about similar goals in the past, and after searching within my custom iLogic snippets, I found an iLogic rule example in there which is related to this.  I do not recall what other forum discussion this may be from, or if I authored some or all of it or not, but I will post the code here anyways, just as added reference and ideas.  The code asks the user to select the 'feature' right up front (not just an Edge or Face), then starts digging into its geometry to identify it as a slot.  Once that is determined, it uses the 'profile' edges to get their 'centroid', which would be at the center of the slot.  Then it creates a WorkPoint at its top, and bottom center points.  Then it creates a WorkAxis which passes through those WorkPoints.  Then it extrudes a cylindrical surface around that center axis.  I don't recall why all the work features and surface were used, but it may have been an 'alignment' project, where they will later be aligned with holes in another part in an assembly.

Sub Main
	Dim oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFeatureFilter, "Select an Extrude Cut Slot.")
	If oObj Is Nothing OrElse (TypeOf oObj Is Inventor.ExtrudeFeature = False) Then Exit Sub
	Dim oExtFeat As ExtrudeFeature = oObj
	Dim oExtDef As ExtrudeDefinition = oExtFeat.Definition
	If Not oExtDef.Operation = PartFeatureOperationEnum.kCutOperation Then
		MsgBox("This is not a 'Cut' operation.  Exiting code.", , "")
		Exit Sub
	End If
	Dim oProfile As Inventor.Profile = oExtDef.Profile
	Dim oEdges1, oEdges2 As EdgeCollection
	Dim oSideFace As Face = oExtFeat.SideFaces.Item(1)
	For Each oEdge As Edge In oSideFace.Edges
		If oEdge.TangentiallyConnectedEdges.Count = 4 Then
			If oEdges1 Is Nothing OrElse oEdges1.Count = 0 Then
				oEdges1 = oEdge.TangentiallyConnectedEdges
			Else
				oEdges2 = oEdge.TangentiallyConnectedEdges
			End If
		End If
	Next 'oEdge
	Dim oCDef As ComponentDefinition = oExtFeat.Parent
	Dim oWPts As WorkPoints = oCDef.WorkPoints
	Dim oWPt1 As WorkPoint = oWPts.AddAtCentroid(oEdges1)
	oWPt1.Visible = False
	'oWPt1.Name = oExtFeat.Name & " Profile Center 1"
	Dim oWPt2 As WorkPoint = oWPts.AddAtCentroid(oEdges2)
	oWPt2.Visible = False
	'oWPt2.Name = oExtFeat.Name & " Profile Center 2"
	Dim oWAs As WorkAxes = oCDef.WorkAxes
	Dim oWA As WorkAxis = oWAs.AddByTwoPoints(oWPt1, oWPt2)
	oWA.AutoResize = False
	oWA.SetSize(oWPt1.Point, oWPt2.Point)
	'oWA.Name = oExtFeat.Name & " Center Axis"
	
	'now create an extruded cylinder surface around the center axis that is 5mm dia.
	Dim oWPlanes As WorkPlanes = oCDef.WorkPlanes
	Dim oSketchPlane As WorkPlane = oWPlanes.AddByNormalToCurve(oWA, oWPt1)
	Dim oToPlane As WorkPlane = oWPlanes.AddByNormalToCurve(oWA, oWPt2)
	Dim oCylinderSketch As PlanarSketch = oCDef.Sketches.Add(oSketchPlane, False)
	Dim oCenter As SketchPoint = oCylinderSketch.AddByProjectingEntity(oWPt1)
	Dim oCircle As SketchCircle = oCylinderSketch.SketchCircles.AddByCenterRadius(oCenter, .5) 'understood as centimeters
	Dim oCylProfile As Inventor.Profile = oCylinderSketch.Profiles.AddForSurface()
	Dim oExtFeats As ExtrudeFeatures = oCDef.Features.ExtrudeFeatures
	Dim oCylExtDef As ExtrudeDefinition = oExtFeats.CreateExtrudeDefinition(oCylProfile, PartFeatureOperationEnum.kSurfaceOperation)
	oCylExtDef.SetFromToExtent(oSketchPlane, False, oToPlane, False)
	Dim oCylExt As ExtrudeFeature = oExtFeats.Add(oCylExtDef)
	oSketchPlane.Visible = False : oToPlane.Visible = False
	'now update the document
	Dim oDoc As Document = oCDef.Document
	oDoc.Update
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)