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: 

iLogic: show list of all array items in a messagebox

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Neuzzo
2991 Views, 3 Replies

iLogic: show list of all array items in a messagebox

Hi all, i've this ilogic macro to set a custom iProp of each ipt in an assembly.

 

All works fine but i want a control for exist iProp  when if exist it add the Part number to an array and at the end show all parts number in a msgbox.

Now it show a windows of each part, how i can show all array list in a same msgbox? Thank you

 

Sub Main ()
'Create variables'set a reference to the assembly component definintion
Dim oAssDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim ExcelFullName As String
Dim FileName As String
Dim ListaEsistenti As New ArrayList
Dim oStringList As String



Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.InitialDirectory = oOrigRefName
oFileDlg.CancelError = True

oFileDlg.ShowOpen()
If Err.Number <> 0 Then
Return
ElseIf oFileDlg.FileName <> "" Then
ExcelFullName = oFileDlg.FileName
End If

'Open Excel database
GoExcel.Open(ExcelFullName,"DISTINTA BASE")

'Iterate through each referenced document'Dim oOcc As ComponentOccurrence
    For Each oDoc As Document In oAssDoc.AllReferencedDocuments
    ErHa = "Start"
    Try
        'Extract Part Number of active occurrence 
        Dim oPropSet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
        oPartNumber = Left(oDoc.DisplayName, Len(oDoc.DisplayName) - 4) '(Left(oDoc.DisplayName) -4)
		oPartNumber1 = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
                    

    ErHa = "Define custom property collection"
        Parameter.UpdateAfterChange = True       
        i = GoExcel.FindRow(ExcelFullName, "DISTINTA BASE", "Part Number", "=", oPartNumber1)
		
		If i = "-1" 
			GoTo PROSSIMO
		End If
		
		Dim COSTO As String = GoExcel.CurrentRowValue("Unit price €")
        If GetProperty(oPropSet, "Costo").Value Is Nothing Then
		GetProperty(oPropSet, "Costo").Value = COSTO
		GetProperty(oPropSet, "Tipo ricambio").Value = "R"
		GoTo PROSSIMO
		Else
        ListaEsistenti.Add(oPartNumber1)
        End If
		

    ErHa = "Update the file"
        iLogicVb.UpdateWhenDone = True
        Catch ex As Exception
        MsgBox("Part: " & oDoc.DisplayName & vbLf & "Code-Part: " & ErHa & vbLf & "Error: " & ex.Message)  
    
    End Try
PROSSIMO:
    Next 
	
		For Each oStringList In ListaEsistenti
		MessageBox.Show(oStringList & vbLf)
		Next

	
'Close Excel database
GoExcel.Close

End Sub

Private ErHa As String = vbNullString

Function GetProperty(oPropset As PropertySet, iProName As String) As Inventor.Property
    ErHa = "GetProperty: " & iProName
    Dim iPro As Inventor.Property
    Try
        'Attempt to get the iProperty from the document
        iPro = oPropset.Item(iProName)
    Catch
        'Assume error means not found, so create it
        iPro = oPropset.Add("", iProName)
    End Try
    Return iPro
End Function

Thank you!

Danilo "DannyGi" G.
Mechanical design engineer and product developer
3 REPLIES 3
Message 2 of 4
Sergio.D.Suárez
in reply to: Neuzzo

Ciao, dato che non ho i tuoi file, non riesco a creare e testare la tua regola. Allora, condividerò con te un metodo in modo che tu possa fare ciò che stai cercando di ottenere, questo codice prenderà i nomi di tutti i file di riferimento e li aggiungerà alla finestra di messaggio.

 

Dim oAssDoc As AssemblyDocument = ThisApplication.ActiveDocument

Dim ListaEsistenti As New ArrayList
Dim oText As String 


For Each oDoc As Document In oAssDoc.AllReferencedDocuments
	ListaEsistenti.Add(oDoc.DisplayName)
Next


For i As Integer = 0 To ListaEsistenti.Count - 1
	If i = 0 Then 
		oText = ListaEsistenti(i)
	Else
		oText = oText & vbLf & ListaEsistenti(i)
	End If
Next



MessageBox.Show(oText)

 Spero che questo ti aiuti a sviluppare il tuo codice.
In bocca al lupo!
Arrivederchi!


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 4
Neuzzo
in reply to: Sergio.D.Suárez

I've use your code in my ilogic macro, it works!

 

Grazie, sei stato davvero gentile

Danilo "DannyGi" G.
Mechanical design engineer and product developer
Message 4 of 4
Anonymous
in reply to: Sergio.D.Suárez

Hey Sergio, I have a similar issue

 

Here's my code

 

I too want to print the entire array in 1 text box.

 

Dim A = Parameter("Horizontal Connector Bar:1", "horizontal_length")
Dim B = New Object(){0, 1, 2, 3, 4}
'Where 0 = Free, 1 = Corner cut, 2 = Pin, 3 = Handle, 4 = Driver, 5 = Reversed Driver
Dim oText As String
Dim BarV1 (0 To A, 0) As String

BarV1(0, 0) = 1
BarV1(10 mm, 0) = 2
BarV1(Parameter("Horizontal Connector Bar:1", "Handle_slot"), 0) = 3 
BarV1(Parameter("Horizontal Connector Bar:1", "h_set1"), 0) = 4
BarV1((Parameter("Horizontal Connector Bar:1", "horizontal_length") - 10 mm), 0) = 2
BarV1(Parameter("Horizontal Connector Bar:1", "horizontal_length"), 0) = 1

Dim List1 As New ArrayList

For Each Var In BarV1
	List1.Add(BarV1)
Next

For i As Integer = 0 To List1.Count - 1
	If i = 0 Then
		oText = List1(i)
	Else
		oText = oText & vbLf & List1(i)
	End If
Next
MessageBox.Show(oText)


Could you tell me as to what I am doing wrong?

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report