Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

VBA macro for renaming multiple operations AGAIN 2

Status
Not open for further replies.

red987

Industrial
Oct 1, 2009
23
0
0
US
ok so I ran across a couple of posts that had information on this already. 2 yrs old and closed. hoping someone is watching "markrief" lol Looking for a variation on the file that was posted in the others. (RenameOperationsOntSelection) I need it to not ask me for what I am looking for as I already know since I selected it to begin with. What I do need is for it to ask me what I want them to be named. Then rename all in a sequential order adding 1 the number I start with on the information entered. Say WHAT_EVER_I_WANT_TO_NAME_IT_1 is what I put in then it adds 1 to the 1 at the end so the second becomes WHAT_EVER_I_WANT_TO_NAME_IT_2 the third WHAT_EVER_I_WANT_TO_NAME_IT_3 and so on until the last one is reached.

Here's to hoping someone has had the same desire but more vb knowledge.

Thanks in advance
 
Replies continue below

Recommended for you

No need to hunt for the program - I added the sample vb to rename operations to the NX installation several releases ago. You can find it in UGOPEN\SampleNXOpenApplications\.NET\CAM.

Mark Rief
Product Manager
Siemens PLM
 
the sample isn't exactly what I'm looking for. I was able to locate that file. what I am looking for is explained in my post is a modified version of it.

from my first post.....I need it to not ask me for what I am looking for as I already know since I selected it to begin with. What I do need is for it to ask me what I want them to be named. Then rename all in a sequential order adding 1 the number I start with on the information entered. Say WHAT_EVER_I_WANT_TO_NAME_IT_1 is what I put in then it adds 1 to the 1 at the end so the second becomes WHAT_EVER_I_WANT_TO_NAME_IT_2 the third WHAT_EVER_I_WANT_TO_NAME_IT_3 and so on until the last one is reached.
 
Try this:

Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UF.UFoper
Imports NXOpen.CAM
Imports NXOpenUI


Module NXJournal
Dim OPERATIONGROUP As String
Dim NEWNAME As String

Dim m_OperationList() As String



Sub Main
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim theUISession As UI = UI.GetUI

Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display



OPERATIONGROUP = NXInputBox.GetInputString("Enter Group Name to edit", "Renaming Tool", "PROGRAM")
NEWNAME = NXInputBox.GetInputString("Enter New Name for operations", "Renaming Tool", "MYNEWNAME")
NEWNAME = ucase(NEWNAME)
Dim MainProg As CAM.NCGroup = CType(WorkPart.CAMSetup.CAMGroupCollection.FindObject(OPERATIONGROUP), CAM.NCGroup)

'List all the ops in the program
Dim Opnames() As String = OperationList(MainProg.Tag)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim counter As Integer = 1
For Each Op As String In Opnames
theUfSession.Ui.SetStatus("Renaming Operation:" & OP)

Dim operation As CAM.Operation


operation = CType(WorkPart.CAMSetup.CAMOperationCollection.FindObject(Op), CAM.Operation)
operation.SetName(NEWNAME & counter)

counter += 1

Next
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
msgbox(counter - 1 & " OPERATIONS HAVE BEEN RENAMED")
End Sub

Public Function OperationList(ByVal sTag As NXOpen.Tag) As String()
Dim theUfSession As UFSession = UFSession.GetUFSession()
m_OperationList = Nothing

Dim ptr As IntPtr = New System.IntPtr
Dim cycle_cb_fn As NXOpen.UF.UFNcgroup.CycleCbFT = New NXOpen.UF.UFNcgroup.CycleCbFT(AddressOf cycle_OperationList)

'Cycle throught this view and find every object
theUfSession.Ncgroup.CycleMembers(sTag, cycle_cb_fn, ptr)

Return m_OperationList

End Function

Private Function cycle_OperationList(ByVal camObjectTag As Tag, ByVal ptr As IntPtr) As Boolean

Dim camObject As CAM.CAMObject = NXOpen.Utilities.NXObjectManager.Get(camObjectTag)

'Check if the object is an Operation
If TypeOf camObject Is CAM.Operation Then

If m_OperationList Is Nothing Then
ReDim m_OperationList(0)
Else
ReDim Preserve m_OperationList(m_OperationList.Length)
End If

m_OperationList(UBound(m_OperationList)) = camObject.Name

End If

Return True

End Function


End Module
 
props to KS1971 that does exactly what I need... you have saved my cohorts and myself considerable time. Much appreciated..[2thumbsup]
 
Status
Not open for further replies.
Back
Top