Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

NXOPEN getting body information

Status
Not open for further replies.

jonathan8388

Aerospace
Jul 31, 2015
20
Hi everybody

I am relatively new with NXOPEN and am having some trouble particularly with NX bodies. Hoping somebody can help me

I made a code that allows the user to select a bunch of points, curves, and bodies on the screen and the information window will export the object name, feature name, type, and tag. This works by getting the tag of the selected object and then using that to get the information about that object and post to the listing window. This works fine if I am selecting these entities while the component they live in is the one that is open. However if i am selecting these on-screen while at an assembly level (and the points, curves, bodies are shown on screen but lie in a sub-component) then the bodies selection does not work.

For any body I select on screen, the code will only work if I am actively in the component that directly has the body. The code will NOT work if I select a body on screen that is under a different component (ie in a sub assembly). if i do this, i get an error that says "index as outside of the bounds of the array". The trouble seems to happen at the Tree_Obj_feature=myBody.getfeatures(0) line.

Does anyone know how to modify the code so i can get information on the selected bodies regardless of what sub-component they lie in?

I should note that when i select a body and print a mybody.tag to the LW, the tag of the SAME body is different based off of what component i currently have active. For instance, when i select that body while i have its owning component open, mybody.tag returns 59334. But when i select the same body while i am in a parent component (upper level assebly) that same body returns mybody.tag = 59933.

So I think it is pulling the wrong tag when i am selecting the body at a different assembly level. I dont know how to fix that.

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features
 
Module Get_Selected_Items

    Sub Main()
        
        Dim theSession As Session = Session.GetSession()
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim response2 As Selection.Response = Nothing
        Dim selectedObjects() As NXObject
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        Dim lw As ListingWindow = theSession.ListingWindow
        Dim Tree_Object As NXObject
        Dim Tree_Obj_Tagged as NXOpen.TaggedObject
        Dim Tree_Obj_feature as features.feature
        Dim featureTag As Tag
        lw.Open()
        
Start1:
Start2:
        response2 = Select_Objects(selectedObjects)
        If response2 = Selection.Response.Back Then GoTo Start1 ' Select a new face
        If response2 = Selection.Response.Cancel Then GoTo End1

For Each Tree_Object In selectedObjects
    if typeof Tree_Object is Nxopen.body then
        Dim myBody As NXOpen.body = CType(NXOpen.Utilities.NXObjectManager.Get(Tree_Object.Tag), NXObject)
        [b]Tree_Obj_feature=myBody.getfeatures(0)[/b]
        lw.WriteLine("|Name:" & Tree_Obj_feature.name & "|" & "Feature Name:" & Tree_Obj_feature.getfeaturename  & "|" &  "Type:" & typename(Tree_Object) & "|"  & "Tag:" & Tree_Obj_feature.tag)
    else
        theUfSession.Modl.AskObjectFeat(Tree_Object.Tag, featureTag)
        Tree_Obj_Feature=Utilities.NXObjectManager.Get(featureTag)
        lw.WriteLine("|Name:" & Tree_Obj_feature.name & "|" & "Feature Name:" & Tree_Obj_feature.getfeaturename  & "|" &  "Type:" & typename(Tree_Object) & "|"  & "Tag:" & Tree_Obj_feature.tag)
    end if
Next 
        GoTo Start2 ' Continue selecting points for current face
End1:
    End Sub

    Function Select_Objects (ByRef selectedObjects As NXObject())
        Dim ui As UI = ui.GetUI()
        Dim lineMask = New Selection.MaskTriple(NXOpen.UF.UFConstants.UF_line_type, NXOpen.UF.UFConstants.UF_all_subtype, 0)
        Dim PointMask = New Selection.MaskTriple(NXOpen.UF.UFConstants.UF_point_type, NXOpen.UF.UFConstants.UF_all_subtype, 0)
        Dim SolidMask = New Selection.MaskTriple(NXOpen.UF.UFConstants.UF_solid_type, NXOpen.UF.UFConstants.UF_all_subtype, 0)
        Dim Circ_Arc = New Selection.MaskTriple(NXOpen.UF.UFConstants.UF_circle_type, NXOpen.UF.UFConstants.UF_all_subtype, 0)
        Dim mask() As Selection.MaskTriple={lineMask,PointMask,SolidMask, Circ_Arc}
        Dim resp As Selection.Response  
	        resp = ui.SelectionManager.SelectObjects("Select Anything", "Select Anything", Selection.SelectionScope.AnyInAssembly,  Selection.SelectionAction.ClearAndEnableSpecific, False, False, mask, selectedObjects)
	        If resp = Selection.Response.Cancel Or resp = Selection.Response.Back Then
	            Return Selection.Response.Cancel
	        Else
	            Return Selection.Response.Ok
	        End If
    End Function
    
End Module


 
Replies continue below

Recommended for you

You can probably avoid the error by replacing that one line with the following:

Code:
If myBody.IsOccurrence() then
  Dim bodyInPart = CType((myBody.Prototype), NXOpen.Body)
  bodyInPart.OwningPart.LoadFeatureDataForSelection()
  Tree_Obj_feature=bodyInPart.getfeatures(0)
else
  Tree_Obj_feature=myBody.getfeatures(0)
end if

This will get you the actual geometry body tag in the owner part (and make sure it's loaded).

Which instance of the object you actually want to have here is a separate question.
 
The instance tag will be different from the prototype tag, this is normal and expected.

For a good overview of prototypes and occurrences, see the programming help -> getting started with SNAP guide (chapter 11).

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor