Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Module NXJournal
Sub Main
Dim theUI As UI = UI.GetUI()
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim partname As String
Dim workpart As Part = theSession.Parts.work
Dim disp_partname As String
Dim displayPart As Part = theSession.Parts.Display
Dim comp As String
Dim Revcomp As String
Dim insert as String
partname = path.GetFileNameWithoutExtension(workPart.FullPath)
comp = partname
insert = "__Rev"
Revcomp = comp .insert(5, insert)
'Msgbox(comp & chr(13) & Revcomp)
Dim partLoadStatus2 As PartLoadStatus
Dim status1 As PartCollection.SdpsStatus
status1 = theSession.Parts.SetDisplay(displaypart, False, True, partLoadStatus2)
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
partLoadStatus2.Dispose()
'Msgbox(partname)
'To find folder name and such
Dim folderName As String = "C:"
'assign output folder to workpart folder
folderName = Path.GetDirectoryName(workPart.FullPath)
'Msgbox(foldername)
Dim fileNew1 As FileNew
fileNew1 = theSession.Parts.FileNew()
fileNew1.Application = FileNewApplication.Assemblies
fileNew1.Units = Part.Units.Inches
fileNew1.TemplateFileName = "Modeling\english-model-template_c.prt"
fileNew1.NewFileName = foldername & "\" & Revcomp & ".prt"
'fileNew1.Application = FileNewApplication.Modeling
fileNew1.MasterFileName = ""
fileNew1.UseBlankTemplate = False
fileNew1.MakeDisplayedPart = False
Dim nXObject1 As NXObject
'
'nXObject1 = fileNew1.Commit()
'
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
fileNew1.Destroy()
Dim sPartFullPath As String = theSession.Parts.Display.FullPath
'Dim part1 As Part = CType(theSession.Parts.FindObject(Revcomp), Part)
Dim basePoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
Dim orientation1 As Matrix3x3
orientation1.Xx = 1.0
orientation1.Xy = 0.0
orientation1.Xz = 0.0
orientation1.Yx = 0.0
orientation1.Yy = 1.0
orientation1.Yz = 0.0
orientation1.Zx = 0.0
orientation1.Zy = 0.0
orientation1.Zz = 1.0
Dim partLoadStatus1 As PartLoadStatus
Dim component1 As Assemblies.Component
component1 = workPart.ComponentAssembly.AddMasterPartComponent(displayPart , "True" , Revcomp, basePoint1, orientation1, 50, partLoadStatus1)
'I wanted the component to be placed directely under the display part so I changed that, as well as part name and layer.
End Sub
End Module