Projecting edges of a face if parallel to a plane

Projecting edges of a face if parallel to a plane

llorden4
Collaborator Collaborator
1,148 Views
3 Replies
Message 1 of 4

Projecting edges of a face if parallel to a plane

llorden4
Collaborator
Collaborator

I'm close to a solution here but it's kicking my butt.  I have a workplane that is on face and I need to project the edges of that face onto my sketch plane.  I'm nearly there on this path, but am coming up just short of my desire.   Maybe you know the solution or a better path, if you're willing to share I'm eager for a solution on this.

 

'current code

oWorkPlane = oCompDef.WorkPlanes.Item("FACE Plane")
oSketch = oCompDef.Sketches.Add(oWorkPlane)
 oSketch.Name = "LP Sketch"
oSurfaceBody = oCompDef.SurfaceBodies.Item(1)
For i = 1 To oSurfaceBody.Faces.Count
	oFace = oSurfaceBody.Faces.Item(i)
	If oWorkPlane.Plane.DistanceTo(oFace.GetClosestPointTo(oWorkPlane.Plane.RootPoint)) = 0 And oWorkPlane.Plane.IsParallelTo(oFace) Then  'This fails to find the parallel feature
		For j = 1 To oFace.Edges.Count
			oSketch.AddByProjectingEntity(oFace.Edges.Item(j))
		Next
	End If
Next

 [The plane & adjacent face I'm trying to project ]

llorden4_0-1619131630560.png

 

Autodesk Inventor Certified Professional
0 Likes
Accepted solutions (1)
1,149 Views
3 Replies
Replies (3)
Message 2 of 4

nmunro
Collaborator
Collaborator

You are on the right track. You must make sure the face you are comparing is planar (sketch creation), and you have to get the geometry of the planar face for use when comparing with the Plane generated from the work plane. The attached part contains a VBA macro with complete code, which is also pasted below.

 

 

Public Sub CreateSketch()

    Dim doc As PartDocument
    Set doc = ThisDocument
    
    Dim compDef As PartComponentDefinition
    Set compDef = doc.ComponentDefinition
    
    Dim workFeatPlane As workPlane
    Set workFeatPlane = compDef.WorkPlanes.Item("FACE Plane")
    
    Dim oSketch As PlanarSketch
    Set oSketch = compDef.Sketches.Add(workFeatPlane)
     oSketch.Name = "LP Sketch"
     
    Dim surfBody As SurfaceBody
    Set surfBody = compDef.SurfaceBodies.Item(1)
    
    Dim i, j As Integer
    Dim face As face
    Dim wpPlane As Plane
    Set wpPlane = workFeatPlane.Plane
    Dim facePlane As Plane
    'Dim rootPoint As Point
    'Set rootPoint = wpPlane.rootPoint
    
    For i = 1 To surfBody.Faces.Count
        Set face = surfBody.Faces.Item(i)
        'must be planar surface to create sketch so check surface type
        If face.SurfaceType = kPlaneSurface Then
            'must get the underlying plane geometry of the face
            Set facePlane = face.Geometry
            'replaced distance and isparallet with IsCoplanarTo method (negates need for rootPoint variable)
            'If wpPlane.DistanceTo(face.GetClosestPointTo(rootPoint)) < 0.000001 And wpPlane.IsParallelTo(facePlane) Then
            'could optionally use and is more compact
            If wpPlane.IsCoplanarTo(facePlane) Then
                For j = 1 To face.Edges.Count
                    Call oSketch.AddByProjectingEntity(face.Edges.Item(j))
                Next
            End If
        End If
    Next

End Sub

 

        


https://c3mcad.com

Message 3 of 4

J-Camper
Advisor
Advisor
Accepted solution

@llorden4,

 

Here is a straight iLogic example:

Dim oCompDef As PartComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
Dim oWorkPlane As WorkPlane = oCompDef.WorkPlanes.Item("FACE Plane")
Dim oSketch As PlanarSketch = oCompDef.Sketches.Add(oWorkPlane)

Try
	oSketch.Name = "LP Sketch"
Catch
	Logger.Trace("Sketch name: LP Sketch : already exists")
End Try
 
Dim oSurfaceBody As SurfaceBody = oCompDef.SurfaceBodies.Item(1)
For Each f As Face In oSurfaceBody.Faces
    If f.SurfaceType <> SurfaceTypeEnum.kPlaneSurface Then Continue For
    If oWorkPlane.Plane.IsCoplanarTo(f.Geometry) 
        For Each ed As Edge In f.Edges
			oSketch.AddByProjectingEntity(ed)
		Next
		Exit For 'As we have found the face we want
    End If
Next

 

Message 4 of 4

llorden4
Collaborator
Collaborator

Thanks to you both for your input.  A bit of playing to discover JCamper's suggestion handled a condition I was running into, that I first had to ensure the face was a Plane Surface before performing ANY other evaluations as they resulted in a .COM error if I tried to pair the condition with an AND  in one conditional check statement.  Making that a stand alone check was the key element I was missing.  My final code segment for anyone interested...

oWorkPlane = oCompDef.WorkPlanes.Item("FACE Plane")
oSketch = oCompDef.Sketches.Add(oWorkPlane)
 oSketch.Name = "LP Sketch"
oSurfaceBody = oCompDef.SurfaceBodies.Item(1)
For i = 1 To oSurfaceBody.Faces.Count
	oFace = oSurfaceBody.Faces.Item(i)
	If oFace.SurfaceType.Equals(kPlaneSurface) Then	'Ensure the face is a plane surface else other evaluators cause a .COM error
		If oWorkPlane.Plane.IsCoplanarTo(oFace.Geometry) Then
			For j = 1 To oFace.Edges.Count
				oSketch.AddByProjectingEntity(oFace.Edges.Item(j))
			Next
		End If
	End If
Next
Autodesk Inventor Certified Professional
0 Likes