iLogic: get part number instead file name

iLogic: get part number instead file name

Neuzzo
Advocate Advocate
2,525 Views
6 Replies
Message 1 of 7

iLogic: get part number instead file name

Neuzzo
Advocate
Advocate

Hi, i've modify this iLogic macro for my use.

 

Now the macro compare from an excel file the value of part number in my assembly.

If part match, it write a custom iProp. All works.

 

But it work on a file name. I need to do it with part number and not the file name. But i don't find the value to get this param.

 

Can someone help me? Thanks in advance

 

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 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)
                    
        'MessageBox.Show(oPartNumber)

    ErHa = "Define custom property collection"
        Parameter.UpdateAfterChange = True       
        i = GoExcel.FindRow(ExcelFullName, "DISTINTA BASE", "Part Number", "=", oPartNumber)
		
		If i = "-1" 
			GoTo PROSSIMO
		End If
		
		Dim COSTO As String = GoExcel.CurrentRowValue("Unit price €")
        If String.IsNullOrEmpty(COSTO) Then
        GetProperty(oPropSet, "Costo").Value = ""
        Else
        GetProperty(oPropSet, "Costo").Value = COSTO
		GetProperty(oPropSet, "Tipo ricambio").Value = "C"
        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 
'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

This is the function

 

'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)
Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes
Accepted solutions (1)
2,526 Views
6 Replies
Replies (6)
Message 2 of 7

Neuzzo
Advocate
Advocate

Up?

Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes
Message 3 of 7

Curtis_Waguespack
Consultant
Consultant

@Neuzzo wrote:

Up?


Hi @Neuzzo 

Programming questions of this type are better asked on the Inventor Customization forum :
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

You can use the REPORT button to ask the Admin staff to move your post to that forum.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 4 of 7

Neuzzo
Advocate
Advocate

Uhm ok, thank you. I ask for a topic move.

Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes
Message 5 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@Neuzzo wrote:

Uhm ok, thank you. I ask for a topic move.


To your question though, I think you can just use this:

 

oPartNumber = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 6 of 7

Neuzzo
Advocate
Advocate

You're the man! Thank you

Danilo "DannyGi" G.
Mechanical design engineer and product developer
0 Likes
Message 7 of 7

john.vanderhoven
Contributor
Contributor

Hi, sorry dont see how this answers my request.

0 Likes