Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Turn off Read Only

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
ndillner343SKL
573 Views, 7 Replies

Turn off Read Only

Is there a way to turn off "Read Only" for your project folder and all of its contents?

 

I assume it would start by grabbing the directory.

ThisDoc.WorkspacePath()

 

7 REPLIES 7
Message 2 of 8
WCrihfield
in reply to: ndillner343SKL

Hi @ndillner343SKL.  That situation sounds a bit odd.  Are you using Vault?  If so, is it possible that the directory in question is being controlled by Vault?  Are you talking about the Project file itself, and the settings within that project file, or just the directory, like when viewed through the Windows file explorer?  The settings within the Project file will remain ReadOnly while there are any Inventor documents open.  It will also remain ReadOnly, if it is being used by other users, and any of them currently have any Inventor documents open.  If you are the only one using that Project file, and you have all Inventor documents closed, then the Project file should be editable.  I'm not sure if you may have a CAD Manager or IT admin that might have it locked for some reason though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 8
ndillner343SKL
in reply to: WCrihfield

It is being controlled by a vault like program. I'm talking about the directory when viewed from the file explorer. And this only applies when I'm working outside the "Vault" program. Therefore, I can easily turn off read only manually in file explorer or change project folders or break the link with "Vault". So it's definitely not an issue, but just something I was curious if it could be controlled via iLogic.

Message 4 of 8
WCrihfield
in reply to: ndillner343SKL

You can try this bit of code as an iLogic rule, to attempt to check if that directory is currently set to ReadOnly, and if so, attempt to turn it off.  I haven't really tested it yet though.

 

Imports System.IO
oActiveProj = ThisApplication.DesignProjectManager.ActiveDesignProject
Dim oWSPath As String = oActiveProj.WorkspacePath
If String.IsNullOrEmpty(oWSPath) Then
	MsgBox("No 'WorkspacePath' specified in active Project.", , "")
	Exit Sub
End If
If Not Directory.Exists(oWSPath) Then
	MsgBox("The specified directory could not be found.", , "")
	Exit Sub
End If
Dim oAtts As FileAttributes = System.IO.File.GetAttributes(oWSPath)
If ((oAtts And FileAttributes.ReadOnly) = FileAttributes.ReadOnly) Then
	MsgBox("The 'WorkspacePath' directory was ReadOnly.", , "")
	oAtts = (oAtts And (Not FileAttributes.ReadOnly))
	System.IO.File.SetAttributes(oWSPath, oAtts)
	MsgBox("Now the 'WorkspacePath' directory should not be ReadOnly.", , "")
Else
	MsgBox("The 'WorkspacePath' directory is not ReadOnly.", , "")
End If

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 8
ndillner343SKL
in reply to: WCrihfield

Hi @WCrihfield,

 

I ended up going a different route with this last year. But now I'm back to wanting to change the entire directory at once. The code you have below appears to be exactly what I'm looking for. But it's not working for me. Could it be because I have sub-folders within my directory?

 

Thank you!

 

Imports System.IO

Dim oActiveProj = ThisApplication.DesignProjectManager.ActiveDesignProject
Dim oWSPath As String = oActiveProj.WorkspacePath

If String.IsNullOrEmpty(oWSPath) Then Exit Sub
If Not Directory.Exists(oWSPath) Then Exit Sub

Dim oAtts As FileAttributes = System.IO.File.GetAttributes(oWSPath)
If ((oAtts And FileAttributes.ReadOnly) = FileAttributes.ReadOnly) Then
      oAtts = (oAtts And (Not FileAttributes.ReadOnly))
      System.IO.File.SetAttributes(oWSPath, oAtts)
End If

 

Message 6 of 8
WCrihfield
in reply to: ndillner343SKL

Hi @ndillner343SKL.  Working with an 'Enum' in this way is tricky and can be difficult to picture in our minds.  The 'ReadOnly' status is also a bit trickier than some other attributes to mess with in some situations.  For instance, on my work computer (Windows 10 PC), all folders seem to have a 'partial' status for that specific attribute.  What I mean is that the checkbox is filled in with a black box, instead of simply a check mark or no check mark.  This appears to be a rather meaningless status, according to some quick/brief searches.  When I run a similar code, I get results in my iLogic Log window indicating that the process works as designed, but when I manually review the folder in the Windows File Explorer (right-click on it, choose Properties, look at the CheckBox) it appears the same either way (still has the black, filled-in square, instead of a check mark or clear box).

 

However, when I switched my code to controlling the 'Hidden' attribute, instead of ReadOnly, the status changes are obvious, and appear to work as designed, so I can only assume the 'ReadOnly' process is also working just fine.

 

Below are the two code examples I was working with.  After you run these, check in the iLogic Log window for any feedback.  I did not like working directly with my project workspace directory in these examples, because we have a whole team of people working within that same directory, and I did not want to mess things up for them.  So I just created a new temporary folder right under my 'C' drive to test on.

 

Here is the one for 'toggling' the 'ReadOnly' attribute.

