Minimum Flange Height iLogic Rule

Minimum Flange Height iLogic Rule

Anonymous
Not applicable
841 Views
6 Replies
Message 1 of 7

Minimum Flange Height iLogic Rule

Anonymous
Not applicable

Developing an external rule that is triggered on 'Part Geometry Change' to ensure that any sheet metal flange heights which are less than the minimum are flagged up to the user.

 

There's a couple of things not quite perfect with it. Any tips on solving these would be much appreciated:

 

  1. After setting a new flange height (through the inputbox) the parameter has a huge trail of zeros (i.e 12.00000000 mm), I would like this to just be 12 mm, 12.5 mm etc
  2. I would love to include a color change to highlight the feature but I get some funny looking results (see attached images) as if the model geometry hasn't updated properly when the message box is presented.
  3. If I try to delete a flange that's too small, the rule is triggered and detects this flange, even though I just tried to delete it (guessing that solving point 2 will also solve this one)

See code below, or I've attached a sample part file.

Sub Main ()

' Get active document
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

' Make sure the active document is a sheet metal document.
If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
   MsgBox ("A sheet metal document must be open.")
    Exit Sub
End If

' Get component definition of part
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

' Get the referenced document feature collection
Dim oFlangesFeatures As PartFeatures
oFlangeFeatures = oCompDef.Features.FlangeFeatures

' Get thickness of part
Dim thickParam As Double
thickParam = Double.Parse(oCompDef.Thickness.Value * 10)
'MsgBox(thickParam)

' Set Min Flange rules
If thickParam = 1
    MinFlange = 6
ElseIf thickParam = 1.5
    MinFlange = 8.5
ElseIf thickParam = 2
    MinFlange = 9
ElseIf thickParam = 3
    MinFlange = 12
ElseIf thickParam = 4
    MinFlange = 17.5
ElseIf thickParam = 5
    MinFlange = 31
ElseIf thickParam = 6
    MinFlange = 33.5
ElseIf thickParam = 8
    MinFlange = 34
End If

Dim oFlange As FlangeFeature

For Each oFlange In oFlangeFeatures

oFlangeHeight = oFlange.Definition.HeightExtent.Distance.Value * 10

If oFlangeHeight < MinFlange
    Feature.Color(oFlange.Name) = "Red"
    myparam = InputBox(oFlange.Name & " is less than the minimum required." & vbLf & "The minimum distance required is " & MinFlange & vbLf & vbLf & "Enter new flange height.", "Flange Error", MinFlange)
    Feature.Color(oFlange.Name) = "As Body"
    oFlange.Definition.HeightExtent.Distance.Value = myparam/10
    RuleParametersOutput()
    InventorVb.DocumentUpdate()
End If

Next

End Sub

 

0 Likes
842 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Ooops forgot to attach images

0 Likes
Message 3 of 7

JaneFan
Autodesk
Autodesk

Hey @Anonymous, 

 

Thank you for your reporting.

For issue 1, please try to use set expression of the Distance instead. 

oFlange.Definition.HeightExtent.Distance.expression  = (myparam).ToString + "mm"

Issue 2 is tracked in our internal system. 

For issue 3, deleting a feature definitely changes the part geometry so that the rule will be triggered accordingly. How about making the Min Flange rule being triggered by Model Parameter Change? 

 

 

 




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 4 of 7

Anonymous
Not applicable

Hi @JaneFan

 

Thank you for your response and for solving my first problem.

 

I have tried the event trigger 'Model Parameter Change', unfortunately this will not work for me, as I need the rule to run when a new flange is created.

I am happy for the rule to run on part geometry change, but only if there a way to force Inventor to execute the delete command before the rule reaches the For loop?

0 Likes
Message 5 of 7

b_sharanraj
Advocate
Advocate

Hi @Anonymous

 

Please find the attachment 🙂

 

 

Regards

B.Sharan Raj

0 Likes
Message 6 of 7

Anonymous
Not applicable

Thank you @b_sharanraj

 

You have solved issue number 2 🙂

 

Although, I do not want a loop, as I would like the user to be able to enter a value that is smaller than MinFlange if they wish so and for it to be accepted.

 

I have edited your code as below, it almost perfect but I still have issue number 3:

 

Sub Main ()

' Get active document
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

' Make sure the active document is a sheet metal document.
If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
   MsgBox ("A sheet metal document must be open.")
    Exit Sub
End If

' Get component definition of part
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

' Get the referenced document feature collection
Dim oFlangesFeatures As PartFeatures
oFlangeFeatures = oCompDef.Features.FlangeFeatures

' Get thickness of part
Dim thickParam As Double
thickParam = Double.Parse(oCompDef.Thickness.Value * 10)
'MsgBox(thickParam)

' Set Min Flange rules
If thickParam = 1
    MinFlange = 6
ElseIf thickParam = 1.5
    MinFlange = 8.5
ElseIf thickParam = 2
    MinFlange = 9
ElseIf thickParam = 3
    MinFlange = 12
ElseIf thickParam = 4
    MinFlange = 17.5
ElseIf thickParam = 5
    MinFlange = 31
ElseIf thickParam = 6
    MinFlange = 33.5
ElseIf thickParam = 8
    MinFlange = 34
End If

Dim oFlange As FlangeFeature

For Each oFlange In oFlangeFeatures

oFlangeHeight = oFlange.Definition.HeightExtent.Distance.Value * 10
myparam = oFlangeHeight 

If oFlangeHeight < MinFlange
    
    Feature.Color(oFlange.Name) = "Red"
    oFlange.Definition.HeightExtent.Distance.expression = myparam
    InventorVb.DocumentUpdate()
    
    'Do Until myparam >= MinFlange
    ThisApplication.ActiveView.Update()
    'MessageBox.Show(myparam, "Title")
    myparam = InputBox(oFlange.Name & " height of " & oFlangeHeight & " mm is less than the minimum required." & vbLf & vbLf & "The minimum distance required is " & MinFlange & vbLf & vbLf & "Enter new flange height.", "Flange Error", MinFlange)
    
    oFlange.Definition.HeightExtent.Distance.expression = myparam
    RuleParametersOutput()
    InventorVb.DocumentUpdate()
    'Loop
    
    Feature.Color(oFlange.Name) = "As Body"
End If

Next

End Sub

 

 

0 Likes
Message 7 of 7

b_sharanraj
Advocate
Advocate

I have been tried and get got the code to delete the existing Flange if it's less MinFlange.

 

But i can see that you are planning to use this as an Sheetmetal Template so that a new flange feature will be taken care by that code.

 

Inventor crashes when I'm checking for a new flange feature.

 

Add the below one at the end of the existing code 

 

If myparam < MinFlange then

ThisApplication.ActiveDocument.ComponentDefinition.Features.FlangeFeatures.Item(oFlange.Name).delete
End If

 

Regards

B.Sharan Raj

0 Likes