iLogic oFileDlg Place Component

iLogic oFileDlg Place Component

dusan.naus.trz
Advisor Advisor
507 Views
4 Replies
Message 1 of 5

iLogic oFileDlg Place Component

dusan.naus.trz
Advisor
Advisor

I need to insert a part into an assembly via iLogic.
I need to bring up the insert component dialog. I always select the component manually in the dialog box.
After inserting the component, an iProperty is created with a value.
I looked in the API Help and didn't find anything. FileDialog Object

 

'define the active document
oDoc = ThisDoc.Document
'create a file dialog box
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)

'check file type and set dialog filter
If oDoc.DocumentType = kPartDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
Else If oDoc.DocumentType = kDrawingDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw"
End If

'set the directory to open the dialog at
oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()
'set the file name string to use in the input box
'oFileDlg.FileName = iProperties.Value("Custom", "Saved By")& "-" & iProperties.Value("Custom", "Date Saved") & "-" & iProperties.Value("Custom", "Time Saved")

'work with an error created by the user backing out of the save
oFileDlg.CancelError = True
On Error Resume Next
'specify the file dialog as a save dialog (rather than a open dialog)
'oFileDlg.ShowSave()
'oFileDlg.ShowOpen()
oFileDlg.ShowPlaceComponent()???????????????????????????????????????????

'catch an empty string in the imput
If Err.Number <> 0 Then
'MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
ElseIf oFileDlg.FileName <> "" Then
MyFile = oFileDlg.FileName
'save the file
'ThisApplication.Documents.Open(oFileDlg.FileName)
'oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As
End If

MessageBox.Show(oFileDlg.FileName, "Title")

 

2022-12-22_18h24_32.png

0 Likes
Accepted solutions (2)
508 Views
4 Replies
Replies (4)
Message 2 of 5

dusan.naus.trz
Advisor
Advisor

2022-12-22_18h54_44.png

0 Likes
Message 3 of 5

JelteDeJong
Mentor
Mentor
Accepted solution

Try it like this:

Dim dialog As Inventor.FileDialog = Nothing
ThisApplication.CreateFileDialog(dialog)

dialog.DialogTitle = "Place Component"
dialog.ShowOpen()

MsgBox(dialog.FileName)

Dim position As Matrix = ThisApplication.TransientGeometry.CreateMatrix()

Dim doc As AssemblyDocument = ThisDoc.Document
doc.ComponentDefinition.Occurrences.Add(dialog.FileName, position)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 4 of 5

dusan.naus.trz
Advisor
Advisor

Hi,
Thank you for answer.
You're missing this. Highlighted in red.

 

Dim dialog As Inventor.FileDialog = Nothing
ThisApplication.CreateFileDialog(dialog)

dialog.Filter = "All Files (*.*)|*.*"

dialog.DialogTitle = "Place Component"
dialog.ShowOpen()

MsgBox(dialog.FileName)

Dim position As Matrix = ThisApplication.TransientGeometry.CreateMatrix()

Dim doc As AssemblyDocument = ThisDoc.Document
doc.ComponentDefinition.Occurrences.Add(dialog.FileName, position)

 

0 Likes
Message 5 of 5

dusan.naus.trz
Advisor
Advisor
Accepted solution

Thank you very much for the inspiration.
I am sending my version.

 

Dim dialog As Inventor.FileDialog = Nothing
ThisApplication.CreateFileDialog(dialog)

dialog.Filter = "All Files (*.*)|*.*"

dialog.DialogTitle = "Place Component"
dialog.ShowOpen()

'MsgBox(dialog.FileName)

'definuj nazev komponenty
'Dim doc As Document
Dim CurFileName As String
'get the selected item document occurrence name
'doc = comp.Definition.Document
'get the path and file name of the selected item
CurFileName = dialog.FileName'doc.FullFileName
'defines backslash as the subdirectory separator
Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar
'find the postion of the last backslash in the path
FNamePos = InStrRev(CurFileName, "\", -1)
'get the file name with the file extension
Name = Right(CurFileName, Len(CurFileName) -FNamePos)
'get the file name (without extension)
ShortName = Left(Name, Len(Name) -4)
'get the path of the folder containing the file
Folder_Location = Left(CurFileName, Len(CurFileName) -Len(Name))
'MessageBox.Show("File Name: " & Name _
'& vbLf & "File Name without extension: " & ShortName _
'& vbLf & "File Path: " & Folder_Location _
'& vbLf & "Path and File Name: " & CurFileName, "iLogic")

'MessageBox.Show(Name, "Title")
'Dim position As Matrix = ThisApplication.TransientGeometry.CreateMatrix()

'Dim doc As Document = ThisDoc.Document
'doc.ComponentDefinition.Occurrences.Add(dialog.FileName, position)

iProperties.Value(Name, "Custom", "TEST") = "OK"
ThisDoc.Save

ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,CurFileName) 
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute
0 Likes