NxOpen check if part IsModified
NxOpen check if part IsModified
(OP)
Hi guys,
I wrote a script that changes the file attribute of a part to readonly. And I want to add a check if a part is modified. After searching the help I found "NXOpen.UF ► UFPart ► IsModified(Tag)".
But I don't know how to call the Ismodified-function.
Please help!
Thanks
Option Strict Off
Imports System
Imports System.IO
Imports System.Collections
Imports System.Threading
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Assemblies
Module ReadOnly_ON
Sub Main()
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI
Dim lw As ListingWindow = s.ListingWindow()
Dim workPart As Part = s.Parts.Work
Dim RemUtil As RemoteUtilities = NXOpen.RemoteUtilities.GetRemoteUtilities()
Dim FilePath As String
Dim ufp As UFPart
Dim modified As Boolean
''lw.WriteLine("Work : " & workPart.FullPath)
FilePath = workPart.FullPath
modified = ufp.IsModified(workPart.Tag)
If modified Then
lw.WriteLine("modified")
End If
If RemUtil.IsFileWritable(FilePath) = True Then
''lw.WriteLine("File is WRITABLE")
RemUtil.SetFileWritable(FilePath, False)
'check if changed
If RemUtil.IsFileWritable(FilePath) = True Then
''lw.WriteLine("FAILED: File is LOCKED")
theUI.NXMessageBox.Show(workPart.Leaf & ".prt", NXMessageBox.DialogType.Error, "Failed: File is LOCKED")
Else
''lw.WriteLine("Attibute changed: File is READ-ONLY")
theUI.NXMessageBox.Show(workPart.Leaf & ".prt", NXMessageBox.DialogType.Information, "Attibute changed: File is READ-ONLY")
End If
Else
''lw.WriteLine("File is already READ-ONLY")
theUI.NXMessageBox.Show(workPart.Leaf & ".prt", NXMessageBox.DialogType.Warning, "File is already READ-ONLY")
End If
End Sub
End Module
I wrote a script that changes the file attribute of a part to readonly. And I want to add a check if a part is modified. After searching the help I found "NXOpen.UF ► UFPart ► IsModified(Tag)".
But I don't know how to call the Ismodified-function.
Please help!
Thanks
Option Strict Off
Imports System
Imports System.IO
Imports System.Collections
Imports System.Threading
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Assemblies
Module ReadOnly_ON
Sub Main()
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI
Dim lw As ListingWindow = s.ListingWindow()
Dim workPart As Part = s.Parts.Work
Dim RemUtil As RemoteUtilities = NXOpen.RemoteUtilities.GetRemoteUtilities()
Dim FilePath As String
Dim ufp As UFPart
Dim modified As Boolean
''lw.WriteLine("Work : " & workPart.FullPath)
FilePath = workPart.FullPath
modified = ufp.IsModified(workPart.Tag)
If modified Then
lw.WriteLine("modified")
End If
If RemUtil.IsFileWritable(FilePath) = True Then
''lw.WriteLine("File is WRITABLE")
RemUtil.SetFileWritable(FilePath, False)
'check if changed
If RemUtil.IsFileWritable(FilePath) = True Then
''lw.WriteLine("FAILED: File is LOCKED")
theUI.NXMessageBox.Show(workPart.Leaf & ".prt", NXMessageBox.DialogType.Error, "Failed: File is LOCKED")
Else
''lw.WriteLine("Attibute changed: File is READ-ONLY")
theUI.NXMessageBox.Show(workPart.Leaf & ".prt", NXMessageBox.DialogType.Information, "Attibute changed: File is READ-ONLY")
End If
Else
''lw.WriteLine("File is already READ-ONLY")
theUI.NXMessageBox.Show(workPart.Leaf & ".prt", NXMessageBox.DialogType.Warning, "File is already READ-ONLY")
End If
End Sub
End Module





RE: NxOpen check if part IsModified
CODE
It seems you declared the variable name as "ufs" then called it as "ufp". Change "ufp" to "ufs" in the above line of code and it should work.
www.nxjournaling.com
RE: NxOpen check if part IsModified
But I've found it thanks to your tip. THANKS!!!
I have to assign ufd a value when I declare it.
Then it works.
CODE
But I have an other problem.
The readonly caption in the titlebar is set automatically when you open/save a part.
When you change the file attribute to ON or OFF with a journal or in explorer, the readonly-status is not changed in the titlebar.
With the following code you can check what is displayed in the titlebar, but this is not the real "readonly-status" of the file.
CODE
How can I change the readonly-status of the workpart in the titlebar
OR
How can I make NX recheck the actual file attribute so the titlebar updates?
RE: NxOpen check if part IsModified
CODE
Does your journal open the part file?
If so, you can check/change the read only attribute before you open the file.
If not, you can close the file, change the attribute, and reopen the file.
I don't know of any other way to update the title bar. Perhaps someone else has a trick they can share.
www.nxjournaling.com
RE: NxOpen check if part IsModified
Because it's posible that the files are modified and we don't want to lose/save changes...