Option Strict Off Imports System.IO Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.UF.UFPs Imports NXOpen.UF.UFAssem Imports NXOpen.UF.UFModl Imports NXOpen.UF.UFObj Imports NXOpen.UF.UFPart Imports NXOpen.UF.UFConstants Module Module1 Public body_list() As Tag ' Explicit Activation ' This entry point is used to activate the application explicitly Sub Main() Dim theSession As Session = Session.GetSession() Dim theUI As UI = UI.GetUI() Dim theUfSession As UFSession = UFSession.GetUFSession() ' TODO: Add your application code here Dim displayPart As Part = theSession.Parts.Display MsgBox("1") 'Dim prtname As String = "D:\1111111.prt" '部件文件名 'Dim prtname As String = "F:\lashen.prt" 'Dim expname As String = "F:\lashen.txt" '表达式文件名 Dim x_tname As String = "D:\aasse_pb.x_t" 'ParaSolid文件名 Dim part_tag As NXOpen.Tag = displayPart.Tag 'Dim load_status As NXOpen.UF.UFPart.LoadStatus 'Try ' theUfSession.Part.Open(prtname, part_tag, load_status) 'Catch ex As Exception ' MsgBox(ex.ToString) 'End Try 'Try ' theUfSession.Modl.ImportExp(expname, 0) 'Catch ex As Exception ' MsgBox(ex.ToString) 'End Try Try theUfSession.Modl.Update() Catch ex As Exception ex.ToString() End Try Try theUfSession.Part.Save() Catch ex As Exception ex.ToString() End Try Dim root_part_occ As NXOpen.Tag root_part_occ = theUfSession.Assem.AskRootPartOcc(part_tag) theUfSession.Modl.CreateList(body_list) Try If root_part_occ = Tag.Null Then make_body_list_part(part_tag) Else Dim obj As NXOpen.Tag = theUfSession.Assem.AskPrototypeOfOcc(root_part_occ) make_body_list_assem(obj) End If theUfSession.Ps.ExportData(body_list, x_tname) theUfSession.Modl.DeleteBodyParms(body_list) Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Sub make_body_list_part(ByVal body_tag As Tag) Dim obj As NXOpen.Tag = Tag.Null Dim UF_body_type As Int32 Dim type As Int32 Dim subtype As Int32 Do UFSession.GetUFSession().Obj.CycleObjsInPart(body_tag, UF_solid_type, obj) If obj <> Tag.Null Then UFSession.GetUFSession().Obj.AskTypeAndSubtype(obj, type, subtype) UFSession.GetUFSession().Modl.AskBodyType(obj, UF_body_type) If subtype <> UF_solid_body_subtype Then Continue Do End If If UF_body_type = UF_MODL_SOLID_BODY Then UFSession.GetUFSession().Modl.PutListItem(body_list, obj) Exit Do End If End If Loop End Sub Sub make_body_list_assem(ByVal body_tag As Tag) Dim obj As Tag = Tag.Null Dim UF_body_type As Int32 Dim type As Int32 Dim subtype As Int32 Do Dim UF_OBJ As UFObj = UFSession.GetUFSession().Obj UF_OBJ.CycleObjsInPart(body_tag, UF_solid_type, obj) If obj <> Tag.Null Then UF_OBJ.AskTypeAndSubtype(obj, type, subtype) Dim UF_MODL As UFModl = UFSession.GetUFSession().Modl UF_MODL.AskBodyType(obj, UF_body_type) If subtype <> UF_solid_body_subtype Then Continue Do End If If UF_body_type = UF_MODL_SOLID_BODY Then UF_MODL.PutListItem(body_list, obj) Exit Do End If End If Loop End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately '----Other unload options------- 'Unloads the image when the NX session terminates 'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination 'Unloads the image explicitly, via an unload dialog 'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly '------------------------------- End Function End Module |
|