Run ilogic rule in each part from the assembly via external rule

Run ilogic rule in each part from the assembly via external rule

Anonymous
Not applicable
1,235 Views
7 Replies
Message 1 of 8

Run ilogic rule in each part from the assembly via external rule

Anonymous
Not applicable

I have the following piece of code that I'd like to be able to run in any assembly to check that the flat sizes of my sheet metal parts are not over the maximum stock sizew. I originally had the section highlighted in red as a rule on it's own that I could run at part level, which worked perfectly. But it would be hugely useful to have a rule that ran through the same check on all the sub-parts of my assembly. I don't recieve any errors with this bit of code, but its not returning the error message box that it should to tell me the dimensions are too large. Is the code actually running through each sub-part?

 

Dim openDoc As Document
openDoc = ThisDoc.Document

Dim docFile As Document 

If openDoc.DocumentType = 12291 Then

    For Each docFile In openDoc.AllReferencedDocuments
    
        If docFile.DocumentType = 12290 Then

InventorVb.DocumentUpdate()
'Obtain max & min flat sizes of part
x = MaxOfMany(SheetMetal.FlatExtentsLength, SheetMetal.FlatExtentsWidth)
y = MinOfMany(SheetMetal.FlatExtentsLength, SheetMetal.FlatExtentsWidth)

'Read R number of part
material1 = (Left(iProperties.Material(False),6))

'Read max stock sizes of material
GoExcel.TitleRow = 3
i = GoExcel.FindRow("F:\Reports\RPT-E2I-012 - Parts Costing.xls", "Parts Costing", "Part Num", "=", material1)
maxX = GoExcel.CurrentRowValue("size_x")
maxY = GoExcel.CurrentRowValue("size_y")

'Check flat sizes don't exceed stock sizes
If x > maxX Or y > maxY Then
MessageBox.Show("Your dimensions are too large." & vbLf & "Max dimensions are: " & maxX & " x " & maxY & vbLf & "Your dimensions are: " & Ceil(x) & " x " & Ceil(y), "ERROR!",MessageBoxButtons.OK,MessageBoxIcon.Error)

RuleParametersOutput()
InventorVb.DocumentUpdate()

End If
End If

Next
    
    Else
    
    MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
    
End If 

 

0 Likes
Accepted solutions (1)
1,236 Views
7 Replies
Replies (7)
Message 2 of 8

rjay75
Collaborator
Collaborator

The statement SheetMetal.FlatExtentsLength(Width) returns the size of the flatpattern of the document running the rule. Since it's run from an assembly this always returns 0 as a value. You need to get the dimensions of the document you're checking.

 

Here's the edited code to address that.

 

SyntaxEditor Code Snippet

Dim openDoc As Document
openDoc = ThisDoc.Document

Dim docFile As Document 

If openDoc.DocumentType = 12291 Then

    For Each docFile In openDoc.AllReferencedDocuments
        'Is a Sheet Metal File
        If docFile.SubType.Equals("{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then

            'Obtain max & min flat sizes of part
            Dim smComp As SheetMetalComponentDefinition = docFile.ComponentDefinition
            If smComp.HasFlatPattern Then
                'Get FlatPattern Dims; Returned in cm need to convert to Inches (Or whatever units you're using)
                x = MaxOfMany(smComp.FlatPattern.Length, smComp.FlatPattern.Width) / 2.54
                y = MinOfMany(smComp.FlatPattern.Length, smComp.FlatPattern.Width) / 2.54
                
                'Read R number of part
                material1 = (Left(iProperties.Material(False),6))
                
                'Read Max stock sizes Of material
                GoExcel.TitleRow = 3
                i = GoExcel.FindRow("F:\Reports\RPT-E2I-012 - Parts Costing.xls", "Parts Costing", "Part Num", "=", material1)
                maxX = GoExcel.CurrentRowValue("size_x")
                maxY = GoExcel.CurrentRowValue("size_y")

                'Check flat sizes don't exceed stock sizes
                If x > maxX Or y > maxY Then
                    MessageBox.Show("Your dimensions are too large." & vbLf & "Max dimensions are: " & maxX & " x " & maxY & vbLf & "Your dimensions are: " & Ceil(x) & " x " & Ceil(y), "ERROR!",MessageBoxButtons.OK,MessageBoxIcon.Error)                    
                    RuleParametersOutput()
                End If
            End If
        End If
    Next
    
