Browse folder path using ilogic

Browse folder path using ilogic

karram
Advocate Advocate
1,490 Views
9 Replies
Message 1 of 10

Browse folder path using ilogic

karram
Advocate
Advocate

Hello,

 

How to create browser button and add folder path using ilogic?

karram_0-1709152352207.png

 

0 Likes
Accepted solutions (2)
1,491 Views
9 Replies
Replies (9)
Message 2 of 10

A.Acheson
Mentor
Mentor

Hi @karram 

See solved post here. Kudos up the origional post if it solves your question. 

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

karram
Advocate
Advocate

Hello,

 

Thanks for the solved items code, its works perfectly.

 

But my case after open the folder, i need to select only drawings files (*.idw) and then i add my other requirement rules, like >> For Example:  all open drawings i delete particular sketched symbol..... like other performance.

So i need open folder and select drawings files.

Thanks.

Below is solved code as per your link

 

Imports System.Windows.Forms
Dim filepath As String = "K:\"
Dim selectedfolder As String
Dim oFolderDlg As New FolderBrowserDialog
oFolderDlg.SelectedPath = filepath
Dim oResult As DialogResult = oFolderDlg.ShowDialog()
If oResult = DialogResult.OK
	selectedfolder = oFolderDlg.SelectedPath
End If
Try
Process.Start(selectedfolder)
Catch
End Try
0 Likes
Message 4 of 10

A.Acheson
Mentor
Mentor
Accepted solution

If you want to select files then use the inventor dialogue in the help files here. Change the extension to filter for drawings. You will likely find a version on this forum allready modified for multiple file selection also. Or just poke around with the options in this one and learn  little. 

    ' Create a new FileDialog object.
    Dim oFileDlg As FileDialog
    Call ThisApplication.CreateFileDialog(oFileDlg)

    ' Define the filter to select part and assembly files or any file.
    oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"

    ' Define the part and assembly files filter to be the default filter.
    oFileDlg.FilterIndex = 1

    ' Set the title for the dialog.
    oFileDlg.DialogTitle = "Open File Test"

    ' Set the initial directory that will be displayed in the dialog.
    oFileDlg.InitialDirectory = "C:\Temp"

    ' Set the flag so an error will be raised if the user clicks the Cancel button.
    oFileDlg.CancelError = True

    ' Show the open dialog.  The same procedure is also used for the Save dialog.
    ' The commented code can be used for the Save dialog.
    On Error Resume Next
    oFileDlg.ShowOpen
'    oFileDlg.ShowSave

    ' If an error was raised, the user clicked cancel, otherwise display the filename.
    If Err Then
        MsgBox "User cancelled out of dialog"
    ElseIf oFileDlg.FileName <> "" Then
        MsgBox "File " & oFileDlg.FileName & " was selected."
    End If

 

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

karram
Advocate
Advocate

Above code works fine and open the folder, but i am not able to select multiple files (drawings) and also not able to open the drawings.

If i click open button, its not works.

0 Likes
Message 6 of 10

A.Acheson
Mentor
Mentor

That sample shown earlier is the generic sample so you need to customize to what you need.  See image below, once the object is declared you can see all the methods available. 

AAcheson_0-1709234745887.png

 

One specific for drawings. 

'present a File Selection dialog
	Dim oFileDlg As Inventor.FileDialog = Nothing
	InventorVb.Application.CreateFileDialog(oFileDlg)
	
	oFileDlg.CancelError = True
	oFileDlg.MultiSelectEnabled = True
	oFileDlg.ShowQuickLaunch = True
	
	' Define the filter to select files 
	oFileDlg.Filter = "Inventor Drawing Files (*.idw;*.dwg)|*.idw;*.dwg"
	
	' Set the title for the dialog.
	oFileDlg.DialogTitle = "Choose the files to work with."
	
	On Error Resume Next
	'oFileDlg.ShowSave()
	oFileDlg.ShowOpen()
	
	If Err.Number <> 0 Then
	Return
	ElseIf oFileDlg.FileName <> "" Then
		selectedfiles = oFileDlg.FileName
	End If
	
	' Split the string on the vertical bar character.
	Dim sFiles As String() = selectedfiles.Split(New Char() {"|"c})
	
	'Loop through result strings with For Each.
	For Each sFile  As String In sFiles
		Logger.Info("Drawing File.", sFile)
	Next

 

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

karram
Advocate
Advocate

Now multiple drawings files selected thanks, but not able to open the drawings in inventor. If i select the multiple drawings and click open no operation carried.

0 Likes
Message 8 of 10

A.Acheson
Mentor
Mentor

The purpose of the dialogue is to return file paths not to open the files. Your recreating the User Interface by code so you need to open the files by code also. The line below needs to be inserted in the for loop. Did the logger statement show you the correct file paths? 

 

ThisApplication.Documents.Open(filepath,True) 

 

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

karram
Advocate
Advocate

Also now i add delete sketched symbol in end of the browser folder path code.

how can i add and merge the code. can you help

My requirements:

1. Open browser folder as working space.

2. Select the drawings files as per the requirements and selected file to be open.

3. Then targeted sketched symbol delete my open drawings.

4. Save and close

 

'present a File Selection dialog
	Dim oFileDlg As Inventor.FileDialog = Nothing
	InventorVb.Application.CreateFileDialog(oFileDlg)
	
	oFileDlg.CancelError = True
	oFileDlg.MultiSelectEnabled = True
	oFileDlg.ShowQuickLaunch = True
	
	' Define the filter to select files 
	oFileDlg.Filter = "Inventor Drawing Files (*.idw;*.dwg)|*.idw;*.dwg"
	
	' Set the title for the dialog.
	oFileDlg.DialogTitle = "Choose the files to work with."
	
	On Error Resume Next
	'oFileDlg.ShowSave()
	oFileDlg.ShowOpen()
	
	If Err.Number <> 0 Then
	Return
	ElseIf oFileDlg.FileName <> "" Then
		selectedfiles = oFileDlg.FileName
	End If
' Specify the name of the sketched symbol you want to delete
targetSymbolName = "Reference document No"

' Loop through all drawing files in the folder

While drawingFile <> ""
    ' Open each drawing document
    Dim oDoc As DrawingDocument
    oDoc = ThisApplication.Documents.Open(folderPath & drawingFile, True)
    
    ' Check if the document is a drawing
    If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
        ' Loop through all sheets in the drawing
		For Each oSymbol In oDoc.ActiveSheet.SketchedSymbols
	'look for the symbol by name
	If oSymbol.Name = "Reference document No" Then
		oSymbol.Delete
	End If
Next 

        oDoc.Save()
        oDoc.Close()
    End If
    
    ' Get the next drawing file in the folder
    drawingFile = Dir
End While

MsgBox("Deletion of specific sketched symbols completed for all drawings in the folder.", MsgBoxStyle.Information, "Complete")

 

0 Likes
Message 10 of 10

A.Acheson
Mentor
Mentor
Accepted solution

The code you worked in over here in this other post is more complete than the one supplied in this post so please work with the other post rather than duplicate. 

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