Message 1 of 4
[Approach Needed] - How to re-orient step files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have a large number of step files that contain extruded parts which were drawn in random orientations. My objective is to get the extrusion direction to be in parallel to the Z-axis, then re-export those files as step files.
I can get the camera to face the "profile face" of the part through the code below, but I can't think of a way to set the XY plane to be parallel to the camera front.
Sub Main()
oPartDoc = ThisApplication.ActiveDocument
getLargestAreaFace(oPartDoc)
oCamera = ThisApplication.ActiveView.Camera
oCamera.ViewOrientationType = ViewOrientationTypeEnum.kRightViewOrientation
oCamera.ApplyWithoutTransition
ThisApplication.ActiveView.SetCurrentAsFront
End Sub
Function getLargestAreaFace(oPartDoc As PartDocument) As Face
Dim maxarea As Double: maxarea = 0
Dim oFace As Face
Dim ofacemax As Face
For Each oFace In oPartDoc.ComponentDefinition.SurfaceBodies.Item(1).Faces
If oFace.SurfaceType <> kCylinderSurface Then
If oFace.Evaluator.Area > maxarea Then
maxarea = oFace.Evaluator.Area
ofacemax = oFace
End If
End If
Next
Dim oSSet As SelectSet
oSSet = oPartDoc.SelectSet
Call oSSet.Clear
Call oSSet.Select(ofacemax)
ThisApplication.CommandManager.ControlDefinitions.Item("AppLookAtCmd").Execute2(True)
ThisApplication.ActiveView.SetCurrentAsFront
End Function
The result:
The other approach I was thinking of is to create a new assembly, import the part, align the longest edge of the largest face to the Z-axis, then export the assembly as a step file.
I am open to any suggestions.
Thanks in advance.