×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

NxOpen check if part IsModified

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

RE: NxOpen check if part IsModified

CODE

modified = ufp.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

RE: NxOpen check if part IsModified

(OP)
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?



RE: NxOpen check if part IsModified

My previous post should have read:

CODE

modified = ufs.Part.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

RE: NxOpen check if part IsModified

(OP)
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...


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources