Sketch orientation - align with selected face
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey
Im adding a sketch by doing the following-
select edge
add plane (normal to edge)
add workpoint
add sketch to plane on workpoint
add sketch lines to sketch at defined size (.75 x .25)
add constraints to sketch lines
problem im having is the orientation of the sketch. sometimes it correct, sometimes its not. I think id like to select a defining face first to set the direction of the sketch but im struggling to do that.
in the picture above, sketch (A) is how i need to be every time. Id like to select a face, align the sketch as shown and then it always orients this direction. Sketch (B) is rotated 90 degrees but needs to align with the selected face.
The pink lines i added to show the edges that i selected.
Is there a way to orient a sketch based on a selected face? here is my code:
Sub Rebate()
Dim oApp As Inventor.Application: Set oApp = ThisApplication
Dim oPartDoc As PartDocument: Set oPartDoc = oApp.ActiveDocument
Dim oCompDef As PartComponentDefinition: Set oCompDef = oPartDoc.ComponentDefinition
Dim oTG As TransientGeometry: Set oTG = oApp.TransientGeometry
Dim oFace As Face: Set oFace = oApp.CommandManager.Pick(kAllPlanarEntities, "pick rebate face")
Dim oEdge As Edge: Set oEdge = oApp.CommandManager.Pick(kPartEdgeFilter, "pick edge")
'Try to find the selected edge in the face edge collection
'if found, set the edge as the face edge
Dim e As Edge
For Each e In oFace.Edges
If e.TransientKey = oEdge.TransientKey Then
Set oEdge = e
End If
Next
' Get the start vertex of the edge to use as the origin of the sketch.
Dim oVertex As Vertex
Set oVertex = oEdge.StartVertex
Dim oPT As WorkPoint: Set oPT = oCompDef.WorkPoints.AddByMidPoint(oEdge)
oPT.Visible = False
Dim oWP As WorkPlane: Set oWP = oCompDef.WorkPlanes.AddByNormalToCurve(oEdge, oPT)
oWP.Visible = False
''create the sketch
'Dim oSketch As PlanarSketch: Set oSketch = oCompDef.Sketches.Add(oWP)
Dim oSketch As PlanarSketch
Set oSketch = oCompDef.Sketches.AddWithOrientation(oWP, oEdge, True, True, oEdge.StartVertex, True)
'Set oSketch = oCompDef.Sketches.AddWithOrientation(oWP, oEdge, False, False, oVertex, False)
'project the edge to create a point
Dim p As SketchPoint
Set p = oSketch.AddByProjectingEntity(oEdge)
'create the rectangle at the projected point
Dim r As SketchEntitiesEnumerator
Set r = oSketch.SketchLines.AddAsTwoPointCenteredRectangle(p, oTG.CreatePoint2d(0.25, 0.125))
Dim oSketchLine As SketchLine
Set oSketchLine = r.Item(1)
Call oSketch.DimensionConstraints.AddTwoPointDistance(oSketchLine.StartSketchPoint, oSketchLine.EndSketchPoint, kHorizontalDim, oTG.CreatePoint2d(0, -2))
Set oSketchLine = r.Item(4)
Call oSketch.DimensionConstraints.AddTwoPointDistance(oSketchLine.StartSketchPoint, oSketchLine.EndSketchPoint, kVerticalDim, oTG.CreatePoint2d(-2, 0))
oSketch.AxisEntity = oCompDef.WorkAxes.Item(2)
oSketch.OriginPoint = oPT
Dim oConstraint1 As TwoPointDistanceDimConstraint
Set oConstraint1 = oSketch.DimensionConstraints.Item(1)
oConstraint1.Parameter.Expression = "Depth"
Dim oConstraint2 As TwoPointDistanceDimConstraint
Set oConstraint2 = oSketch.DimensionConstraints.Item(2)
oConstraint2.Parameter.Expression = "Rebate"
Dim oSketch3D As Sketch3D
Set oSketch3D = oCompDef.Sketches3D.Add
Dim oLine As SketchLine3D
Set oLine = oSketch3D.Include(oEdge)
Dim oProfile As Profile
Set oProfile = oSketch.Profiles.AddForSolid
Dim oPath As Path
Set oPath = oCompDef.Features.CreatePath(oLine)
Dim spDef As SweepDefinition
Set spDef = oCompDef.Features.SweepFeatures.CreateSweepDefinition(kPathSweepType, oProfile, oPath, kCutOperation)
Dim sp As SweepFeature
Set sp = oCompDef.Features.SweepFeatures.Add(spDef)
End Sub
thanks for any help
Nacho
Automation & Design Engineer
Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.