By Wayne Brill
If you import a model from another format there should be NonParametricBaseFeature. You can use this to get B-Rep infromation. (In Inventor 2011 this was the only way to get this information from a model imported from another format.)
Here are VBA and VB.NET examples accessing the surface body of the model from the NonParametricBaseFeature. These examples print out the Brep information in the immediate window.
Sub NonParametricBaseFeatures()
'get the non param feature
Dim nonparamF As NonParametricBaseFeature
Dim basebody As SurfaceBody
Dim pdoc As PartDocument
Set pdoc = ThisApplication.ActiveDocument
Set nonparamF = pdoc.ComponentDefinition. _
Features.NonParametricBaseFeatures.Item(1)
Call nonparamF.Edit
Set basebody = nonparamF.BaseSolidBody
'Works too in Inventor 2013
'Set basebody = pdoc.ComponentDefinition _
' .SurfaceBodies(1)
Call AnalyseSurfaceBody(basebody)
Call nonparamF.ExitEdit
End Sub
Sub AnalyseSurfaceBody(oSB As SurfaceBody)
Dim I As Long
For I = 1 To oSB.Edges.count
Dim oEdge As Edge
Set oEdge = oSB.Edges(I)
If oEdge.CurveType = kCircleCurve Then
Debug.Print oEdge.CurveType & _
" -> Circle"
ElseIf (oEdge.CurveType = kLineCurve) Then
Debug.Print oEdge.CurveType & _
" -> Line"
Else
Debug.Print oEdge.CurveType & _
" -> Other types or Unknown"
End If
Next I
For I = 1 To oSB.Faces.count
Dim oFace As Face
Set oFace = oSB.Faces(I)
If (oFace.SurfaceType = kCylinderSurface) Then
Debug.Print oFace.SurfaceType & _
" -> Cylinder"
ElseIf (oFace.SurfaceType = kPlaneSurface) Then
Debug.Print oFace.SurfaceType & _
" -> Plane"
Else
Debug.Print oFace.SurfaceType & _
" -> Other types or Unknown"
End If
Next I
End Sub
VB.NET
Public Class Form1
Dim m_inventorApp As Inventor.Application _
= Nothing
Private Sub Button1_Click(ByVal sender As _
System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
' Get an active instance of Inventor
Try
m_inventorApp = System.Runtime. _
InteropServices.Marshal. _
GetActiveObject("Inventor.Application")
Catch 'Inventor not started
System.Windows.Forms.MessageBox. _
Show("Start an Inventor session")
Exit Sub
End Try
'Call the Sub
NonParametricBaseFeatures()
End Sub
Sub NonParametricBaseFeatures()
'get the non param feature
Dim nonparamF As NonParametricBaseFeature
Dim basebody As SurfaceBody
Dim pdoc As PartDocument
pdoc = m_inventorApp.ActiveDocument
nonparamF = pdoc.ComponentDefinition. _
Features.NonParametricBaseFeatures.Item(1)
Call nonparamF.Edit()
basebody = nonparamF.BaseSolidBody
'Works too in Inventor 2013
'Set basebody = pdoc.ComponentDefinition _
'.SurfaceBodies(1)
Call AnalyseSurfaceBody(basebody)
Call nonparamF.ExitEdit()
End Sub
Sub AnalyseSurfaceBody(oSB As SurfaceBody)
Dim I As Long
For I = 1 To oSB.Edges.count
Dim oEdge As Edge
oEdge = oSB.Edges(I)
If oEdge.CurveType = _
CurveTypeEnum.kCircleCurve Then
Debug.Print(oEdge.CurveType & _
" -> Circle")
ElseIf (oEdge.CurveType = _
CurveTypeEnum.kLineCurve) Then
Debug.Print(oEdge.CurveType & _
" -> Line")
Else
Debug.Print(oEdge.CurveType & _
" -> Other types or Unknown")
End If
Next I
For I = 1 To oSB.Faces.count
Dim oFace As Face
oFace = oSB.Faces(I)
If (oFace.SurfaceType = _
SurfaceTypeEnum.kCylinderSurface) Then
Debug.Print(oFace.SurfaceType & _
" -> Cylinder")
ElseIf (oFace.SurfaceType = _
SurfaceTypeEnum.kPlaneSurface) Then
Debug.Print(oFace.SurfaceType & _
" -> Plane")
Else
Debug.Print(oFace.SurfaceType & _
" -> Other types or Unknown")
End If
Next I
End Sub
End Class