Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

NxOpen check if part IsModified

Status
Not open for further replies.

FV

Mechanical
Jul 14, 2011
6
BE
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
 
Replies continue below

Recommended for you

Code:
modified = [COLOR=red]ufp[/color].IsModified(workPart.Tag)

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
 
If I do that I get an error, "IsModified is not a member of UFsession"

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:
 ...
Dim ufp As UFPart = ufs.part
Dim modified As Boolean


''lw.WriteLine("Work : " & workPart.FullPath)
FilePath = workPart.FullPath

modified = ufp.IsModified(workPart.Tag)
...


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:
Dim s As Session = Session.GetSession()
Dim workPart As Part = s.Parts.Work

if workPart.IsReadOnly then
...

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?



 
My previous post should have read:

Code:
modified = ufs.[COLOR=red]Part[/color].IsModified(workPart.Tag)

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
 
No my journal doesn't open the parts. And I don't want to use save or open to update the titlebar.
Because it's posible that the files are modified and we don't want to lose/save changes...


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top