Imports System.IO
'Dim sPath As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
Dim sPath As String = "C:\MyTempFolder"
If String.IsNullOrEmpty(sPath) Then
	Logger.Debug("Path Is Null or Empty!")
	Return
ElseIf System.IO.Directory.Exists(sPath) = False Then
	Logger.Debug("Path Does Not Exist!")
	Return
End If
Logger.Info("Path:" & vbCrLf & sPath)
Dim oFileAtts = System.IO.File.GetAttributes(sPath)
If IsNothing(oFileAtts) Then
	Logger.Debug("No FileAttributes Obtained.")
	Return
Else 'toggle the 'ReadOnly' attribute
	'if it is ReadOnly, then change it to not ReadOnly
	If ((oFileAtts And System.IO.FileAttributes.ReadOnly) = System.IO.FileAttributes.ReadOnly) Then
		Logger.Info("Directory Was ReadOnly.")
		oFileAtts = (oFileAtts And (Not System.IO.FileAttributes.ReadOnly))
		System.IO.File.SetAttributes(sPath, oFileAtts)
		Logger.Info("Directory Changed To Not ReadOnly.")
	Else 'if it is not ReadOnly, so change it to ReadOnly
		Logger.Info("Directory Was Not ReadOnly.")
		oFileAtts = (oFileAtts Or System.IO.FileAttributes.ReadOnly)
		System.IO.File.SetAttributes(sPath, oFileAtts)
		Logger.Info("Directory Changed To ReadOnly.")
	End If
End If

And this one is for 'toggling' the 'Hidden' attribute.  (Almost exactly the same.)  It worked just fine for me.

Imports System.IO
'Dim sPath As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
Dim sPath As String = "C:\MyTempFolder"
If String.IsNullOrEmpty(sPath) Then
	Logger.Debug("Path Is Null or Empty!")
	Return
ElseIf System.IO.Directory.Exists(sPath) = False Then
	Logger.Debug("Path Does Not Exist!")
	Return
End If
Logger.Info("Path:" & vbCrLf & sPath)
Dim oFileAtts = System.IO.File.GetAttributes(sPath)
If IsNothing(oFileAtts) Then
	Logger.Debug("No FileAttributes Obtained.")
	Return
Else 'toggle the 'Hidden' attribute
	'if it is Hidden, then change it to not Hidden
	If ((oFileAtts And System.IO.FileAttributes.Hidden) = System.IO.FileAttributes.Hidden) Then
		Logger.Info("Directory Was Hidden.")
		oFileAtts = (oFileAtts And (Not System.IO.FileAttributes.Hidden))
		System.IO.File.SetAttributes(sPath, oFileAtts)
		Logger.Info("Directory Changed To Not Hidden.")
	Else 'if it is not Hidden, so change it to Hidden
		Logger.Info("Directory Was Not Hidden.")
		oFileAtts = (oFileAtts Or System.IO.FileAttributes.Hidden)
		System.IO.File.SetAttributes(sPath, oFileAtts)
		Logger.Info("Directory Changed To Hidden.")
	End If
End If

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 8
WCrihfield
in reply to: ndillner343SKL

And by the way, below is a link to the 'official' online documentation about these code objects/methods, for more reference & reading.  There is already a decent example code in there for working with the 'Hidden' attribute of a file.

https://learn.microsoft.com/en-us/dotnet/api/system.io.fileattributes 

https://learn.microsoft.com/en-us/dotnet/api/system.io.file.getattributes 

https://learn.microsoft.com/en-us/dotnet/api/system.io.file.setattributes 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 8
ndillner343SKL
in reply to: WCrihfield

@WCrihfield 

 

The following code is able to turn off read only on all of the individual files. Although the directories still appear with the filled square. I believe that may be unavoidable. But the code is working as needed and I couldn't have done it without your help.

 

Thank you very much! 

 

Private Sub iLogicButtom3_OnExecute(Context As NameValueMap) Handles iLogicButtom3.OnExecute
    Dim oWSPath As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath

    If String.IsNullOrEmpty(oWSPath) Then Exit Sub
    If Not Directory.Exists(oWSPath) Then Exit Sub

    Dim mainDir As New DirectoryInfo(oWSPath)

    Dim dInfo As DirectoryInfo() = mainDir.GetDirectories("*.*")

    Call recursionDir(dInfo)
    Call readOnlyOff(mainDir)
End Sub
Private Sub recursionDir(dInfo As DirectoryInfo())
    For Each dir As DirectoryInfo In dInfo
        Dim dInfoNew As DirectoryInfo() = dir.GetDirectories("*.*")
        If dInfoNew.Length > 0 Then Call recursionDir(dInfoNew)
        Call readOnlyOff(dir)
    Next
End Sub
Private Sub readOnlyOff(oDir As DirectoryInfo)
    Dim fInfo As IO.FileInfo() = oDir.GetFiles("*.*")
    For Each file As IO.FileInfo In fInfo
        If file.IsReadOnly Then file.IsReadOnly = False
    Next
End Sub

 

 

 

 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report