I am learning as I go and piecing code together to accomplish what I need.
The main goal is to export a light weight parasolid for System Layout (AutoCAD). I have tried different code and different manual steps and nothing comes close to what this code does.
The process is after blanking/hiding what is not needed through the assembly, run this code....pull into the assembly the component solids with Wave Geometry Linker, continue using Linked Exterior with all unblanked solids in the Assembly, remove Parameters from the resulted Sheet Bodies, and export as a parasolid file.
The main issue I need help on is that when the code is ran, I get unwanted sheet bodies at 0,0,0. Example....If I take a simple unit and blank out all the screw heads (M8, M10, M12), I get one set of M12 sheet bodies at 0,0,0. If I blank any combination of M12s and leave at least one M12 unblanked, I do not get the extra sheet bodies. I have ran this code with an assembly that had many sub-assemblies. I would get a handful of unwanted sheet bodies at 0,0,0 from the sub-assemblies.
I have tested many options. If I suppress items instead of blank them, I do not receive the extra sheet bodies, but for some reason my final parasolid file can be up to twice as large compared to blanking items. Also, it seems like the last item blanked in the navigator "determines" what are the extra sheet bodies at 0,0,0.
I am only guessing that the Wave Geometry Linker is the issue. I am working with NX11.
Update-
I did some troubleshooting and the extra sheet bodies actually show up right after this...
ufs.Modl.CreateLinkedExterior(extData, extFeat)
I am unsure if the extra sheet bodies show up from something in the Wave Geometry Linker or actually from the Linked Exterior operation.
Option Strict Off
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports System.Collections
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.Assemblies
Imports Microsoft.VisualBasic
Module create_linked_exterior_and_export_parasolid_result
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Sub Main()
Dim FolderBrowserDialog1 As New FolderBrowserDialog
Dim filepath As String
Dim filename As String
With FolderBrowserDialog1
.RootFolder = Environment.SpecialFolder.Desktop
.SelectedPath = "T:\data\medm\biw\"
.Description = "Select the Tool Folder to Save in..."
If .ShowDialog = DialogResult.OK Then
filepath = .SelectedPath
Else
Exit Sub
End If
End With
Redo:
filename = ""
filename = filename + InputBox("Filename: ", "Filename for Exported Parasolid", "MAAXXXXXL_XX_DATE")
Dim myPath As String = IO.Path.Combine(filepath, filename & ".x_t")
Dim UserResponse As Integer
If IO.File.Exists(myPath) Then
UserResponse = MsgBox ("File """ & filename & ".x_t""" & " already exists. Do you want to replace it?", vbYesNo, "Journal - Export Reduced Parasolid")
If UserResponse = vbYes Then
IO.File.Delete(myPath)
Else 'No
Goto Redo
End If
End If
Dim dPart As Part = theSession.Parts.Display
Dim bodies() As Body = AskAllBodies(dPart)
Dim comps(bodies.Length - 1) As Assemblies.Component
Dim xforms(bodies.Length - 1) As NXOpen.Tag
Dim body_tags(bodies.Length - 1) As NXOpen.Tag
Dim proto As NXObject
For ii As Integer = 0 To bodies.Length - 1
If bodies(ii).IsOccurrence() Then
comps(ii) = bodies(ii).OwningComponent
proto = bodies(ii).Prototype
body_tags(ii) = proto.Tag
If NOT bodies(ii).IsBlanked Then
ufs.So.CreateXformAssyCtxt(comps(ii).Tag, _
comps(ii).Tag, NXOpen.Tag.Null, xforms(ii))
End If
Else
comps(ii) = Nothing
body_tags(ii) = bodies(ii).Tag
xforms(ii) = NXOpen.Tag.Null
End If
Next
Dim directions(,) As Double = _
{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}
Dim n_faces As Integer
Dim faces() As Tag = Nothing
Dim comp_index() As Integer = Nothing
ufs.Modl.IdentifyExteriorUsingHl(bodies.Length, body_tags, _
xforms, 6, directions, _
dPart.Preferences.Modeling.DistanceToleranceData, _
UFConstants.UF_LINKED_HL_RES_COARSE, n_faces, faces, comp_index)
Dim extData As UFModl.LinkedExt
With extData
.at_timestamp = False
.bodies = body_tags
.delete_openings = True
.faces = faces
.group_results = UFConstants.UF_LINKED_EXT_GROUP_NONE
.mass_props = False
.num_bodies = bodies.Length
.num_faces = n_faces
.xform_index = comp_index
.xforms = xforms
End With
Dim extFeat As NXOpen.Tag = Nothing
Dim mark As Session.UndoMarkId = theSession.SetUndoMark( _
Session.MarkVisibility.Visible, "Create Linked Exterior")
ufs.Modl.CreateLinkedExterior(extData, extFeat)
Dim n_groups As Integer
Dim groups() As NXOpen.Tag = Nothing
Dim n_subfeats As Integer
Dim subfeats() As NXOpen.Tag = Nothing
Dim mass_props(46) As Double
ufs.Modl.AskLinkedExterior(extFeat, extData, n_groups, groups, _
n_subfeats, subfeats, mass_props)
Dim bList As ArrayList = New ArrayList
Dim bTag As NXOpen.Tag
For ii As Integer = 0 To n_subfeats - 1
ufs.Modl.AskFeatBody(subfeats(ii), bTag)
bList.Add(bTag)
Next
Dim bTags() As NXOpen.Tag = bList.ToArray(GetType(NXOpen.Tag))
ufs.Modl.DeleteBodyParms(bTags)
ufs.Ps.ExportData(bTags, myPath)
MsgBox ("Successfully Completed the Task.", vbInformation, "Journal - Export Reduced Parasolid")
End Sub
Function AskAllBodies(ByVal thePart As Part) As Body()
Dim theBodies As New System.Collections.ArrayList()
Dim aBodyTag As Tag = NXOpen.Tag.Null
Do
ufs.Obj.CycleObjsInPart(thePart.Tag, _
UFConstants.UF_solid_type, aBodyTag)
If aBodyTag = NXOpen.Tag.Null Then
Exit Do
End If
Dim theType As Integer, theSubtype As Integer
ufs.Obj.AskTypeAndSubtype(aBodyTag, theType, theSubtype)
If theSubtype = UFConstants.UF_solid_body_subtype Then
theBodies.Add(theSession.GetObjectManager.GetTaggedObject(aBodyTag))
End If
Loop While True
Return DirectCast(theBodies.ToArray(GetType(Body)), Body())
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module