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 Replacing FindObject from a Journal

Status
Not open for further replies.

EngProgrammer

Aerospace
Jan 14, 2015
150
Dear Forum,

I am trying to find the equivalent for the following journal code CType(component1.FindObject("PROTO#.Bodies|LINKED_BODY(0)"), NXOpen.Body). I have babdy within a component of an assembly. I can get at the component but I need to get at the solid body within the component. Does anyone know how to reference into the solid body instance inside the component?

Thanks
 
Replies continue below

Recommended for you

If you have a reference to an occurrence body, you can use theBody.Prototype to get a reference to the prototype body. (Edit for completeness) Conversely, if you have a reference to the prototype body and the component, you can use the component's .FindOccurrence method to get a reference to the occurrence body.

If all you have is a reference to the component and you need to find the used body(ies), you can query the component's used reference set, then cycle through the component part's ref set objects looking for the body.

www.nxjournaling.com
 
Hi cowski,

Below is a generic subroutine that I am creating to make a wavelink body in the parent of a component assembly. The line I am having issues with is Dim body1 As NXOpen.Body = CType(component1.FindObject("PROTO#.Bodies|LINKED_BODY(0)"), NXOpen. The components have solid bodies. In which namespace am I getting references into the assembly structure. "theUFsession.Assem.??" I haven't worked with this namespace and it's concepts.


Code:
Public Shared Sub CreateWaveLinkBody(ByVal ComponentToBeWaveLinked As NXOpen.Assemblies.Component)

        Dim waveLinkBuilder1 As NXOpen.Features.WaveLinkBuilder
        waveLinkBuilder1 = workpart.BaseFeatures.CreateWaveLinkBuilder(Nothing)

        Dim extractFaceBuilder1 As NXOpen.Features.ExtractFaceBuilder
        extractFaceBuilder1 = waveLinkBuilder1.ExtractFaceBuilder

        extractFaceBuilder1.FaceOption = NXOpen.Features.ExtractFaceBuilder.FaceOptionType.FaceChain

        waveLinkBuilder1.Type = NXOpen.Features.WaveLinkBuilder.Types.BodyLink

        extractFaceBuilder1.FaceOption = NXOpen.Features.ExtractFaceBuilder.FaceOptionType.FaceChain

        extractFaceBuilder1.AngleTolerance = 45.0

        waveLinkBuilder1.Associative = False

        waveLinkBuilder1.CopyThreads = False

        extractFaceBuilder1.ParentPart = NXOpen.Features.ExtractFaceBuilder.ParentPartType.OtherPart

        extractFaceBuilder1.Associative = False

        extractFaceBuilder1.MakePositionIndependent = False

        extractFaceBuilder1.FixAtCurrentTimestamp = False

        extractFaceBuilder1.HideOriginal = True

        extractFaceBuilder1.InheritDisplayProperties = False

        Dim scCollector1 As NXOpen.ScCollector
        scCollector1 = extractFaceBuilder1.ExtractBodyCollector

        extractFaceBuilder1.CopyThreads = False

        extractFaceBuilder1.FeatureOption = NXOpen.Features.ExtractFaceBuilder.FeatureOptionType.OneFeatureForAllBodies

        Dim bodies1(0) As NXOpen.Body
        Dim theUI As UI = UI.GetUI()

        Dim component1 As NXOpen.Assemblies.Component = CType(ComponentToBeWaveLinked, NXOpen.Assemblies.Component)

        Dim body1 As NXOpen.Body = CType(component1.FindObject("PROTO#.Bodies|LINKED_BODY(0)"), NXOpen.Body)

        bodies1(0) = body1
        Dim bodyDumbRule1 As NXOpen.BodyDumbRule
        bodyDumbRule1 = workpart.ScRuleFactory.CreateRuleBodyDumb(bodies1, True)

        Dim rules1(0) As NXOpen.SelectionIntentRule
        rules1(0) = bodyDumbRule1
        scCollector1.ReplaceRules(rules1, False)

        Dim nXObject1 As NXOpen.NXObject
        nXObject1 = waveLinkBuilder1.Commit()

        waveLinkBuilder1.Destroy()

    End Sub
 
How do you want the body to be chosen for the wave link operation; do you want the user to make an interactive selection, or should the journal code find the body automatically?

If you want the journal code to find the body, what to do if the component contains multiple bodies in the reference set?

I don't see any reason to dive into the UfSession.Assem. functions just yet.

www.nxjournaling.com
 
Hi Cowski,

For now, there is only one solid body within the component. So, I am passing in the ComponentToBeWaveLinked. The code below works for a single level component in the tree. I am cycling through the part object occurrences then getting the try to cast that occurrence into a body. If successful than I have my body, I could probably exit the do loop at that time.

This code is working for a single component in the assembly. By it is not working for grandchildren in the assembly. I have one level of grandchildren. To get the grandchild component I am using: workpart.ComponentAssembly.RootComponent.GetChildren()(0).GetChildren()(0)

Code:
        Dim objectOcc As Tag = Tag.Null
        Dim aBody As Body = Nothing
        Do
            objectOcc = theUFSession.Assem.CycleEntsInPartOcc(component1.Tag, objectOcc)
            If objectOcc.Equals(Tag.Null) Then Exit Do
            Try
                aBody = CType(theSession.GetObjectManager().GetTaggedObject(objectOcc), Body)
            Catch ex As Exception
                '  Do Nothing
            End Try
        Loop While True
 
It really depends on what you want to do.
Is your goal to wave link all of the bodies up to the assembly level? If so, an easier method would be to get the occurrence bodies directly from the assembly file. The code below shows a way to do this.

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
 
Module Module59
    Sub Main()
 
        Dim theSession As Session = Session.GetSession()
        Dim theUfSession As UFSession = UFSession.GetUFSession
        Dim workPart As Part = theSession.Parts.Work
	Dim displayPart as Part = theSession.Parts.Display
 
        Dim theSolidBodies As New List(Of Body)
 
        Dim aBodyTag As Tag = Tag.Null
        Do
            theUfSession.Obj.CycleObjsInPart(displayPart.Tag, UFConstants.UF_solid_type, aBodyTag)
 
            If aBodyTag = Tag.Null Then
                Exit Do
            End If
 
            Dim theBody As Body = Utilities.NXObjectManager.Get(aBodyTag)
            If theBody.IsSolidBody Then
                theSolidBodies.Add(theBody)
            End If
 
        Loop While True
 
    End Sub
 
End Module

If your goal is to only wave link certain bodies, you could get all the bodies with the above code then iterate through the list and query the body to see which component owns it.

www.nxjournaling.com
 
In this situation there is only one child component and one grandchild component

I ended up doing this for the child component:

Dim theComponent1 As Assemblies.Component = workpart.ComponentAssembly.RootComponent.GetChildren()(0)
CType(theComponent1.Prototype, Part).LoadFully()
Dim compPart1 As Part = CType(theComponent1.Prototype, Part)
Dim theBody1 As Body = compPart1.Bodies.ToArray()(0)
Dim theBodyOcc1 As Body = CType(theComponent1.FindOccurrence(theBody1), Body)

I ended up doing this for the grandchild component:

Dim CastBody As Features.BodyFeature
Dim theComponent2 As Assemblies.Component = workpart.ComponentAssembly.RootComponent.GetChildren()(0).GetChildren()(0)
CType(theComponent2.Prototype, Part).LoadFully()
Dim compPart2 As Part = CType(theComponent2.Prototype, Part)
Dim theBody2 As Body = compPart2.Bodies.ToArray()(0)
Dim theBodyOcc2 As Body = CType(theComponent2.FindOccurrence(theBody2), Body)

Then passing the component body Occurrences at the parent level into the function for creating the wavelinked bodies. One trick that was hanging me up was to check to make sure that the component is fully Loaded.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor