Range Box bug? (Inventor 2023.2)

Range Box bug? (Inventor 2023.2)

llorden4
Collaborator Collaborator
1,000 Views
15 Replies
Message 1 of 16

Range Box bug? (Inventor 2023.2)

llorden4
Collaborator
Collaborator

I'm working on a routine to test hole placements next to edges and I've found a condition in patterns this is creating a problem for me.  It appears that when getting a Range Box for a pattern, that the original feature is not included in the range box even though it appears as an occurrence in the pattern.  For example, I've highlighted "H1 Pattern" which is created from hole feature "H1".  The pattern features in the tree show all features, including the original "H1".  In this screen capture where there's two columns & rows, I do get a valid range box (represented by the two points highlighted which are the MinPoint and MaxPoint return values (inverted due to view & YZ Plane usage).

llorden4_0-1677261115129.png

 

However when there's only 1 column OR 1 row, then the range box only includes the copied features and therefore provides an incorrect range box for the pattern, or at least not what I was expecting from the range box.

llorden4_0-1677261323621.png

 

oFeature = oCompDef.Features.Item("H1 Pattern")
oMinPoint = oFeature.RangeBox.MinPoint
oMaxPoint = oFeature.RangeBox.MaxPoint

Is my understanding of range boxes incorrect here or is this a bug and not operating as expected?

 

If I'm off here, is there a way to get a range box to include the original feature(s)?

Autodesk Inventor Certified Professional
Accepted solutions (1)
1,001 Views
15 Replies
Replies (15)
Message 2 of 16

WCrihfield
Mentor
Mentor

Hi @llorden4.  You always come up with some interesting and challenging posts. 😁

I guess you would have to do it the hard way.  Maybe get the RectangularPatternFeature.PatternElements, dig down to its Items (FeaturePatternElement), and use their ResultFeatures (ObjectsEnumerator) or Faces properties to get a starter collection.  Then get the 'parent' feature through RectangularPatternFeature.Definition.ParentFeatures (an ObjectCollection).  I'd probably start with the 'parent' object, since we know what it is, and get its RangeBox as a starting point.  A HoleFeature object has a RangeBox property, so at leas that step is easy.  Then loop through all child objects, and try using the Box.Extend method to include both the MinPoint & MaxPoint of all the other object's RangeBoxes.  And of course, this whole can of worms would only work if every one of the objects involved has a RangeBox property.  With a Face object, you would have to use Face.Evaluator.RangeBox.

 

Edit:  Wow.  Don't know why I didn't think of this originally, but start with the RangeBox that you get from the pattern feature, then attempt to add the parent feature's RangeBoxes into it using the Box.Extend method.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 16

llorden4
Collaborator
Collaborator

Right, I get all the fun issues.  I didn't mention it, but my routine could be a rectangular or a circular pattern.  A rectangular pattern would be easy for me to calculate a range box but a circular pattern without a full 360 sweep is much easier to resolve with the range box.  How would this change your approach?  Box.Extend would likely work here as well, yah?

Autodesk Inventor Certified Professional
0 Likes
Message 4 of 16

WCrihfield
Mentor
Mentor

Good point.  Whatever the best universally usable workaround solution is, I bet it is going to be a whole lot more work and complication than if the folks at Autodesk were to fix or extend that RangeBox property of these types of patterns to optionally include the 'parent'/input features.  Might be a good one to post on the Inventor Ideas forum.

It likely depends somewhat on your accuracy requirements/expectations/needs.  I first looked at OrientedBox, but that doesn't have anything like the Extend method, and seems more difficult to work with.  Then I started looking into TransientBRep stuff, like a cylinder, or creating a new SurfaceBodyDefinition, then adding each box to it somehow as a lump or vertexes or something like that.  Then maybe using the RangeBox of the body you end up with.  Lots of thoughts, but no tested solutions yet.  Have a good weekend...I'm headed out.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 16

llorden4
Collaborator
Collaborator

Posted to Ideas, just in case but REALLY hope this is a bug that can get fixed quickly in time for my project to be completed (next week?), better not hold my breath.

 

@johnsonshiue might be able to comment if this is expected behavior for this feature.

Autodesk Inventor Certified Professional
0 Likes
Message 6 of 16

JelteDeJong
Mentor
Mentor
Accepted solution

I tested your situation and get the same results. While trying to come up with a solution I found that the first element in the pattern does not return any faces. Because of that, I did get the same results as the inventor API. But I could work around this because the original/parent features return the faces. With that, I could get a correct range box. here is the code:

Sub Main()

    Dim doc As PartDocument = ThisDoc.Document
    Dim def As PartComponentDefinition = doc.ComponentDefinition

    Dim pattern As RectangularPatternFeature = def.Features.Item("H1 Pattern")

    Dim myRangeBox As Box = GetRangeBoxFromPattern(pattern)

    Dim workPointMin = def.WorkPoints.AddFixed(myRangeBox.MinPoint)
    Dim workPointMax = def.WorkPoints.AddFixed(myRangeBox.MaxPoint)

End Sub

Private Function GetRangeBoxFromPattern(pattern As RectangularPatternFeature) As Box
    Dim min As Double() = New Double() {Double.MaxValue, Double.MaxValue, Double.MaxValue}
    Dim max As Double() = New Double() {Double.MinValue, Double.MinValue, Double.MinValue}

    For Each element As FeaturePatternElement In pattern.PatternElements
        For Each face As Face In element.Faces
            Dim elfMin = Face.Evaluator.RangeBox.MinPoint
            Dim elfMax = Face.Evaluator.RangeBox.MaxPoint

            If (elfMin.X < min(0)) Then min(0) = elfMin.X
            If (elfMin.Y < min(1)) Then min(1) = elfMin.Y
            If (elfMin.Z < min(2)) Then min(2) = elfMin.Z

            If (elfMax.X > max(0)) Then max(0) = elfMax.X
            If (elfMax.Y > max(1)) Then max(1) = elfMax.Y
            If (elfMax.Z > max(2)) Then max(2) = elfMax.Z
        Next
    Next

    ' If you skip this loop you get the same result as the Inventor API
    For Each feature As PartFeature In pattern.ParentFeatures
        For Each face As Face In Feature.Faces
            Dim elfMin = Face.Evaluator.RangeBox.MinPoint
            Dim elfMax = Face.Evaluator.RangeBox.MaxPoint

            If (elfMin.X < min(0)) Then min(0) = elfMin.X
            If (elfMin.Y < min(1)) Then min(1) = elfMin.Y
            If (elfMin.Z < min(2)) Then min(2) = elfMin.Z

            If (elfMax.X > max(0)) Then max(0) = elfMax.X
            If (elfMax.Y > max(1)) Then max(1) = elfMax.Y
            If (elfMax.Z > max(2)) Then max(2) = elfMax.Z
        Next
    Next


    Dim rangeBox As Box = ThisApplication.TransientGeometry.CreateBox()
    rangeBox.MinPoint = ThisApplication.TransientGeometry.CreatePoint(min(0), min(1), min(2))
    rangeBox.MaxPoint = ThisApplication.TransientGeometry.CreatePoint(max(0), max(1), max(2))

    Return rangeBox
End Function

 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 7 of 16

llorden4
Collaborator
Collaborator

Thanks, this works well.  I even threw another hole variation option I already have in my code for slots and it worked fine for those too.

 

While this is a good work-around, I suppose I should leave this open as a bug report.

 

llorden4_0-1677492839714.png

 

Autodesk Inventor Certified Professional
0 Likes
Message 8 of 16

JelteDeJong
Mentor
Mentor

Probably it's better to accept as solution here. Then it get easier for others to find this solution/workaround. 

And the bug can better be reported in the "Inventor Feedback/Beta Project" forum. There you will find a complete form for reporting bugs. You can join the "Inventor Feedback/Beta Project" and if you find often bug/strange things then this would be a good thing. But I could also do it for you if you like. (just let me know.)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 9 of 16

llorden4
Collaborator
Collaborator

You can put in the error report.   I don't need another forum to keep up with and participate in, too busy as it is, thanks.

Autodesk Inventor Certified Professional
0 Likes
Message 10 of 16

WCrihfield
Mentor
Mentor

Hi guys.  Looks like my initial thoughts were valid as a workaround process.  Hopefully we won't need the workaround for too long.  I voted for you idea.  Every once in a while an idea gets implemented without really having tons of votes, just because it was easy to implement, and it has come up in enough other conversations, so maybe that will be the case with yours.  Anyways, after I got in this morning, got some other stuff under control, and saw the responses here, I decided to explore my second thought (the Edit part of message 2), to see if that would also be valid, or any simpler to use.  The process does seem to work, but only for patterns of features so far, and not patterns of solid bodies, for some reason.  When the pattern is of solid bodies, then the Pattern.Definition.ParentFeatures is empty, making it difficult to pinpoint the 'input' bodies.  There is likely a secondary way to workaround that detail too, but I just did not spend any time looking into it yet.

I tested the following code on a circular hole pattern (not 360 degrees, on purpose) in a part, and this seemed to work OK for me.  It seems like a shorter & simpler code, using the Box.Extend method I mentioned, where I start with the RangeBox of the pattern, then add the 'parent's range box bounds into it.  Just another way of looking at the problem.

Sub Main
	Dim oPDoc As PartDocument = ThisDoc.Document
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	Dim oFPatt As CircularPatternFeature = oPDef.Features.CircularPatternFeatures.Item("CP1")
	Dim oRBox As Box = GetCircPatternRangeBox(oFPatt, True)
	If IsNothing(oRBox) Then Logger.Debug("oRBox Is Nothing") : Exit Sub
	Dim oMinWP As WorkPoint = oPDef.WorkPoints.AddFixed(oRBox.MinPoint)
	Dim oMaxWP As WorkPoint = oPDef.WorkPoints.AddFixed(oRBox.MaxPoint)
End Sub

Function GetCircPatternRangeBox(oCPatt As CircularPatternFeature, Optional IncludeParentFeatures As Boolean = False) As Box
	Dim oBox As Box = oCPatt.RangeBox
	If IncludeParentFeatures = False Or oCPatt.Definition.ParentFeatures.Count = 0 Then Return oBox
	For Each oParentFeature As PartFeature In oCPatt.Definition.ParentFeatures
		If Not oBox.Contains(oParentFeature.RangeBox.MinPoint) Then oBox.Extend(oParentFeature.RangeBox.MinPoint)
		If Not oBox.Contains(oParentFeature.RangeBox.MaxPoint) Then oBox.Extend(oParentFeature.RangeBox.MaxPoint)
	Next
	Return oBox
End Function

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 11 of 16

llorden4
Collaborator
Collaborator

I did need to come back and point out that it seems I need to create two versions of this function, one for Rectangular and one for Circular patterns, another reason to simply fix the Feature.RangeBox.MinPoint/Maxpoint to avoid the double dip.

Autodesk Inventor Certified Professional
Message 12 of 16

WCrihfield
Mentor
Mentor

Yep.  I noticed that too.  Unlike a pattern of assembly components, which has a 'base Class' (OccurrencePattern) that the rectangular or circular versions are derived from, there is no PatternFeatures base class.  I suppose you define the Type of the first 'input' parameter as an Object.  Then within the method, check its Type before proceeding, then have an If...Then block to get a step deeper, because they pretty similar after that point.  Like you said, just another downside to the whole workaround business.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 13 of 16

JelteDeJong
Mentor
Mentor

I didn't know about the Box.Contains() and Box.Extend() methods. But it could make the code a lot smaller:

Sub Main()

    Dim doc As PartDocument = ThisDoc.Document
    Dim def As PartComponentDefinition = doc.ComponentDefinition

    Dim pattern As RectangularPatternFeature = def.Features.Item("H1 Pattern")

    Dim myRangeBox As Box = GetRangeBoxFromPattern(pattern)

    Dim workPointMin = def.WorkPoints.AddFixed(myRangeBox.MinPoint)
    Dim workPointMax = def.WorkPoints.AddFixed(myRangeBox.MaxPoint)

End Sub

Private Function GetRangeBoxFromPattern(pattern As RectangularPatternFeature) As Box
	
	Dim rangeBox As Box = pattern.RangeBox

    For Each feature As PartFeature In pattern.ParentFeatures
        For Each face As Face In Feature.Faces
            Dim elfMin = Face.Evaluator.RangeBox.MinPoint
            Dim elfMax = Face.Evaluator.RangeBox.MaxPoint

            If Not rangeBox.Contains(elfMin) Then rangeBox.Extend(elfMin)
			If Not rangeBox.Contains(elfMax) Then rangeBox.Extend(elfMax)
        Next
    Next

    Return rangeBox
End Function

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 14 of 16

llorden4
Collaborator
Collaborator

Nice, that does free up some space and I'm VERY curious how you got the line numbers to appear in your message.  For the benefit of others watching, here are my adjustments to scan for the pattern type and handle it accordingly.  (Some variables changed for personal preference).

 

Sub Main()
    Dim oDoc As PartDocument = ThisDoc.Document
    Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition
	Dim myRangeBox As Box
	Dim oMinPoint, oMaxPoint As Point
	
	oFeature = oCompDef.Features.Item("H1 Pattern")
	If oFeature.Type = 83913728 Then
		oRangeBox = GetRangeBoxFromRecPattern(oFeature)
	ElseIf oFeature.Type = 83909632 Then
		oRangeBox = GetRangeBoxFromCircPattern(oFeature)
	End If
	
	oMinPoint = oRangeBox.MinPoint     'not required, just giving its own variable
	oMaxPoint = oRangeBox.MaxPoint     'not required, just giving its own variable
End Sub

Private Function GetRangeBoxFromRecPattern(pattern As RectangularPatternFeature) As Box
	Dim rangeBox As Box = pattern.RangeBox
    For Each feature As PartFeature In pattern.ParentFeatures
        For Each face As Face In Feature.Faces
            Dim elfMin = Face.Evaluator.RangeBox.MinPoint
            Dim elfMax = Face.Evaluator.RangeBox.MaxPoint

            If Not rangeBox.Contains(elfMin) Then rangeBox.Extend(elfMin)
			If Not rangeBox.Contains(elfMax) Then rangeBox.Extend(elfMax)
        Next
    Next
    Return rangeBox
End Function

Private Function GetRangeBoxFromCircPattern(pattern As CircularPatternFeature) As Box
	Dim rangeBox As Box = pattern.RangeBox
    For Each feature As PartFeature In pattern.ParentFeatures
        For Each face As Face In Feature.Faces
            Dim elfMin = Face.Evaluator.RangeBox.MinPoint
            Dim elfMax = Face.Evaluator.RangeBox.MaxPoint

            If Not rangeBox.Contains(elfMin) Then rangeBox.Extend(elfMin)
			If Not rangeBox.Contains(elfMax) Then rangeBox.Extend(elfMax)
        Next
    Next
    Return rangeBox
End Function

 

 

Autodesk Inventor Certified Professional
0 Likes
Message 15 of 16

JelteDeJong
Mentor
Mentor

First add a code block:

JelteDeJong_0-1677537925334.png

then you can select the language.

JelteDeJong_2-1677538062986.png

this will add the line numbers and font colours.

'Your code here

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 16 of 16

WCrihfield
Mentor
Mentor

I always used the 'Insert/Edit code sample' button, but never had to use the code language selection part.  It just started adding the line numbers into the code I posted about the same time that the line numbers started showing up in the iLogic rule editor window, when that feature became available in Inventor.  So, I think it just had to do with me copying code directly from my iLogic rule editor window, and pasting them directly into the code window of the forum post.  It was always just as simple as that for me.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes