Create an ilogic rule for round up length

Create an ilogic rule for round up length

eladm
Collaborator Collaborator
1,293 Views
23 Replies
Message 1 of 24

Create an ilogic rule for round up length

eladm
Collaborator
Collaborator

Hi All

I need an ilogic rule for  tube and pipe length 

for example:

eladm_0-1719299310566.png

 

for each pipe when the length (QTY column ) is between 0-4.99 m another column (Item QTY for example) the value will be : 5m .  when the length between 5-9.99 m the value will be 10m , when the length between 10-14.99 m the value will be 15m . If the length will be at inch can it convert to m , and than change the other column value ? 

 

Regards 

 

 

 

0 Likes
Accepted solutions (2)
1,294 Views
23 Replies
Replies (23)
Message 2 of 24

Michael.Navara
Advisor
Advisor

You don't need iLogic for this. You can define new parameter with the following expression. Then you can set this parameter to BOM.

 

ceil(Length / 5 m) * 5 m

 

 

MichaelNavara_0-1719312638096.png

 

0 Likes
Message 3 of 24

nstevelmans
Advocate
Advocate

Hi, maybe this can be start.

 

 Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
        Dim oSheet As Sheet = oDrawDoc.ActiveSheet
        Dim oPartslist As PartsList = oSheet.PartsLists.Item(1)

        Dim rows As PartsListRows = oPartslist.PartsListRows
        Dim row As PartsListRow = Nothing

        Dim Columns As PartsListColumns = oPartslist.PartsListColumns

        'Dim QTY As PartsListColumns = Columns.Item("QTY")

        For Each row In rows
            Dim QTYValue As String = (row.Item("QTY").Value)

            If QTYValue.Contains("in") Then
                Dim cleanString As String = Replace(QTYValue, "in", "")
                Dim QTYValueNew As Double = CDbl(Val(cleanString)) '// Val do hard 
                QTYValueNew = Math.Round((QTYValueNew * 25.4) / 1000, 2)


                row.Item("QTY").Value = CStr(QTYValueNew & " " & "m")
                row.Item("QTY").Static = True

                If QTYValueNew < 5 Then
                    row.Item("ITEM QTY").Value = CStr(5 & " " & "m")
                    row.Item("QTY").Static = True
                End If

                If QTYValueNew >= 5 AndAlso QTYValueNew < 10 Then
                    row.Item("ITEM QTY").Value = CStr(10 & " " & "m")
                    row.Item("QTY").Static = True
                End If

                If QTYValueNew >= 10 AndAlso QTYValueNew < 15 Then
                    row.Item("ITEM QTY").Value = CStr(15 & " " & "m")
                    row.Item("QTY").Static = True
                End If



            End If

        Next

 

 

 

 

0 Likes
Message 4 of 24

eladm
Collaborator
Collaborator

Hi 

The rule didn't do anything 

I need that in the part list :

if the total length of the pipe (after add 5%) the value will be changed to 1,2,3 ...

If the length is 0 – 4.99m the value will need to be 1

If the length is 5 – 9.99m the value will need to be 2

If the length is 10 – 14.99m the value will need to be 3 ...

*** not change the value of the coupling ***

eladm_1-1719488743961.png

regards

0 Likes
Message 5 of 24

nstevelmans
Advocate
Advocate

Hi, try this one

 

Animatie.gif

 

 

 Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
        Dim oSheet As Sheet = oDrawDoc.ActiveSheet
        Dim oPartslist As PartsList = oSheet.PartsLists.Item(1)

        Dim rows As PartsListRows = oPartslist.PartsListRows
        Dim row As PartsListRow = Nothing
        Dim Columns As PartsListColumns = oPartslist.PartsListColumns
        Dim Partslistrows As New List(Of PartsListRow)

        For Each row In rows
            Dim QTYValue As String = (row.Item("QTY").Value)
            If QTYValue.Contains("in") Then
                Dim cleanString As String = Replace(QTYValue, "in", "")
                Dim QTYValueNew As Double = CDbl(cleanString)
                QTYValueNew = Math.Round(QTYValueNew * 25.4, 2)
                row.Item("QTY").Value = CStr(QTYValueNew)
                row.Item("QTY").Static = True
            End If

            If QTYValue.Contains("mm") Then
                Dim cleanString As String = Replace(QTYValue, "mm", "")
                Dim QTYValueNew As Double = CDbl(cleanString)
                QTYValueNew = Math.Round(QTYValueNew, 2)
                row.Item("QTY").Value = CStr(QTYValueNew)
                row.Item("QTY").Static = True
            End If
        Next


        For Each row In rows
            Dim Valuestart As Double = 0
            Dim value2 As Double = 5000
            Dim QTYValue As String = (row.Item("QTY").Value)
            If row.Item("QTY").Static = True Then
                Dim count As Integer = 2
                For i = 1 To 1000
                    Dim QTYValueNew As Double = CDbl(QTYValue)
                    If QTYValueNew < 5000 Then
                        row.Item("QTY").Value = CStr(1)
                        row.Item("QTY").Static = True
                    End If

                    If QTYValueNew >= value2 AndAlso QTYValueNew < value2 * 2 Then
                        row.Item("QTY").Value = CStr(count)
                        row.Item("QTY").Static = True
                    End If
                    value2 = value2 + 5000

                    count = count + 1
                    If value2 > QTYValue Then
                        Exit For
                    End If
                Next
            End If
        Next




 

0 Likes
Message 6 of 24

eladm
Collaborator
Collaborator

Hi

 

Can you add 5% of the length before change  the value ?

Can you add : if the unit is at meter ? ( is the rule only for the unit at inch or mm ? )

If the length is change after run the rule , I need manually to uncheck the static value(in the part list) and rerun the rule ?

regards

0 Likes
Message 7 of 24

nstevelmans
Advocate
Advocate

Hi,  I Modified the code and added the issues

 

Works with mm and inches

You can  update the Assy and rerun the rule

5% tol added

 

 

Animatie.gif

 

 

 Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
        Dim oSheet As Sheet = oDrawDoc.ActiveSheet
        Dim oPartslist As PartsList = oSheet.PartsLists.Item(1)

        Dim rows As PartsListRows = oPartslist.PartsListRows
        Dim row As PartsListRow = Nothing
        Dim Columns As PartsListColumns = oPartslist.PartsListColumns
        Dim Partslistrows As New List(Of PartsListRow)
		
		
		For Each row In rows
            row.Item("QTY").Static = False
        Next

        For Each row In rows
            Dim QTYValue As String = (row.Item("QTY").Value)
            If QTYValue.Contains("in") Then
                Dim cleanString As String = Replace(QTYValue, "in", "")
                Dim QTYValueNew As Double = CDbl(cleanString)
                QTYValueNew = Math.Round(QTYValueNew * 25.4, 2)
				QTYValueNew = QTYValueNew + (QTYValueNew / 20)
                row.Item("QTY").Value = CStr(QTYValueNew)
                row.Item("QTY").Static = True
            End If

            If QTYValue.Contains("mm") Then
                Dim cleanString As String = Replace(QTYValue, "mm", "")
                Dim QTYValueNew As Double = CDbl(cleanString)
				QTYValueNew = QTYValueNew + (QTYValueNew / 20)
                QTYValueNew = Math.Round(QTYValueNew, 2)
                row.Item("QTY").Value = CStr(QTYValueNew)
                row.Item("QTY").Static = True
            End If
        Next


        For Each row In rows
            Dim Valuestart As Double = 0
            Dim value2 As Double = 5000
            Dim QTYValue As String = (row.Item("QTY").Value)
            If row.Item("QTY").Static = True Then
                Dim count As Integer = 2
                For i = 1 To 1000
                    Dim QTYValueNew As Double = CDbl(QTYValue)
                    If QTYValueNew < 5000 Then
                        row.Item("QTY").Value = CStr(1)
                        row.Item("QTY").Static = True
                    End If

                    If QTYValueNew >= value2 AndAlso QTYValueNew < value2 * 2 Then
                        row.Item("QTY").Value = CStr(count)
                        row.Item("QTY").Static = True
                    End If
                    value2 = value2 + 5000

                    count = count + 1
                    If value2 > QTYValue Then
                        Exit For
                    End If
                Next
            End If
        Next




 

If this answers your question, please use  ACCEPT SOLUTION  to assist other users later.

Also be generous with Likes!  Thank you and enjoy!

 

0 Likes
Message 8 of 24

eladm
Collaborator
Collaborator

Hi

 

Can you add a code in the rule if the pipe's unit is already in meter ? (add to the inch and the mm)

 

regards

0 Likes
Message 9 of 24

nstevelmans
Advocate
Advocate

Hi, Added the m request.

 

 

 Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
        Dim oSheet As Sheet = oDrawDoc.ActiveSheet
        Dim oPartslist As PartsList = oSheet.PartsLists.Item(1)

        Dim rows As PartsListRows = oPartslist.PartsListRows
        Dim row As PartsListRow = Nothing
        Dim Columns As PartsListColumns = oPartslist.PartsListColumns
        Dim Partslistrows As New List(Of PartsListRow)

        For Each row In rows
            Dim QTYValue As String = (row.Item("QTY").Value)
            If QTYValue.Contains("in") Then
                Dim cleanString As String = Replace(QTYValue, "in", "")
                Dim QTYValueNew As Double = CDbl(cleanString)
                QTYValueNew = Math.Round(QTYValueNew * 25.4, 2)
                row.Item("QTY").Value = CStr(QTYValueNew)
                row.Item("QTY").Static = True
            End If

            If QTYValue.Contains("mm") Then
                Dim cleanString As String = Replace(QTYValue, "mm", "")
                Dim QTYValueNew As Double = CDbl(cleanString)
                QTYValueNew = Math.Round(QTYValueNew, 2)
                row.Item("QTY").Value = CStr(QTYValueNew)
                row.Item("QTY").Static = True
            End If
			
			  If QTYValue.Contains("m") Then
                Dim cleanString As String = Replace(QTYValue, "m", "")
                Dim QTYValueNew As Double = CDbl(cleanString)
                QTYValueNew = Math.Round(QTYValueNew * 1000, 2)
                QTYValueNew = QTYValueNew + (QTYValueNew / 20)
                row.Item("QTY").Value = CStr(QTYValueNew)
                row.Item("QTY").Static = True
            End If
        Next


        For Each row In rows
            Dim Valuestart As Double = 0
            Dim value2 As Double = 5000
            Dim QTYValue As String = (row.Item("QTY").Value)
            If row.Item("QTY").Static = True Then
                Dim count As Integer = 2
                For i = 1 To 1000
                    Dim QTYValueNew As Double = CDbl(QTYValue)
                    If QTYValueNew < 5000 Then
                        row.Item("QTY").Value = CStr(1)
                        row.Item("QTY").Static = True
                    End If

                    If QTYValueNew >= value2 AndAlso QTYValueNew < value2 * 2 Then
                        row.Item("QTY").Value = CStr(count)
                        row.Item("QTY").Static = True
                    End If
                    value2 = value2 + 5000

                    count = count + 1
                    If value2 > QTYValue Then
                        Exit For
                    End If
                Next
            End If
        Next

 

 

If this answers your question, please use  ACCEPT SOLUTION  to assist other users later.

Also be generous with Likes!  Thank you and enjoy!

 

 

 

 

0 Likes
Message 10 of 24

eladm
Collaborator
Collaborator

Hi

 

The result take now a more time to get the result , and the result is wrong

 

I got this :

the mm and inch  is give wrong result  , you also delete the /20 - is this the 5% ?

Why at m you multiple by 1000 ?

but here a test :

 

eladm_0-1719750011449.pngeladm_1-1719750020942.png

if I rerun the rule the result will be 1 , no matter

regards

0 Likes
Message 11 of 24

nstevelmans
Advocate
Advocate
Accepted solution

Hi, conditional statements where wrong,

QTYValueNew = QTYValueNew + Math.Round(QTYValueNew / 20) is the 5%

QTYValueNew = Math.Round(QTYValueNew * 1000, 2) roundup is based on mm so I convert m to mm

 

try this one

 

  Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
        Dim oSheet As Sheet = oDrawDoc.ActiveSheet
        Dim oPartslist As PartsList = oSheet.PartsLists.Item(1)

        Dim rows As PartsListRows = oPartslist.PartsListRows
        Dim row As PartsListRow = Nothing
        Dim Columns As PartsListColumns = oPartslist.PartsListColumns
        Dim Partslistrows As New List(Of PartsListRow)


        For Each row In rows
            row.Item("QTY").Static = False
        Next

        For Each row In rows
            Dim QTYValue As String = (row.Item("QTY").Value)
            If QTYValue.Contains("in") Then
                Dim cleanString As String = Replace(QTYValue, "in", "")
                Dim QTYValueNew As Double = CDbl(cleanString)
                QTYValueNew = QTYValueNew * 25.4 'convert in to mm
                QTYValueNew = Math.Round(QTYValueNew + (QTYValueNew / 20), 2) 'add 5%
                row.Item("QTY").Value = CStr(QTYValueNew)
                row.Item("QTY").Static = True
            ElseIf QTYValue.Contains("mm") Then
                Dim cleanString As String = Replace(QTYValue, "mm", "")
                Dim QTYValueNew As Double = CDbl(cleanString)
                QTYValueNew = Math.Round(QTYValueNew + (QTYValueNew / 20), 2) 'add 5%
                row.Item("QTY").Value = CStr(QTYValueNew)
                row.Item("QTY").Static = True
            ElseIf QTYValue.Contains("m") Then
                Dim cleanString As String = Replace(QTYValue, "m", "")
                Dim QTYValueNew As Double = CDbl(cleanString)
                QTYValueNew = QTYValueNew * 1000 'convert m to mm
                QTYValueNew = Math.Round(QTYValueNew + (QTYValueNew / 20), 2) 'add 5%
                row.Item("QTY").Value = CStr(QTYValueNew)
                row.Item("QTY").Static = True
            End If
        Next

        For Each row In rows
            Dim Valuestart As Double = 0
            Dim value2 As Double = 5000
            Dim QTYValue As String = (row.Item("QTY").Value)
            If row.Item("QTY").Static = True Then
                Dim count As Integer = 2
                For i = 1 To 1000
                    Dim QTYValueNew As Double = CDbl(QTYValue)
                    If QTYValueNew < 5000 Then
                        row.Item("QTY").Value = CStr(1)
                        row.Item("QTY").Static = True
                    End If

                    If QTYValueNew >= value2 AndAlso QTYValueNew < value2 * 2 Then
                        row.Item("QTY").Value = CStr(count)
                        row.Item("QTY").Static = True
                    End If
                    value2 = value2 + 5000

                    count = count + 1
                    If value2 > QTYValue Then
                        Exit For
                    End If
                Next
            End If
        Next
Message 12 of 24

Stakin
Collaborator
Collaborator

HI,Maybe you can use the UnitsOfMeasure Object,to convert tube length to database units 

 

 

 

 

		Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
        Dim oSheet As Sheet = oDrawDoc.ActiveSheet
        Dim oPartslist As PartsList = oSheet.PartsLists.Item(1)
		Dim oUm As UnitsOfMeasure
		oUm = oDrawDoc.UnitsOfMeasure
        Dim rows As PartsListRows = oPartslist.PartsListRows
        Dim row As PartsListRow = Nothing
        For Each row In rows
            Dim QTYValue As String = (row.Item("QTY").Value)
			Dim  oValue As Double
			Try 
				oValue=CDbl(QTYValue)	
			Catch
				oValue = oUm.GetValueFromExpression(QTYValue, UnitsTypeEnum.kInchLengthUnits)
				Dim oPNum As Integer
				oPNum=Math.Ceiling(oValue*1.05/500)
				row.Item("QTY").Value = CStr(oPNum)				
				row.Item("QTY").Static = True 
			End Try          
        Next

 

 

Stakin_0-1719806643937.png

 

 

Message 13 of 24

eladm
Collaborator
Collaborator

Hi

 

