Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

FindObject("PROTO#.Bodies *** in Journal VB

Status
Not open for further replies.

lklo

Industrial
Nov 24, 2010
226
Hi

I´m writing on a little script , that will help me get quicker starting on a new EDM electrode part.

I use the the "Create New Parent" to create an assembly,
and the Electrode part will be the top part - and the core and cavity plate is the component.
I have made som VB tricks to automate the new name of the Electrode part. Everything works fine - but I have one problem.

In the new part I want to make a Linked Body of the component´s solid body (core or cavity plate).

In the recorded journal I have edited the "COMPONENT CavityPlatePart 1" so it is a variable of the component name.
That works 100%.

recorded journal :
>> Dim component1 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT CavityPlatePart 1"), Assemblies.Component) <<

But, and here comes the problem.

recorded journal :
>> Dim body1 As Body = CType(component1.FindObject("PROTO#.Bodies|EXTRUDE(1)"), Body) <<

I can´t get a solution to create a variable of the component´s Solid Body name, so I can replace the EXTRUDE(1) in ("PROTO#.Bodies|EXTRUDE(1)"), with a variable.

Maybe someone here can the trick ?

lklo



 
Replies continue below

Recommended for you

I often apply a name to a body so that it becomes a simple journal/program task to find the body. The small example code finds and highlights a body that has the name WHATEVER applied to it.

Option Strict Off
Imports System
Imports NXOpen

Module FindNamedObject
Sub Main()
Dim s As Session = Session.GetSession()
Dim workPart As Part = s.Parts.Work
Dim bodies As BodyCollection = workPart.Bodies
Dim bodyname As String = "WHATEVER"

For Each b As Body In bodies
If Not b.IsBlanked Then
If b.Name = bodyname Then
b.Highlight()
End If
End If
Next
End Sub

Just change the bodyname string to whatever you might apply to the required body.

Hope this helps.

Frank Swinkels
 
Hello Frank

Thank You for the answer.

But your solution in my case is not what I need.



I need to be able to create a linked body of the displayed componet( always a solid body on layer 1).

I can get the component in a variable.But not the body.

I have tried with the command DisplayableObject
but I cant figure it out.

lklo
 
OK for an assembly it is better to use object cycle by name as in the simple journal/program below.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Utilities
Imports NXOpen.UF

Module FindNamedObject

Sub Main()
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()

Dim bodyname As String = "WHATEVER"
Dim obj As Body
Dim objTag As Tag = Tag.Null

ufs.Obj.CycleByName(bodyname, objTag)
If objTag <> Tag.Null Then
obj = NXObjectManager.Get(objTag)
obj.Highlight()
End If

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Hope this helps.

Frank Swinkels
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor