Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

rename nciname by toolgroup name


Recommended Posts

vb.net 2008 X5

how can i do rename nciname by toolgroup name,below code run fail,thanks

 

          For Each groups As Mastercam.Support.Group In Mastercam.Support.SearchManager.GetGroups()

               For Each op_s As Mastercam.Database.Operation In SearchManager.GetOperations
                   op_s.NCIName = group_name & Str(intCount) & ".NCI"
                    op_s.Commit()
                    If (op_s.Dirty) Then
                        op_s.Regenerate()
                    End If
               Next
               intCount = intCount + 1
           Next

Link to comment
Share on other sites
12 hours ago, Roger Martin from CNC Software said:

Could we get a bit more information here? Any errors? 

What are the specific types of the toolpath operation you are trying to .Commit?

 

no any error,all operation nci name are same last group name, I want rename operation nci by group name

Toolpath Group-1  nci name Toolpath Group-1.nci

Toolpath Group-2  nci name Toolpath Group-2.nci

Toolpath Group-3  nci name Toolpath Group-3.nci

Toolpath Group-4  nci name Toolpath Group-4.nci

..etc.

thanks

Link to comment
Share on other sites

This code tested in Mastercam X9 (using the NETHook3_0 API).
It is possible that it may not work in older versions.


Imports System.IO
Imports Mastercam.Support

Namespace ChangeToolpathName

    Public Class ChangeNCI
        ''' <summary> Change the NCI/NC output name in the selected operations. </summary>
        '''
        ''' <param name="onlySelectedOps"> (Optional) True to only process 'selected' operations, false to do all of the ops. </param>
        '''
        ''' <returns> The number of operations that were altered. </returns>
        Public Function ChangeName(Optional onlySelectedOps As Boolean = False) As Integer
            Dim count = 0

            Dim ops = SearchManager.GetOperations(onlySelectedOps)

            For Each op As var In ops
                ' Find the Group this Operation is in and then get the Name of that Group.
                Dim groupNumber = op.GroupNumber
                Dim group As Mastercam.Support.Group = GroupManager.FindGroupByID(groupNumber)

                ' Get the output folder path.
                Dim nciPath = Path.GetDirectoryName(op.NCIName) + "\"

                ' *** NOTE ***
                ' A Group Name could contain characters that are invalid for a path\name!
                ' We are NOT doing any checking for that situation here!

                ' Build up the new toolpath output file name.
                Dim newPath = nciPath + group.Name + ".NCI"
                op.NCIName = newPath

                ' Older Mastercam may not have this true/false parameter on .Commit()
                If op.Commit(False) Then
                    count += 1
                End If
            Next

            Return count
        End Function
    End Class
End Namespace

Edited by Roger Martin from CNC Software
Link to comment
Share on other sites
25 minutes ago, Roger Martin from CNC Software said:

This code tested in Mastercam X9 (using the NETHook3_0 API).
It is possible that it may not work in older versions.


Imports System.IO
Imports Mastercam.Support

Namespace ChangeToolpathName

    Public Class ChangeNCI
        ''' <summary> Change the NCI/NC output name in the selected operations. </summary>
        '''
        ''' <param name="onlySelectedOps"> (Optional) True to only process 'selected' operations, false to do all of the ops. </param>
        '''
        ''' <returns> The number of operations that were altered. </returns>
        Public Function ChangeName(Optional onlySelectedOps As Boolean = False) As Integer
            Dim count = 0

            Dim ops = SearchManager.GetOperations(onlySelectedOps)

            For Each op As var In ops
                ' Find the Group this Operation is in and then get the Name of that Group.
                Dim groupNumber = op.GroupNumber
                Dim group As Mastercam.Support.Group = GroupManager.FindGroupByID(groupNumber)

                ' Get the output folder path.
                Dim nciPath = Path.GetDirectoryName(op.NCIName) + "\"

                ' *** NOTE ***
                ' A Group Name could contain characters that are invalid for a path\name!
                ' We are NOT doing any checking for that situation here!

                ' Build up the new toolpath output file name.
                Dim newPath = nciPath + group.Name + ".NCI"
                op.NCIName = newPath

                ' Older Mastercam may not have this true/false parameter on .Commit()
                If op.Commit(False) Then
                    count += 1
                End If
            Next

            Return count
        End Function
    End Class
End Namespace

Roger isn't that really the best move to update and get with current coding methods and processes? X5 wow that is going back to the either 32bit or 64bit possibility of coding.

Link to comment
Share on other sites
  • 2 weeks later...
On 20.5.2017 at 7:39 PM, Lee1 said:

vb.net 2008 X5

how can i do rename nciname by toolgroup name,below code run fail,thanks

 

          For Each groups As Mastercam.Support.Group In Mastercam.Support.SearchManager.GetGroups()

               For Each op_s As Mastercam.Database.Operation In SearchManager.GetOperations
                   op_s.NCIName = group_name & Str(intCount) & ".NCI"
                    op_s.Commit()
                    If (op_s.Dirty) Then
                        op_s.Regenerate()
                    End If
               Next
               intCount = intCount + 1
           Next

 

X+ ;)

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...