Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pop-up menu to select different 'Note' file

2 REPLIES 2
Reply
Message 1 of 3
Fazlur_Rahaman
75 Views, 2 Replies

Pop-up menu to select different 'Note' file

Hey guys ,

 

I found this code below from ClientBrown3D website

https://clintbrown.co.uk/2019/04/20/drawing_notes_ilogic/

 

And i was wondering if there is a way to have a pop-up window that would allow you to choose different Notepad file and place the notes from that file in to the drawing.

 

Here is the full code from his website:

 

'iLogic code by Clint Brown @ClintBrown3D
'Originally posted at https://clintbrown.co.uk/Drawing_Notes_iLogic

SetNotePath = "C:\TEMP\Notes.txt"

' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
 oDrawDoc = ThisApplication.ActiveDocument

'  a reference to the active sheet.
Dim oActiveSheet As Sheet
 oActiveSheet = oDrawDoc.ActiveSheet

'  a reference to the GeneralNotes object
Dim oGeneralNotes As GeneralNotes
 oGeneralNotes = oActiveSheet.DrawingNotes.GeneralNotes

Dim oTG As TransientGeometry
 oTG = ThisApplication.TransientGeometry

'----------READ IN DATA From TEXT File --------------------
oRead = System.IO.File.OpenText(SetNotePath)
EntireFile = oRead.ReadToEnd()
oRead.Close()
Dim sText As String	
sText = EntireFile 
'----------READ IN DATA From TEXT File --------------------

Dim oGeneralNote As GeneralNote
'oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(3, 40), sText) 'Top Left
'oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(50, 40), sText) 'Top Right
oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(50, 8), sText) 'Bottom Right
'oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(3, 6), sText) 'Bottom Left
Tags (2)
Labels (2)
2 REPLIES 2
Message 2 of 3

I recommend you to enclose the original code to method Main and wrap the browse for file to separate method for better readability of the code. In this new method you can use standard file dialog for selecting the text file.

 

Sub Main()
    'iLogic code by Clint Brown @ClintBrown3D
    'Originally posted at https://clintbrown.co.uk/Drawing_Notes_iLogic

    Dim SetNotePath = BrowseForFile()

    '...
    ' The rest of the original code
End Sub

Private Function BrowseForFile() As String
    Dim fileDialog As Inventor.FileDialog
    ThisApplication.CreateFileDialog(fileDialog)
    fileDialog.Filter = "Text files|*.txt|All files|*.*"
    fileDialog.DialogTitle = "Select text file"

    fileDialog.ShowOpen()

    Return fileDialog.FileName
End Function

 

 

Message 3 of 3

I was able to combine the above code with the one from @WCrihfield and accomplish what i needed to do. 

 

https://forums.autodesk.com/t5/inventor-programming-ilogic/multiselectlistbox-based-on-ilogic-s-inpu...

 

P.S. Im sure there is better way of doing this, with my limited knowledge about iLogic, this is good enough for me. Feel free to add your improved version below if you think it will help someone.

Sub Main
	Dim oList As New List(Of String) From {"Note 1", "Note 2", "Note 3" }
	Dim Selected As IEnumerable(Of Object) = MultiSelectListBox("Select Some", oList, Nothing, "Multi-Select InputListBox", "My List")
	If Selected.Count = 0 Then
		MessageBox.Show("Nothing was selected from the list.", "None Selected",MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
	Else
		For Each Item In Selected
			'MessageBox.Show("You selected:  " & Item.ToString, "Selected", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
			If Item.ToString = "Note 1" Then 
				SetNotePath = "C:\TEMP\Notes1.txt"
				
			Else If Item.ToString = "Note 2" Then
				SetNotePath = "C:\TEMP\Notes2.txt"
			
			Else If Item.ToString = "Note 3" Then
				SetNotePath = "C:\TEMP\Notes3.txt"
			
			End If	
				
				

' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
 oDrawDoc = ThisApplication.ActiveDocument

'  a reference to the active sheet.
Dim oActiveSheet As Sheet
 oActiveSheet = oDrawDoc.ActiveSheet

'  a reference to the GeneralNotes object
Dim oGeneralNotes As GeneralNotes
 oGeneralNotes = oActiveSheet.DrawingNotes.GeneralNotes

Dim oTG As TransientGeometry
 oTG = ThisApplication.TransientGeometry

'----------READ IN DATA From TEXT File --------------------
oRead = System.IO.File.OpenText(SetNotePath)
EntireFile = oRead.ReadToEnd()
oRead.Close()
Dim sText As String	
sText = EntireFile 
'----------READ IN DATA From TEXT File --------------------

Dim oGeneralNote As GeneralNote
oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(20, 8), sText) 'Bottom Right
		Next
	End If
End Sub

Function MultiSelectListBox(Optional Instructions As String = vbNullString, Optional Items As IEnumerable = Nothing,
Optional DefaultValue As Object = Nothing, Optional Title As String = vbNullString, Optional ListName As String = vbNullString) As IEnumerable(Of Object)
	Using oILBD As New Autodesk.iLogic.Runtime.InputListBoxDialog(Title, ListName, Instructions, Items, DefaultValue)
		Dim oLB As System.Windows.Forms.ListBox = oILBD.Controls.Item(0).Controls.Item(2)
		oLB.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple
		Dim oDlgResult As System.Windows.Forms.DialogResult = oILBD.ShowDialog()
		Dim oSelected As IEnumerable(Of Object) = oLB.SelectedItems.Cast(Of Object)
		Return oSelected
	End Using
End Function

 

 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report