turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Siemens PLM Community
- NX Customization and Programming
- NX Programming & Customization Forum
- Compute Model Bounds for some objects not all obje...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-12-2017 03:02 PM

Is there an NXOpen command that does the same thing as:

NXOpen.UF.Disp.ComputeModelBounds()

but allows me to specify the objects to consider, rather than returning a bounding box that is large enough for all displayable objects?

There is a function for adjusting the scale on a view taking particular objects into account, that is called:

View.FitToObjects(objectsToConsider)

but the resulting view extents calculated are dependent on the aspect ratio of the window being displayed.

What I'm trying to do is keep PMI annotations away from the area required to display the model, and I have working functions that convert the bounding box in Model Space to the corners of a rectangular frame in view space. But I found that once I add any PMI, it gets included in the results of the bounding box! I want to be able to re-calculate the required PMI keep-out zone whenever the model changes, so I can't just get numbers once and trust them forever.

I already created a working function to get the objectsToConsider, which for my purposes is all solid bodies and all components in the work part. If there was a way to apply that as a filter to ComputeModelBounds, that would be perfect.

Solved! Go to Solution.

- Tags:
- bounding box

6 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-12-2017 03:35 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-12-2017 03:59 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-13-2017 04:58 AM

'calc bounding box Dim llc() As Double = {5000000, 5000000, 5000000} Dim urc() As Double = {-5000000, -5000000, -5000000} CalculateBox(lstFacetedBodiesInPart.ToArray, llc, urc, False) 'calc total box of filteredobjects objects (filtered by checkobjecttype function)

Sub CalculateBox(ByRef objs() As DisplayableObject, ByRef llc() As Double, ByRef urc() As Double, blnShowComponentBoxes As Boolean) Dim minmax(5) As Double 'loop through all filtered objects For Each obj As DisplayableObject In objs Try ufs.Modl.AskBoundingBox(obj.Tag, minmax) For ii As Integer = 0 To 2 If minmax(ii) < llc(ii) Then llc(ii) = minmax(ii) Next For ii As Integer = 0 To 2 If minmax(ii + 3) > urc(ii) Then urc(ii) = minmax(ii + 3) Next ' show each assembly level body bounding box If blnShowComponentBoxes Then Dim tlc() As Double = {minmax(0), minmax(1), minmax(2)} Dim trc() As Double = {minmax(3), minmax(4), minmax(5)} DrawBox(tlc, trc, , 36) ' 36 = Green 'EchoBoundingBoxValues(tlc, trc, obj) End If Catch ex As NXException EchoError(ex, "Can not calculate Bounding Box from : " & obj.JournalIdentifier, 0) End Try 'End If Next End Sub

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-13-2017 12:13 PM

Here's what I wrote yesterday in Python. It does the rotation into View Space before checking if the bounding box grows the boundaries. That way it doesn't need to keep track of Z at all, which is always 0 in View Space. It is neat to see the similarities between our approaches:

def matrixProduct3B3x3B1(list3B3, list3B1): x, y, z = list3B1 a, b, c, p, q, r, u, v, w = list3B3 i = a*x + b*y + c*z j = p*x + q*y + r*z k = u*x + v*y + w*z resultList3B1 = [i, j, k] return(resultList3B1)

People might wonder why I wrote the matrix multiplication function above - basically I need to keep the scripts to bare Python 3.3.2 so that they can be run by anone with NX10 installed. I only need this one type of matrix multiplication, so this was the easiest way to get it done.

def findExtentsOfViewsMBD0MBD2(self): noIssuesFlag = True minXMBD0 = 100000.0 maxXMBD0 = -100000.0 minYMBD0 = 100000.0 maxYMBD0 = -100000.0 minXMBD2 = 100000.0 maxXMBD2 = -100000.0 minYMBD2 = 100000.0 maxYMBD2 = -100000.0 viewMBD0 = self.theWorkPart.Views.FindObject('MBD0') viewMBD2 = self.theWorkPart.Views.FindObject('MBD2') rotMatrixMBD0 = [viewMBD0.Matrix.Xx, viewMBD0.Matrix.Xy, viewMBD0.Matrix.Xz, viewMBD0.Matrix.Yx, viewMBD0.Matrix.Yy, viewMBD0.Matrix.Yz, viewMBD0.Matrix.Zx, viewMBD0.Matrix.Zy, viewMBD0.Matrix.Zz] rotMatrixMBD2 = [viewMBD2.Matrix.Xx, viewMBD2.Matrix.Xy, viewMBD2.Matrix.Xz, viewMBD2.Matrix.Yx, viewMBD2.Matrix.Yy, viewMBD2.Matrix.Yz, viewMBD2.Matrix.Zx, viewMBD2.Matrix.Zy, viewMBD2.Matrix.Zz] solidsAndComponentsToFit = [] for eachBody in self.allSolidBodies: solidsAndComponentsToFit.append(eachBody) #... for eachItem in solidsAndComponentsToFit: try: thisBB = self.theUFSession.ModlGeneral.AskBoundingBox(eachItem.Tag) except: noIssuesFlag = False continue negX, negY, negZ, posX, posY, posZ = thisBB cornerVertsModelSpace = [[negX, negY, negZ], [posX, negY, negZ], [negX, posY, negZ], [posX, posY, negZ], [negX, negY, posZ], [posX, negY, posZ], [negX, posY, posZ], [posX, posY, posZ]] for oneCorner in cornerVertsModelSpace: X0, Y0, Z0 = matrixProduct3B3x3B1(rotMatrixMBD0, oneCorner) X2, Y2, Z2 = matrixProduct3B3x3B1(rotMatrixMBD2, oneCorner) if X0 < minXMBD0: minXMBD0 = X0 if X0 > maxXMBD0: maxXMBD0 = X0 if Y0 < minYMBD0: minYMBD0 = Y0 if Y0 > maxYMBD0: maxYMBD0 = Y0 if X2 < minXMBD2: minXMBD2 = X2 if X2 > maxXMBD2: maxXMBD2 = X2 if Y2 < minYMBD2: minYMBD2 = Y2 if Y2 > maxYMBD2: maxYMBD2 = Y2 minXMBD0 = (math.floor(minXMBD0*100))/100 maxXMBD0 = (math.ceil(maxXMBD0*100))/100 minYMBD0 = (math.floor(minYMBD0*100))/100 maxYMBD0 = (math.ceil(maxYMBD0*100))/100 minXMBD2 = (math.floor(minXMBD2*100))/100 maxXMBD2 = (math.ceil(maxXMBD2*100))/100 minYMBD2 = (math.floor(minYMBD2*100))/100 maxYMBD2 = (math.ceil(maxYMBD2*100))/100 extentsMBD0 = [minXMBD0, maxXMBD0, minYMBD0, maxYMBD0] extentsMBD2 = [minXMBD2, maxXMBD2, minYMBD2, maxYMBD2] return(extentsMBD0, extentsMBD2, noIssuesFlag)

Much of the end of the function is to round the dimensions to the nearest appropriate hundreth of an inch. I needed to make sure that the left extent went more left and the right extent went more right, same with top and bottom.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-13-2017 12:26 PM

FWIW, the NXOpen API provides some matrix functions, including vector/matrix multiplication.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-13-2017 02:28 PM

This seems to only offer vector*matrix, and I think the rotation matrix needs to be applied as matrix*vector to get the correct (expected) answer? There is an option to transpose the matrix during multiplication, and I guess I could transpose the vector before multiplication and then transpose the result afterwards. But at that point I've written an extra function anyway to do those gyrations...

Unless I'm missing something built in to another module again?

Follow Siemens PLM Software

© 2018 Siemens Product Lifecycle Management Software Inc