I think it work fine (test a few assembly's)

If in the drawing have more than 1 part list , the rule is only to the 1st Part list that inserted.

can the rule works for all the part lists in the drawing?

regards 

0 Likes
Message 14 of 24

eladm
Collaborator
Collaborator

Hi

 

The rule works fine . but if the length of the parts change rerun the rule don't update the value

regards

0 Likes
Message 15 of 24

Stakin
Collaborator
Collaborator

Try this,all partlist will be changed.

and when model changed,run it, the partlist will update.

 

 

		Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
        Dim oSheet As Sheet = oDrawDoc.ActiveSheet
		Dim oUm As UnitsOfMeasure = oDrawDoc.UnitsOfMeasure		
       	For Each oPartslist As Partslist In oSheet.PartsLists			
			For Each row As PartsListRow In oPartslist.PartsListRows
	            row.Item("QTY").Static = False
				Dim QTYValue As String = (row.Item("QTY").Value)
				Dim  oValue As Double
				Try 
					oValue = CDbl(QTYValue)
					row.Item("QTY").Value = CStr(oValue)	
				Catch
					oValue = oUm.GetValueFromExpression(QTYValue, UnitsTypeEnum.kInchLengthUnits)
					Dim oPNum As Integer
					oPNum=Math.Ceiling(oValue*1.05/500)
					row.Item("QTY").Value = CStr(oPNum)				
					row.Item("QTY").Static = True 
				End Try  
	        Next
		Next

 

0 Likes
Message 16 of 24

eladm
Collaborator
Collaborator

ERROR

eladm_0-1719816735825.png

 

0 Likes
Message 17 of 24

Stakin
Collaborator
Collaborator
please ensure it has "QTY" item in every partlist.
0 Likes
Message 18 of 24

eladm
Collaborator
Collaborator

eladm_0-1719817626852.png

 

0 Likes
Message 19 of 24

Stakin
Collaborator
Collaborator
which one is the partlists.item(1)?
0 Likes
Message 20 of 24

nstevelmans
Advocate
Advocate
Accepted solution

Hi, try this for multiple Partslists

 

 Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
        Dim oSheet As Sheet = oDrawDoc.ActiveSheet
        Dim oPartslist As PartsList 
		For Each oPartslist In oSheet.PartsLists
		Dim rows As PartsListRows = oPartslist.PartsListRows
        Dim row As PartsListRow = Nothing
        Dim Columns As PartsListColumns = oPartslist.PartsListColumns
        Dim Partslistrows As New List(Of PartsListRow)


        For Each row In rows
            row.Item("QTY").Static = False
        Next

        For Each row In rows
            Dim QTYValue As String = (row.Item("QTY").Value)
            If QTYValue.Contains("in") Then
                Dim cleanString As String = Replace(QTYValue, "in", "")
                Dim QTYValueNew As Double = CDbl(cleanString)
                QTYValueNew = QTYValueNew * 25.4 'convert in to mm
                QTYValueNew = Math.Round(QTYValueNew + (QTYValueNew / 20), 2) 'add 5%
                row.Item("QTY").Value = CStr(QTYValueNew)
                row.Item("QTY").Static = True
            ElseIf QTYValue.Contains("mm") Then
                Dim cleanString As String = Replace(QTYValue, "mm", "")
                Dim QTYValueNew As Double = CDbl(cleanString)
                QTYValueNew = Math.Round(QTYValueNew + (QTYValueNew / 20), 2) 'add 5%
                row.Item("QTY").Value = CStr(QTYValueNew)
                row.Item("QTY").Static = True
            ElseIf QTYValue.Contains("m") Then
                Dim cleanString As String = Replace(QTYValue, "m", "")
                Dim QTYValueNew As Double = CDbl(cleanString)
                QTYValueNew = QTYValueNew * 1000 'convert m to mm
                QTYValueNew = Math.Round(QTYValueNew + (QTYValueNew / 20), 2) 'add 5%
                row.Item("QTY").Value = CStr(QTYValueNew)
                row.Item("QTY").Static = True
            End If
        Next

        For Each row In rows
            Dim Valuestart As Double = 0
            Dim value2 As Double = 5000
            Dim QTYValue As String = (row.Item("QTY").Value)
            If row.Item("QTY").Static = True Then
                Dim count As Integer = 2
                For i = 1 To 1000
                    Dim QTYValueNew As Double = CDbl(QTYValue)
                    If QTYValueNew < 5000 Then
                        row.Item("QTY").Value = CStr(1)
                        row.Item("QTY").Static = True
                    End If

                    If QTYValueNew >= value2 AndAlso QTYValueNew < value2 * 2 Then
                        row.Item("QTY").Value = CStr(count)
                        row.Item("QTY").Static = True
                    End If
                    value2 = value2 + 5000

                    count = count + 1
                    If value2 > QTYValue Then
                        Exit For
                    End If
                Next
            End If
        Next
				Next