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:

VBS to NEThook question


Recommended Posts

With VBS,  I can get OP's number  form  the specified mcx-9 file.  

[vbs code]
......
Dim fn,n
fn="C:\Test\test.MCX-9"
n=GetOperationCount(fn)
......

The focus is: I don't have to open the target file. (Or it opens in the background but does not affect my current file.)

Now,  with NEThook (X9) , It seems that I need open the file first, then i can get the Number of OP ?

I have 2 questions:

1. Is there any way to get  information without opening the target file?  

2. Or, embed a "vbs file" into the dll ( nethook project ) and then call it directly with the "RunVBScript" Method. Can this be achieved?


Thank you for your help.

Link to comment
Share on other sites

A NET-Hook can call/execute a VB Script.
The script could then write out this “count” to some known location (file) that the NET-Hook add-in would read
The NET-Hook equivalent to obtain this information would be the GetOpGroupDataInExternalFile method.

        ''' <summary> Gets data from an external Mastercam part file. </summary>
        '''
        ''' <remarks> NOTE! A Mill/Router type Machine Group MUST exist in the
        '''           *active* file (not the file being interrogated) in order
        '''           for GetOpGroupDataInExternalFile to return any data. </remarks>
        '''
        ''' <param name="filename"> Full path name of the file to interrogate. </param>
        '''
        ''' <returns> A list of the operation names. </returns>
        Public Function GetData(ByVal filename As String) As List(Of String)
            Dim opNames = New List(Of String)()
            If File.Exists(filename) Then
                ' These parameter values must be pre-initialized as empty.
                ' They are filled in by GetOpGroupDataInExternalFile
                Dim grpData = New Mastercam.Support.Types.ExternalGroupsFileData() {}
                Dim opData = New Mastercam.Support.Types.ExternalOpsFileData() {}
                Dim result = SearchManager.GetOpGroupDataInExternalFile(filename, grpData, opData)

                If result Then
                    For Each op As Mastercam.Support.Types.ExternalOpsFileData In opData
                        ' Note that if the "name" has not been altered by the user,
                        ' the operation has no name assigned to it and will be empty!
                        opNames.Add(op.Name)
                    Next
                End If
            End If
            Return opNames
        End Function


 

  • Thanks 1
Link to comment
Share on other sites

When i call the GetOpGroupDataInExternalFile method, it can get “Operation Comment”、“ID ”、“Tool” and “OpCode” (Operation types code? data type Integer ).

In the old version of C-HOOKS, it seems that I have seen header files about opcodes. It should be :
TP_CONTOUR 1     //contourI
TP_XFORM 4    // mirror, rotate, translate
TP_MANUAL_ENTRY 17     //manual entry
...

Is this possible if I want to get the toolpath'name(like contour, manual entry...) from OpCode? Or where can i get the information of OpCode (X9) ?

    I want to try to imitate "Import Toolpath Operations dialog box",  It must be used in Toolpath Manager with right-click every time.I want to set the shortcut to enter, but I have not found a way.
   So I tried to write a NetHook , and support drag and drop mcx-9 files, which will greatly improve efficiency.
   But at present, this is very difficult: reading the toolpath parameters is one aspect, and it is not difficult to implement drag and drop in Windows Form, but it seems not easy to implement in mastercam.
   I am very sorry that I am not very proficient programming languages, so this is a big... challenge. 😰

Thank you for any suggestions.

 

Link to comment
Share on other sites

The opcode value it gives you is the same code value as in the C-Hook SDK.
In the C-Hook SDK, see in \interfaces\Core\ToolpathOperationCodes_CH.h
Search for this enumeration of OpCode values -> enum TP_OPCODE
Just like in a C-Hook you don't get a (string) "name" like -> TP_MANUAL_ENTRY
These names you mention (like TP_MANUAL_ENTRY) are the names of the items in the enum(eration).
You could easily create your own lookup for gettg the "name" from the code number.

Note that the NET-Hook API does not support manipulating every toolpath operation type.
That may (or may not) affect you after you have loaded those operations.
It depends on what you are trying to do.

Quote

It must be used in Toolpath Manager with right-click every time. I want to set the shortcut to enter, but I have not found a way.

You want to be able to have your add-in run when the user right clicks in Mastercam's Toolpath Manager?
Not possible. You can start an add-in via an icon clicked in the UI and/or if it's mapped been to a keystroke.

  • Thanks 1
Link to comment
Share on other sites
  • 2 weeks later...
On 7/23/2019 at 9:31 PM, Roger Martin from CNC Software said:

The opcode value it gives you is the same code value as in the C-Hook SDK.
In the C-Hook SDK, see in \interfaces\Core\ToolpathOperationCodes_CH.h
...

May I ask another question? Sir.


GroupManager.GetAllGroups Method

I can't understand how it works. 😳

How is it applied, can it output a list of groups?
 

 

 

 

Link to comment
Share on other sites

See -

GroupManager.GetAllGroups Method in NET-Hook API Docs ->
https://nethookdocs.mastercam.com/content/html/4267c9cf-5183-137f-c8dc-bad2fcdc3aed.htm

 

''' <summary> The names of all the Machine and Toolpath groups. </summary>
''' <param name="machineGroupNames">  [out] A list of names of all the Machine Groups. </param>
''' <param name="toolpathGroupNames"> [out] A list of names of all the Toolpath Groups. </param>
''' <returns> The total number of groups that were processed. </returns>
Private Function GetGroupNames(ByRef machineGroupNames As List(Of String), ByRef toolpathGroupNames As List(Of String)) As Integer
    machineGroupNames = New List(Of String)()
    toolpathGroupNames = New List(Of String)()
    Dim groups = New List(Of Group)()
    Dim onlyMachineGroups As Boolean = False
    GroupManager.GetAllGroups(groups, onlyMachineGroups)
    For Each grp In groups
        If grp.IsMachineGroup() Then
            machineGroupNames.Add(grp.Name)
        ElseIf grp.IsToolpathGroup() Then
            toolpathGroupNames.Add(grp.Name)
        End If
    Next
    Return machineGroupNames.Count + toolpathGroupNames.Count
End Function

 

  • Thanks 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...