Delete other files to workspace folder

Delete other files to workspace folder

ksmYFC8W
Explorer Explorer
571 Views
3 Replies
Message 1 of 4

Delete other files to workspace folder

ksmYFC8W
Explorer
Explorer

어셈블리 환경에 하위 부품이 있습니다.
작업을 많이 할 때 작업 공간에 어셈블리 부품 이외의 부품이 있으므로 별도로 삭제합니다.

작업 공간에 불필요한 파일, 내가 삭제할 수 있는 VBA 또는 iLogic을 갖고 싶은 스캐너 하위 부분만 남깁니다.
그러나 나는이 부분에 익숙하지 않다.


나는 당신의 도움이 필요합니다.

0 Likes
Accepted solutions (1)
572 Views
3 Replies
Replies (3)
Message 2 of 4

A.Acheson
Mentor
Mentor

English Translation: 

I have sub-components in the assembly environment.

When I do a lot of work, I have parts other than assembly parts in my workspace, so I delete them separately.

 

It leaves only the scanner sub-parts where I want to have unnecessary files in the workspace, VBA or iLogic that I can delete.

But I'm not familiar with this part.

 

Answer:

Although this is not the full solution, I hope you can find these two post useful.

 You could loop through the main assembly and check the filepath and if it doesn’t match the folder path delete those.  You could also just move them to a folder called obsolete in case you need to recover the old version. 

Here is a link to a post to look at a folder and loop through the files and delete those under a certain condition. See message 5 in link below

 

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/ilogic-rule-for-deleting-or-replacing-f...

 

 

Here is a post to work with the assembly, you can use the all referenced document rule and get the full file path

 

https://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 4

A.Acheson
Mentor
Mentor
Accepted solution

Here is a rule to combine the two previous methods discussed. It will only work if the files are in a flat storage workspace folder but can be changed to suit other folder structure. 

Sub Main
	
	Dim AssyFiles As New ArrayList
	Dim oWPath As String
	oWPath = ThisDoc.Path
	
	AssyLoop(oWPath,AssyFiles)
	CleanWorkspaceFolder(oWPath,AssyFiles)
End Sub

 
Sub AssyLoop(oWPath As String, AssyFiles As ArrayList)

    ' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument
  	oAsmDoc = ThisApplication.ActiveDocument
	 
	Dim oAsmDocFullName As String
	oAsmDocFullName = ThisDoc.ModelDocument.FullDocumentName
	
	AssyFiles.add(oAsmDocFullName)
    
	' Get all of the referenced documents.
    Dim oRefDocs As DocumentsEnumerator
 	oRefDocs = oAsmDoc.AllReferencedDocuments

    ' Iterate through the list of documents.
    Dim oRefDoc As Document
    For Each oRefDoc In oRefDocs
		If oRefDoc.FullDocumentName.Contains(oWPath)
         'Logger.Info(oRefDoc.FullDocumentName)
		 AssyFiles.add(oRefDoc.FullDocumentName)
	 	End If
    Next

d0 = InputListBox("Prompt", AssyFiles, d0, Title := "AssyFileList", ListName := "AssyFileList")

End Sub

Sub CleanWorkspaceFolder(oWPath As String, AssyFiles As ArrayList)

Dim oFiles  As String()
Dim oFile As String

oFiles = System.IO.Directory.GetFiles(oWPath) 

For Each oFile In oFiles 
	'Logger.Info("FilesInFolder" & oFile)

	'Get Extension
	Ext = System.IO.Path.GetExtension(oFile)

	'Target only these extensions
	If Ext = ".ipt" Or Ext = ".iam" Then
		'Check if the file in the workspace folder is not contained in the assembly
		If Not AssyFiles.Contains(oFile) = True
			'System.IO.File.Delete(oFile)
			
			'[Move the file
			oFileName = System.IO.Path.GetFileName(oFile)
			oNewDir = oWPath & "\NotUsed"
			oNewFile = oNewDir & "\" & oFileName
			'MessageBox.Show(oNewFile, "oNewFile")
			System.IO.Directory.CreateDirectory(oNewDir)
			System.IO.File.Move(oFile, oNewFile)
			']
		End If
	End If

Next
End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 4 of 4

ksmYFC8W
Explorer
Explorer

Thank you.
It's working well.

I'm very satisfied and grateful once again to be able to utilize a really good function.
It will be very helpful at work.

0 Likes