cancel
Showing results for 
Search instead for 
Did you mean: 

From a .sim file setting an .afm as the work part then back to the .sim file - How to?

Phenom
Phenom

To all,

 

I am trying to set-up a "call" to make the .afm (or .fem) file the work part (not the display part) from the .sim file then back again to the .sim file.  I have recorded the steps required (see below) but I am a bit stuck in replacing the .FindObject(). I am sure I have read somewhere that .FindObject() should not be used if not in a recorded journal. I cannot find the appropriate command in the doc. Can anyone point me in the right direction?

 

In the code below I have tried replacing the string in the.FindObject ()  and it seems to work but I suspect it implies that there is only 1 .afm attached to the .sim. Is this correct or is there a way of making the code more general?

 

The problem is related to an attempot at checking that an element exist

 1. Element ID is user supplied,

 2. The main programme oncly works in (from) the .sim,

 3. in the execution of the main programme, check that the element ID exists in the .afm or .fem associated with that .sim)

 

Thanks in anticipation

Regards

JXB

 

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String) 

	Dim theSession As Session = Session.GetSession()
	Dim workSimPart As CAE.SimPart = CType(theSession.Parts.BaseWork, CAE.SimPart)
	
	Dim theSimPart As CAE.SimPart = theSession.Parts.BaseWork
	Dim theFEMCAEPart As CAE.CaePart = theSimPart.FemPart
	Dim strAFMName as String = theFEMCAEPart.Leaf
	
	strAFMName = "COMPONENT "& strAFMName &" 1"
				
	Dim displaySimPart As CAE.SimPart = CType(theSession.Parts.BaseDisplay, CAE.SimPart)

	Dim markId1 As Session.UndoMarkId
	markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Make Work Part")

	'AS RECORDED Dim component1 As Assemblies.Component = CType(workSimPart.ComponentAssembly.RootComponent.FindObject("COMPONENT my_afem_test 1"), Assemblies.Component)

	Dim component1 As Assemblies.Component = CType(theSimPart.ComponentAssembly.RootComponent.FindObject(strAFMName), Assemblies.Component)
	
	Dim partLoadStatus1 As PartLoadStatus
	theSession.Parts.SetWorkComponent(component1, partLoadStatus1)

	Dim workAssyFemPart As CAE.AssyFemPart = CType(theSession.Parts.BaseWork, CAE.AssyFemPart)

	partLoadStatus1.Dispose()

	Dim markId2 As Session.UndoMarkId
	markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Make Work Part")

	Dim nullAssemblies_Component As Assemblies.Component = Nothing

	Dim partLoadStatus2 As PartLoadStatus
	theSession.Parts.SetWorkComponent(nullAssemblies_Component, partLoadStatus2)

	workSimPart = CType(theSession.Parts.BaseWork, CAE.SimPart)
	partLoadStatus2.Dispose()

End Sub
End Module

 

 

 

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)
2 REPLIES

Re: From a .sim file setting an .afm as the work part then back to the .sim file - How to?

Siemens Phenom Siemens Phenom
Siemens Phenom

You don't need to find anything - you already know (assume) that the starting work part is a CAE.SimPart. The parent fem/afm is given by SimPart.FemPart. Knowing that, you simply switch the work part to whatever you want:

 

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String) 

	Dim theSession As Session = Session.GetSession()
	Dim theUI As UI = UI.GetUI()
	Dim theNXMB As NXMessageBox = theUI.NXMessageBox
	
	' This assumes you are starting with a SIM part as the work part
	Dim theSimPart As CAE.SimPart = theSession.Parts.BaseWork

	Dim theFEMCAEPart As CAE.CaePart = theSimPart.FemPart
				
	' Make the FEM part the work part
	theSession.Parts.SetWork(theFEMCAEPart)

	theNXMB.Show("simToFemToSim", NXMessageBox.DialogType.Information, "Work part is now the FEMCAE part")

	theSession.Parts.SetWork(theSimPart)

	theNXMB.Show("simToFemToSim", NXMessageBox.DialogType.Information, "Work part is now the SIM part")

End Sub
End Module

 

Re: From a .sim file setting an .afm as the work part then back to the .sim file - How to?

Phenom
Phenom

Thanks you very much JimB. The swith back-and-forth works. So that the (original) problem's fixed. The probleme remains that I can never confirmed (find) an user specifed element (it does exist!!). Below is the test code with your suggestion embodied. The 'elementMap' & 'theFeElement' have worked in the past but as son as I try to add it to my main code it never find the element!

 

Thanks

 

Regards

 

 

Option Strict Off
Imports System
Imports System.IO
Imports System.Collections

Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.CAE
Imports NXOpen.Utilities
Imports NXOpen.BlockStyler

Module Module1
 
Dim theUI As NXOpen.UI = NXOpen.UI.GetUI()
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
Dim theFeElement As CAE.FEElement
Dim elementMap As CAE.FEElementLabelMap	
		
    Sub Main()
        
Dim theSimPart As CAE.SimPart	'the .sim file
Dim theFEMCAEPart As CAE.CaePart 'the fem/afm associated with the .sim
Dim theFEMPart As CAE.FemPart	'the .fem associated with .sim
Dim theAssyFemPart As CAE.AssyFemPart 'the .afm associated with .sim

       lw.Open()

'*************************************** 'the element number we are interested in Dim lngElemID as Long = 136 '504 '*************************************** theSimPart = theSession.Parts.BaseWork theFEMCAEPart = theSimPart.FemPart If theFEMCAEPart.GetType is GetType(CAE.AssyFemPart) Then theAssyFemPart = theSimPart.FemPart lw.writeline("Work part is now the FEMCAE part") theSession.Parts.SetWork(theFEMCAEPart) elementMap=theAssyFemPart.BaseFEModel.FeelementLabelMap theFeElement = elementMap.GetElement(lngElemID) If (theFeElement Is Nothing) Then lw.WriteLine ("--Specified Element ID was not found - Line is skipped") Else lw.WriteLine ("--Specified Element ID was found") End If lw.writeline("Work part is now the SIM part") theSession.Parts.SetWork(theSimPart) Else lw.writeline("it's a .fem") End if
End Sub End Module

 

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)