I picked up this intriguing question from a customer visit that one of my colleagues made a couple of days ago.
If you immediately create a sketch on a work plane after the plane has been created, there is not really a problem as you can find both the work plane and the sketch sitting next to each other in the browser.
But what if you create the work plane first and then much later on, after many features later, you decide to create a sketch based on the work plane, how can you correlate the two?
Often you don't even create a work plane and just use an origin plane or an existing face.
Here is an example.
Fig 1: What plane or face was Sketch1 created on?
So how do you know what geometry the sketch was built upon?
Although the problem seems rather straightforward for a CAD package, as far as I know Inventor does not offer you any viable solution, hence I decided to write this small VBA macro to fill the gap.
Option Explicit
Sub findplaneofsketch()
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
'Check to make sure a single sketch is selected.
If oDoc.SelectSet.count > 0 Then
If (oDoc.SelectSet.Item(1).Type <> kPlanarSketchObject) Then
MsgBox "A sketch must be selected first."
Exit Sub
End If
Else
MsgBox "A sketch must be selected first."
Exit Sub
End If
Dim osketch As Object
Set osketch = oDoc.SelectSet.Item(1)
If Not (osketch.PlanarEntity Is Nothing) Then
If osketch.PlanarEntity.Type = kFaceObject Then
Dim osurfbody As SurfaceBody
For Each osurfbody In oDoc.ComponentDefinition.SurfaceBodies
Dim oface As Face
For Each oface In osurfbody.Faces
If oface.InternalName = osketch.PlanarEntity.InternalName Then
oDoc.SelectSet.Select oface
Exit For
End If
Next oface
Next osurfbody
ElseIf osketch.PlanarEntity.Type = kWorkPlaneObject Then
Dim wplane As WorkPlane
For Each wplane In oDoc.ComponentDefinition.WorkPlanes
If wplane.name = osketch.PlanarEntity.name Then
oDoc.SelectSet.Select wplane
Exit For
End If
Next wplane
End If
End If
End Sub
Put this code in the ApplicationProject in the VBA editor, select a sketch and when you run the macro, either the face or the work plane the sketch was created on will get highlighted.
Here is the result in our little example. Via the macro we can easily find out that the sketch was created on the XY plane.
Fig 2: Sketch1 was created on the XY plane
You might want to expand the browser before running the macro to actually find the location of the work plane in the browser or to find out if an origin plane was used.
The code also highlights the face used to create the sketch as long as the face has not been completely removed due to a boolean operation.
Bob