- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone!
I’m using Inventor 2020 Pro. Right now I’m trying to write a script to automate part of my workflow.
In a folder I have several files that contain flat parts and follow a similar naming pattern.
In a loop I:
take each file,
open it,
get all faces of the flat part,
find the face with the largest area,
and try to export that selected face as a DXF.
I’m able to find the face with the maximum area in code, but after that I can’t get the export function to work with that face.
Here’s my code.
...
Dim partFiles As String() = Directory.GetFiles(sourceFolder, "*.ipt", SearchOption.TopDirectoryOnly)
...
Try
Dim compDef As Inventor.PartComponentDefinition = partDoc.ComponentDefinition
Dim maxFace As Inventor.Face = Nothing
Dim maxArea As Double = -1.0
For Each body As Inventor.SurfaceBody In compDef.SurfaceBodies
For Each face As Inventor.Face In body.Faces
If face.SurfaceType = Inventor.SurfaceTypeEnum.kPlaneSurface Then
Dim evaluator As Inventor.SurfaceEvaluator = face.Evaluator
Dim area As Double = evaluator.Area
If area > maxArea Then
maxArea = area
maxFace = face
End If
End If
Next
Next
If maxFace Is Nothing Then
Return "[Skip] " & System.IO.Path.GetFileName(partPath) & " — no flat faces found"
End If
Dim selectSet As Inventor.SelectSet = partDoc.SelectSet
selectSet.Clear()
selectSet.Select(maxFace)
Dim dxfPath As String = System.IO.Path.Combine(dxfFolder, System.IO.Path.GetFileNameWithoutExtension(partPath) & ".dxf")
Dim exportStatus As String = ExportSelectedFaceViaUI(dxfPath)
Return "[OK] " & System.IO.Path.GetFileName(partPath) & " → " & exportStatus
Finally
If Not isAlreadyOpen AndAlso partDoc IsNot Nothing Then
partDoc.Close(False)
ElseIf partDoc IsNot Nothing Then
partDoc.Activate()
End If
End Try
Maybe someone more experienced can take a look and point out what I’m doing wrong. I realize it might look like total nonsense, but I really need some guidance.
I can’t get the face export to DXF working — the files just never show up in the target folder. I double-checked that the script returns the correct area for the largest face, so it is finding that face and selecting it. (From what I’ve read, programmatically selecting a face doesn’t necessarily produce any visible selection highlight in the UI.)
My guess is that in the Inventor 2020 Pro API there may not be a way to export a selected face directly.
Thanks for taking the time to read my question.
Solved! Go to Solution.