Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Create new program object - journal

Status
Not open for further replies.

rafl

Mechanical
May 30, 2011
41
Here is a journal which creates cam program object. New program name is created from previously selected program name number +1 ( name[Integer] +1). Is it possible for journal to automatically find last created program (without preselect) get its name and create new one.
PS. How to check if Cam Object is program object and how to check if program already exists.

Code:
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.CAM
Imports NXOpen.UF
Imports NXOpen.Utilities

Module nextprog

    Dim theSession As Session
    Dim theUfSession As UFSession

    Sub Main()

        theSession = Session.GetSession()
        theUfSession = UFSession.GetUFSession()
        Dim WorkPart As Part = theSession.Parts.Work

        Dim setupTag As Tag
        Dim selectedTags() As NXOpen.Tag
        Dim selectedCount As Integer

        ' If there is a work part only then we can go further
        If WorkPart IsNot Nothing Then

            theUfSession.Cam.InitSession()
            theUfSession.Setup.AskSetup(setupTag)

            ' If there is a setup only then we go further
            If setupTag <> 0 Then
                ' Get the selected nodes from the Operation Navigator
                theUfSession.UiOnt.AskSelectedNodes(selectedCount, selectedTags)

                If selectedCount = 0 Then
                    MsgBox("Nothing selected", MsgBoxStyle.Exclamation)
                    Exit Sub
                End If
				
                Dim i As Integer

                For i = 0 To selectedCount - 1
				  Dim camObject As NXObject = NXObjectManager.Get(selectedTags(i))


          Dim CurrentName As String = camObject.Name()
				
				
				Dim value As String = CurrentName

				Dim int As Integer
				int = CInt(value)
				Dim Newname As Integer 
				Newname = int+1
		   
					 Dim nCGroup1 As CAM.NCGroup = CType(workPart.CAMSetup.CAMGroupCollection.FindObject("NC_PROGRAM"), CAM.NCGroup)
 

        Dim nCGroup2 As CAM.NCGroup
        nCGroup2 = workPart.CAMSetup.CAMGroupCollection.CreateProgram(nCGroup1, "mill_contour", "PROGRAM", CAM.NCGroupCollection.UseDefaultName.False, Newname)

       Dim programOrderGroupBuilder1 As CAM.ProgramOrderGroupBuilder
        programOrderGroupBuilder1 = workPart.CAMSetup.CAMGroupCollection.CreateProgramOrderGroupBuilder(nCGroup2)
		
        Dim nXObject1 As NXObject
        nXObject1 = programOrderGroupBuilder1.Commit()
        programOrderGroupBuilder1.Destroy()
					   
					   
                Next i
  
            End If

        End If
    End Sub

End Module
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor