Hi,
Is it possible to change the iLogic txt file, to edit, get text, delete text, add text (I saw this is possible) with another iLogic code.
This way codes can adjust themself and that can be a beginning of an Inventor AI.
Thank you
Have a lovely day.
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
oWrite = System.IO.File.CreateText(c:\Path...) & ".IlogicVb")
oWrite.WriteLine("text in first line of code")
oWrite.WriteLine("next line of code")
oWrite.WriteLine("next line of code")
oWrite.Close()
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
Thank you @bradeneuropeArthur ,
Now just need the code to read text from the txt file and a code to empty the txt file (delete all), so I can get the content, change it, delete the old one, and put the new one.
then I have AI AI (Artificially Intelligent Autodesk Inventor).
looks like I might be able to do it, mmmm, nice
Not an answer but...
Generally changing programs as they run is considered dangerous.
For AI have a look at Neural Networks and Generative Design....
I haven't done it myself but as far as I can tell iLogic is very similar to normal VBA. Here's something you can test to find out if it works, just to start you off
Dim sFilename As String
sFilename = "C:\AutoBat\Support\models.txt"
Dim iFileNumber As Integer
iFileNumber = FreeFile ' Get unused file number.
Open sFilename For Output As #iFileNumber ' Create file
Print #iFileNumber, "First; line"
Print #iFileNumber, "Second; line"
Close #iFileNumber ' Close file.
You'll have to adjust it to your own circumstances and presumably if you want to change iLogic files you'll have to change the global ones which are not inside assemblies and parts.
Search for VBA file handling in your favourite search engine...
To answer your question...YES. It can all be done. There is a ton of code available for working with simple text files. And there are some within the built-in iLogic Snippets too. Within your iLogic Rule Editor dialog, at the top of the Snippets (docked window along its left side), if you click the 'Custom' group (not the System group), then expand the folder labeled 'My Snippets', you will see three iLogic snippets in there for working with text files. One to create a text file, one to read a text file, ans one to append to a text file. There are tons of other easy to follow examples online too...just type in something like "vb.net text file".
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
(Not an Autodesk Employee)
Here is an example iLogic rule that does all of what you asked about in your last post. It reads text from an existing text file, then clears the contents of that text file, then deletes the file, then creates a new text file, writes contents from old file into new file, then puts more new text at the end of the new text file, then launches the new text file, so you can see the results.
To test it, all you need to do is create a text file to test it with. I put mine in my "C:\Temp\" folder, because its a common location, and named it "Test 4U.txt", and wrote three lines of text within it, just to have something to look at. Then just run this rule. The rule first checks to make sure the text file exists, to avoid potential errors.
Dim oPath As String = "C:\Temp\"
Dim oFile As String = oPath & "Test 4U.txt"
Dim oContents As String
If Not System.IO.File.Exists(oFile) Then
MsgBox("The specified text file:" & vbCrLf & _
oFile & vbCrLf & _
"was not found. Exiting.", vbOKOnly, " ")
Exit Sub
Else
'get all text in the text file to a String variable
oContents = System.IO.File.ReadAllText(oFile)
'show the user the contents of the old file in a MsgBox
MsgBox("Here is the contents of the old file:" & vbCrLf & oContents,,"")
'clear all text in the text file (overwrites all text with empty string)
System.IO.File.WriteAllText(oFile, "")
'delete the text file
System.IO.File.Delete(oFile)
End If
'now create a new text file
Dim oWriter As New System.IO.StreamWriter(oPath & "New Test 4U.txt")
'write contents from old text file into the new one
oWriter.Write(oContents)
'write more text below that
oWriter.WriteLine()
oWriter.Write("Added text at bottom of new text file contents.")
oWriter.Flush 'clears buffers & makes sure it's written to the text file
oWriter.Close 'closes the text file
oWriter.Dispose 'releases resources/references to the writer & file
ThisDoc.Launch(oPath & "New Test 4U.txt") 'creates a Process & launches the text file
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 :light_bulb:or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)
One more question. Sorry for bothering you.
Is it possible and how to do it, how to get input from the user and store it for the next usage of the USerForm or Module?
For example, I have buttons with the Product Manager's initial, so when PM changes I want to be able to get new initials and to assign to one of the buttons, basically to change the command button caption and to change what that button sends to the textbox.
The next level is to delete the button if PM leaves or add a new one if a new PM comes, without changing the code, just with user input, which is much more advanced.
So maybe to have one more command button which will ask you which button you wanna exit, then asks for delete or exit name (caption), and one command button to make a new command button and ask for its caption.
Sounds so complicated.
I know that this is easy in VBA and vb.net.
Ilogic will be much more complicated.
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
That's what I need, VBA.
Sorry I did not mention it.
VBA, VBA
Would be great to get it.
Thank you.
Thank you.
Tomorrow I will have a look
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
You can use this:
Public Sub main()
Dim a As UserForm1
Set a = New UserForm1
a.Show (False)
a.CommandButton1.Caption = "Jan"
End Sub
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
thank you @bradeneuropeArthur
It would be more like:
-3 buttons, a button for changing the name (button caption), another button for deleting the button, one more to make a new button
-pressing the first button will ask you which one you wanna change, then what's the new value
-pressing the second button, will ask you which one to delete, or hide
-3rd, will ask you whats the caption of the new one and make it
I do not know how to change the value for the caption of the button, I found online it is possible to put it in Win Reg, but is there a better solution.
Is it possible to change the VBA code itself, for example, to say, from now on xxx.caption is no more ="yyy" in the code itself, now it will be ="zzz", and also variable, xxx1 is not what it was, it will have a new value. Easy. Simple.
I guess it is not possible, but the q. is why, as I many times said we live in the digital era when everything is possible, y not this?
But as @oransen said this is more VBA question, so I will try to find it online.
Can't find what you're looking for? Ask the community or share your knowledge.