iLogic rule for deleting or replacing files in a folder

iLogic rule for deleting or replacing files in a folder

Anonymous
Not applicable
1,572 Views
6 Replies
Message 1 of 7

iLogic rule for deleting or replacing files in a folder

Anonymous
Not applicable

Hello

 

Is there a iLogic rule to Opne, Save (as stp and PDF) , delete olde versions, and close the file. I whant to start the rule from a assembly file, and i have 3 parts to be saved as stp and PDF. I have this rule, but with this i open, save, and close the part. The old parts are in the folder. (this rule save the parts as "Position X" , where X is a parameter from excel)

 

When i save ther rule as "Positon 3" Position 2 shuld be deleted.

 

So, i need to have 3 PDF and 3 STEPS from the current position

 

Here is a rule that save as STP (Position = parameter from excel)

 

'get the part
part = Component.InventorComponent("Glashalter mittig:1")
'open the part
doc = ThisApplication.Documents.Open(part.Definition.Document.FullDocumentName)
'oPath = ThisDoc.Path & "\"
' save the part as step
' doc.SaveAs(oPath & "Glashalter mitte position_" & Position & ".stp" , True)
stp1=doc.SaveAs("C:\Users\Aleksandar.Jovicic\Desktop\FGL\Fertigung\Glashalter\Glashalter mitte " & Position $".stp" , True)
' close the part
doc.Close()

0 Likes
1,573 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Have you tried this?

 

SyntaxEditor Code Snippet

        Try
            My.Computer.FileSystem.DeleteFile(*FULL PATH OF FILE YOU WISH TO DELETE*)
            Catch
            MessageBox.Show(DeleteFile & vbLf & " . . . can not delete file, or file not found.", "iLogic")
        End Try

 

0 Likes
Message 3 of 7

Anonymous
Not applicable

Hi and thank you for the reply!

 

can you PLEASE writhe down the colde in combine with my to know how the cold shuld look like. My folder path is is:

 

"C:\Users\Aleksandar.Jovicic\Desktop\FGL\Fertigung\Glashalter" (delete old versions of PDF and STP)

0 Likes
Message 4 of 7

Anonymous
Not applicable

I guess it'd be something like this

 

        Try
            My.Computer.FileSystem.DeleteFile("C:\Users\Aleksandar.Jovicic\Desktop\FGL\Fertigung\Glashalter\Glashalter mitte " & (Position-1) &".stp")
            Catch
            MessageBox.Show(DeleteFile & vbLf & " . . . can not delete file, or file not found.", "iLogic")
        End Try

 

Hope it helps

0 Likes
Message 5 of 7

MechMachineMan
Advisor
Advisor

Dim oFiles As String()

Dim oFile As File

 

oFiles = System.IO.File.GetFiles(oYourFolder, "*.ipt") 'Or other file type

 

For Each oFile in oFiles 

 

      'String operations to shrink down the file name to whatever is after the last parenthesies

 

             If 'condition for delete here

                            System.IO.File.Delete(oFullFileName of file to delete)
             End if

Next

 

https://msdn.microsoft.com/en-us/library/system.io.file%28v=vs.110%29.aspx

          


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 6 of 7

Anonymous
Not applicable

Hello MechMachineMan and thank you for the replay

 

When i use the rule i bekomme a erro in this part:

 

oFiles = System.IO.File.GetFiles(oYourFolder, "*.pdf") 'Or other file type

 

should this park look like this:

 

oFiles = System.IO.File.GetFiles("C:\Users\user\Desktop\ Glashalter mitte", "*.pdf") 'Or other file type

 

or?

 

 

0 Likes
Message 7 of 7

MechMachineMan
Advisor
Advisor
I believe so, yeah. The oYourFolder is just in there as the variable string
to represent whatever you want it to be. I also added the link so you can
check out the syntax for yourself.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes