journal IO.file.delete
journal IO.file.delete
(OP)
I am having trouble using a IO.File.Delete command within NX's journal. The error message I keep receiving is attached. This is a part of a bigger program that creates a "_rev" version of my current workpart. There is an intermediate part "delete_rev”, which I need to manually go through and delete files but I would like to automate this. The following snippet is what I plan to add to the code but for some reason cannot delete the "delete_rev" part from NX. I can however delete the "_rev" and original part but that doesn't help me automate this.
Additional snippet:
Original Code
Additional snippet:
CODE --> vb
Module NXJournals
Sub Main
Dim theUI As UI = UI.GetUI()
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workpart As Part = theSession.Parts.work
Dim Revcomp As String
Revcomp = path.GetFileNameWithoutExtension(workPart.FullPath)
Dim folderName As String = Path.GetDirectoryName(workpart.FullPath)
Dim fullpathname2 As String = folderName & "\" & "delete_" & Revcomp & ".prt"
'delete
If IO.File.Exists(fullpathname2) Then
MsgBox("Deleting.")
IO.File.Delete(fullpathname2)
End If
End Sub
End Module Original Code
CODE --> vb
Option Strict Off
Imports System
Imports System.Windows.Forms
Imports System.IO
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Threading
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
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
Dim partLoadStatus2 As NXOpen.PartLoadStatus = Nothing
partname = path.GetFileNameWithoutExtension(workPart.FullPath)
comp = partname
insert = "__Prep"
'Revcomp = comp .insert(5, insert)
Dim dIndex = comp.IndexOf("_")
Revcomp=comp.insert(dIndex, insert)
'To find folder name and such
Dim folderName As String = Path.GetDirectoryName(workpart.FullPath)
Dim fullpathname1 As String = "C:\Program Files\UGS\NX 7.5\UGII\html_files/model_template_inch.prt"
Dim fullpathname2 As String = folderName & "\" & "delete_" & Revcomp
If File.Exists(fullpathname2 & ".prt") Then
If Msgbox("File Already Exists. Do you want to overwrite?", vbyesno + vbquestion, "File Already Exists") = vbno then
Exit Sub
Else
fullpathname2 = fullpathname2 & "_"
End If
End If
'Msgbox(comp & chr(13) & Revcomp)
Dim partLoadStatus3 As PartLoadStatus
Dim status1 As PartCollection.SdpsStatus
status1 = theSession.Parts.SetDisplay(displaypart, False, True, partLoadStatus3)
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
partLoadStatus3.Dispose()
'Msgbox(partname)
Fullpathname2 = fullpathname2 & ".prt"
File.Copy(fullpathname1, fullpathname2)
Dim basePart1 As BasePart = theSession.Parts.OpenBase(fullpathname2, partLoadStatus2)
Dim part2 As Part = CType(basePart1, 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 component1 As Component = workpart.ComponentAssembly.AddComponent(part2, "Model", Revcomp, _
basePoint1, orientation1, 200, partLoadStatus2)
Dim partSaveStatus1 As PartSaveStatus
Dim partLoadStatus1 As PartLoadStatus
theSession.Parts.SetWorkComponent(component1, partLoadStatus1)
workPart = theSession.Parts.Work
partLoadStatus1.Dispose()
Dim fullpathname3 As string
fullpathname3=folderName & "\" & Revcomp & ".prt"
If File.Exists(fullpathname3) Then
fullpathname3=foldername & "\" & Revcomp & "_.prt"
End If
'Msgbox(fullpathname2)
partSaveStatus1 = workPart.SaveAs(fullpathname3)
partSaveStatus1.Dispose()
Dim mySolid As NXObject
If SelectSolid("Select a solid", mySolid) = Selection.Response.Cancel Then
Exit Sub
End If
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim nullFeatures_Feature As Features.Feature = Nothing
If Not workPart.Preferences.Modeling.GetHistoryMode Then
Throw (New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
End If
Dim waveLinkBuilder1 As Features.WaveLinkBuilder
waveLinkBuilder1 = workPart.BaseFeatures.CreateWaveLinkBuilder(nullFeatures_Feature)
Dim extractFaceBuilder1 As Features.ExtractFaceBuilder
extractFaceBuilder1 = waveLinkBuilder1.ExtractFaceBuilder
extractFaceBuilder1.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain
waveLinkBuilder1.Type = Features.WaveLinkBuilder.Types.BodyLink
extractFaceBuilder1.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain
'waveLinkBuilder1.CopyThreads = False
extractFaceBuilder1.ParentPart = Features.ExtractFaceBuilder.ParentPartType.OtherPart
theSession.SetUndoMarkName(markId1, "WAVE Geometry Linker Dialog")
extractFaceBuilder1.Associative = True
extractFaceBuilder1.FixAtCurrentTimestamp = False
extractFaceBuilder1.HideOriginal = False
extractFaceBuilder1.InheritDisplayProperties = False
Dim selectObjectList1 As SelectObjectList
selectObjectList1 = extractFaceBuilder1.BodyToExtract
'extractFaceBuilder1.CopyThreads = False
Dim added1 As Boolean
added1 = selectObjectList1.Add(mySolid)
Dim nXObject1 As NXObject
nXObject1 = waveLinkBuilder1.Commit()
theSession.SetUndoMarkName(markId1, "WAVE Geometry Linker")
waveLinkBuilder1.Destroy()
End Sub
Function SelectSolid(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a solid"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selobj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Public Function GetUnloadOption(ByVal arg As String) As Integer
Return CType(Session.LibraryUnloadOption.Immediately, Integer)
End Function
End Module Denis Huskic
Data Prep
Kettering University
Class of '17





RE: journal IO.file.delete
p.s.
It may not be a problem, but I don't recommend mixing forward and backward slashes when referencing a file path.
CODE
Dim fullpathname1 As String = "C:\Program Files\UGS\NX 7.5\UGII\html_files/model_template_inch.prt"www.nxjournaling.com
RE: journal IO.file.delete
Denis Huskic
Data Prep
Kettering University
Class of '17
RE: journal IO.file.delete
CODE --> vb
Denis Huskic
Data Prep
Kettering University
Class of '17