Else
    
    MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
    
End If
0 Likes
Message 3 of 8

Anonymous
Not applicable

Thank you rjay for your quick reply, I think the code is almost there. Sorry if I'm being a bit dim here, but as I am working in mm, is it as simple as multiplying these two lines by 10 (as below). What is the reason for dividing by 2.54?

 

x = MaxOfMany(smComp.FlatPattern.Length, smComp.FlatPattern.Width) / 2.54 * 10
y = MinOfMany(smComp.FlatPattern.Length, smComp.FlatPattern.Width) / 2.54 * 10 

 

If you see the image below, the max dimensions of the part are not pulling through. I've tested the GoExcel piece of the code at part level and its returning the correct values. Could this be because my parameter 'material1' is being set using the iproperty material of my assembly rather than the individial part? Also, do you know how could I have the  message box return the part number of the part being checked?

Capture.JPG

0 Likes
Message 4 of 8

rjay75
Collaborator
Collaborator
smComp.FlatPattern.Length

The value returned by this property is in cm so instead of dividing by 2.54 to conver it to inches you can just multiply times 10.

 

 

x = MaxOfMany(smComp.FlatPattern.Length, smComp.FlatPattern.Width) * 10
y = MinOfMany(smComp.FlatPattern.Length, smComp.FlatPattern.Width) * 10 
0 Likes
Message 5 of 8

Anonymous
Not applicable

Thanks for clearing that up, did you have a chance to look at the problem I'm having with returning the materials max stock sizes? 

0 Likes
Message 6 of 8

rjay75
Collaborator
Collaborator
Accepted solution

New Code to get more of the information.

 

SyntaxEditor Code Snippet

Dim openDoc As Document
openDoc = ThisDoc.Document

Dim docFile As Document 

If openDoc.DocumentType = 12291 Then

    For Each docFile In openDoc.AllReferencedDocuments
        'Is a Sheet Metal File
        If docFile.SubType.Equals("{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then

            'Obtain max & min flat sizes of part
            Dim smComp As SheetMetalComponentDefinition = docFile.ComponentDefinition
            If smComp.HasFlatPattern Then
                'Get Units of Measure Object
                Dim uom As UnitsOfMeasure = docFile.UnitsOfmeasure
                'Get FlatPattern Dims returned as the document units
                x = uom.ConvertUnits(MaxOfMany(smComp.FlatPattern.Length, smComp.FlatPattern.Width), "cm", uom.LengthUnits)
                y = uom.ConvertUnits(MinOfMany(smComp.FlatPattern.Length, smComp.FlatPattern.Width), "cm", uom.LengthUnits)
                
                'Get Partnumber
                partNumber = docFile.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
                'Read R number of part
                materialName = smComp.Material.Name
                material1 = materialName.SubString(0, 6)
                
                'Read Max stock sizes Of material
                GoExcel.TitleRow = 3
                i = GoExcel.FindRow("F:\Reports\RPT-E2I-012 - Parts Costing.xls", "Parts Costing", "Part Num", "=", material1)
                maxX = Double.Parse(GoExcel.CurrentRowValue("size_x"))
                maxY = Double.Parse(GoExcel.CurrentRowValue("size_y"))

                'Check flat sizes don't exceed stock sizes
                If x > maxX Or y > maxY Then
                    MessageBox.Show("Error In " & partNumber & vbLf  & "Your dimensions are too large for " & materialName & "." & vbLf & "Max dimensions are: " & maxX & " x " & maxY & vbLf & "Your dimensions are: " & Ceil(x) & " x " & Ceil(y), "ERROR!",MessageBoxButtons.OK,MessageBoxIcon.Error)                    
                    RuleParametersOutput()
                End If
            End If
        End If
    Next
    
Else
    
    MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
    
End If

 

Verify that maxX and maxY are pulling values from the spreadsheet as numbers. Parsing the value ensures it will be a number. 

 

It now includes the material from the part and the partnumber.

0 Likes
Message 7 of 8

Chirpyboy2060647
Advocate
Advocate
Sorry to hijack your thread without any help to your issue, but would this be possible to use with a little change with Frame Generator? To make it where you pick a size box/crate when u start a new file and it make sures no parts are over like 84" W or 94" w?
0 Likes
Message 8 of 8

Anonymous
Not applicable

Thanks rjay for taking the time to do that, your code works a treat 🙂

0 Likes