How to make rule, that can adapt to the partnumber in the "partname"

How to make rule, that can adapt to the partnumber in the "partname"

r_swaczyna
Observer Observer
244 Views
2 Replies
Message 1 of 3

How to make rule, that can adapt to the partnumber in the "partname"

r_swaczyna
Observer
Observer

Hello,

 

so a year ago I made some ilogic rules for our department that take parts of our naming and put these parts into the correct iproperties automatically, inventor now automatically fills in the parts of our titleblock.

That was relatively easy, because a big part of the naming was constantly the same length.

 

It looked like this

123 123456 12 123 1 Partname

So the "partnumber" was always the same length and that was the base for the rules. The rules are will read the partnumber, revisionnumber and the partname.

 

Because we now have partnumbers, that have partnumbers with a different length, that rules only work for about 70% of our project.

To be precise we now have two lengths of partnumbers

123 123456 12 123 1 Partname

and

1234 123456 12 123 1 Partname

 

So my question is, is there a possibility to make the rules identify the length of the partnumber?

 

Btw here is an example code for the partnumber, I know its probably not good, but it works

 

If Len(ThisDoc.FileName(False)) > 21 Then
	Partnumber = 17
	iProperties.Value("Project", "Part Number") = Left(ThisDoc.FileName(False), Partnumber) & " "

 iLogicVb.UpdateWhenDone = True 

End If
0 Likes
Accepted solutions (1)
245 Views
2 Replies
Replies (2)
Message 2 of 3

aurel_e
Collaborator
Collaborator
Accepted solution

Try the rule below.

It is going to find the 5th space in the ParName and copy all the string before that independently of the number of digits in the first part.

If Len(ThisDoc.FileName(False)) > 21 Then
    Dim fileName As String = ThisDoc.FileName(False)
    Dim spaceCount As Integer = 0
    Dim spaceIndex As Integer = 0
    
    ' Find the 5th space in the file name
    For i As Integer = 1 To Len(fileName)
        If Mid(fileName, i, 1) = " " Then
            spaceCount += 1
            If spaceCount = 5 Then
                spaceIndex = i
                Exit For
            End If
        End If
    Next
    
    If spaceIndex > 0 Then
        ' Extract the numeric part before the 5th space
        Dim numericPart As String = Left(fileName, spaceIndex - 1)
        
        ' Set the Part Number property
        iProperties.Value("Project", "Part Number") = numericPart
    End If
End If

iLogicVb.UpdateWhenDone = True
Message 3 of 3

r_swaczyna
Observer
Observer

That works, thank you very much.

Already adapted the code for partnames and revision number.

 

 

 

0 Likes