Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
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: 

toggle file (.xml) attributes read only on and off

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
316 Views, 2 Replies

toggle file (.xml) attributes read only on and off

Need help with some type of rule(s) that can do the following within a dwg in inventor. I created code that can locate the path where the xml file lives (XMLFileName As String) but i need two rules to toggle the xml to read only on and off. Here are the details of the process I am trying to achieve. 

 

- Button (triggers rule #1) is clicked and checks if the xml file is read only, if yes msgbox, if no it then loads the xml file first and then sets it to read only. This will then open a form that when upon completion you will click a button (triggers rule @#2) set the xml file to read write and then save over that xml using 

iLogicVb.Automation.ParametersXmlLoad(ThisDoc.Document, XMLFileName)

and complete.

 

-Thanks in advance

 

2 REPLIES 2
Message 2 of 3
chandra.shekar.g
in reply to: Anonymous

@Anonymous,

 

To check the readonly xml file, try suggestion in below blog link.

 

https://docs.microsoft.com/en-us/dotnet/api/system.io.fileinfo.isreadonly?view=netframework-4.8

 

Try below VB.net code to read, write and save xml file.

 

https://www.codeproject.com/Articles/1222133/Reading-and-Writing-XML-in-Csharp-VB-Net

 

iLogic code is similar to VB.net code.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 3
Anonymous
in reply to: chandra.shekar.g

@chandra.shekar.g 

 

I was able to find the solution, the reference files you posted were helpful. Thanks!

 

Posting solution below.

 

IO.File.SetAttributes("file.txt",IO.FileAttributes.ReadOnly) 'sets file.txt to read only
IO.File.SetAttributes("file.txt",IO.FileAttributes.Normal) 'sets file.txt to read-write


 

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

Post to forums  

Autodesk Design & Make Report