Split Custom iProperty every 30 characters

Split Custom iProperty every 30 characters

Anonymous
Not applicable
512 Views
3 Replies
Message 1 of 4

Split Custom iProperty every 30 characters

Anonymous
Not applicable

I don’t know if I’m even going down the right path. I’m try to take a custom iproperty and split it every 30 characters (spaces count as a character). From there I would like it to make a custom iproperty for every 30 characters line. If it’s splits in the middle of a word of number I would like it to go to the space before the last 30 characters word or number.

 

For Example:

 

     The custom iproperty (TF BOM) =

 

     GRAYLOC HUB, 2INB14, BW, NON-RECESSED, 2.375 OD X 1.939 ID; W/ .125 THK INCONEL 625 WELD OVERLAY ON SEALING SURFACE

 

I would like the make custom iproperty that split it (spaces count as a character):

 

                Custom iproperty (Line 1) = GRAYLOC HUB, 2INB14, BW,                         (25 characters counting last space)

                Custom iproperty (Line 2) = NON-RECESSED, 2.375 OD X 1.939               (30 characters counting last space)   

                Custom iproperty (Line 3) = ID; W/ .125 THK INCONEL 625                      (28 characters counting last space)

                Custom iproperty (Line 4) = WELD OVERLAY ON SEALING                        (24 characters counting last space)

                Custom iproperty (Line 5) = SURFACE                                                                                        (7 characters)

 

Our attempt at writhing the code below. It kind of works but has problems when it comes to spaces.

 

SyntaxEditor Code Snippet

DL1 = " " & Split(StrReverse(Left(iProperties.Value("Custom", "TF BOM"),30)))(1) & " "

iProperties.Value("Custom", "Line 1") = Split(iProperties.Value("Custom", "TF BOM"), DL1)(0) & DL1
iProperties.Value("Custom", "Line 2") = Split(iProperties.Value("Custom", "TF BOM"), DL1)(1)
iProperties.Value("Custom", "Line 3") = Split(iProperties.Value("Custom", "TF BOM"), DL1)(2)
iProperties.Value("Custom", "Line 4") = Split(iProperties.Value("Custom", "TF BOM"), DL1)(3)
iProperties.Value("Custom", "Line 5") = Split(iProperties.Value("Custom", "TF BOM"), DL1)(4)

 

I would appreciate any help you might be able to give.

0 Likes
Accepted solutions (1)
513 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

This code is getting closer to what we need but still have some issues with it. 

 

If anyone could help that would be awesome. Thanks

 

SyntaxEditor Code Snippet

Try

DL1 = Len(Split(StrReverse(Left(iProperties.Value("Custom", "TF BOM"),30)))(0))+1
DL2 = Len(Split(StrReverse(Left(iProperties.Value("Custom", "TF BOM"),60-DL1)))(0))+1
DL3 = Len(Split(StrReverse(Left(iProperties.Value("Custom", "TF BOM"),90-(DL1+DL2))))(0))+1
DL4 = Len(Split(StrReverse(Left(iProperties.Value("Custom", "TF BOM"),120-(DL1+DL2+DL3))))(0))+1


iProperties.Value("Custom", "PK Extended Item Line 1") = Left(iProperties.Value("Custom", "TF BOM"),30-DL1)

iProperties.Value("Custom", "PK Extended Item Line 2") = Mid(iProperties.Value("Custom", "TF BOM"),32-DL1,30-DL2)

iProperties.Value("Custom", "PK Extended Item Line 3") = Mid(iProperties.Value("Custom", "TF BOM"),62-(DL1+DL2),30-DL3)

iProperties.Value("Custom", "PK Extended Item Line 4") = Mid(iProperties.Value("Custom", "TF BOM"),92-(DL1+DL2+DL3),30-DL4)

Catch
End Try

 

 

0 Likes
Message 3 of 4

ekinsb
Alumni
Alumni
Accepted solution

I wrote a little function to split up the string into strings of a specified length.  Below is the complete iLogic rule with the function.

 

Sub Main()
    Dim pieces() As String = BreakString(iProperties.Value("Custom", "TF BOM"), 30)
	
    Dim count As Integer = 1
    For Each piece As String in pieces
        iProperties.Value("Custom", "PK Extended Item Line " & count) = piece
        count += 1
    Next
End Sub


Private Function BreakString(Input As String, maxChars As Integer) As String()
    Dim pieces() As String = Input.Split(" ")
    Dim result() As String
    ReDim result(200)

    Dim resultCount As Integer = 0
    result(resultCount) = ""
    For Each piece As String In pieces
        If piece.Length + result(resultCount).Length < maxChars Then
            If result(resultCount) = "" Then
                result(resultCount) = piece
            Else
                result(resultCount) &= " " & piece
            End If
        Else
            resultCount += 1
            result(resultCount) = piece
        End If
    Next

    ReDim Preserve result(resultCount)
    Return result
End Function

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 4 of 4

Anonymous
Not applicable

That works great. Thank you very much for your help.

0 Likes