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:

Running a VBScript from .net


Recommended Posts

Got this partially working so another question. I have gotten the script to fire when needed but while c-hook is running I cannot manipulate the model. How can I rotate the model with the mouse while the vb program is still running. If I run the script using the vb command I can manipulate the model it's only when I run the script thru the c-hook.

Sorry if I can't explain it clearly I am just a self taught VB programmer

Here is what I have:

 bReturn = Mastercam.Support.ExternalAppsManager.RunVBScript(ScriptName)
            If bReturn = False Then 'error running script
                MsgBox("There was a problem running script " & ScriptName, vbOK, "Script Error")
                Exit Sub
            Else
                Me.Close() ' done goodbye
                End If
            End If

Link to comment
Share on other sites

Thanks for the reply Mick, Here is the basic portion of the script that I'm running. We have a lot of little scripts that we run so I was trying to create a simple menu system where the user simply selects a script from a list box, the the script runs and the c-hook exits. Like you mentioned if script does not need the user it all works fine. I might use this as a reason to play more with the .Net and have the list box filled with VBS and/or Chooks with out the user needing to know which is which. Most of the script are very simple so maybe convert them all to c-hooks. Like all of our projects here the only limit is time.

Any pointers that could help would be helpful as I am very new to this C-Hook stuff

 Call GetChain ("Select Edge Curves for Pin Boss Milling.") '// prepare to change attributes
    '// Loop thru selected curves and set attribs
        
        Do 
            Call SetEntityColor (NewColor)
            Call SetEntityLevel (NewLevel)
            '//SetEntityStyle(NewStyle)
            
            bRet = MoveForwardOnChain()
                If bret = false then 
                    bret = MoveToNextChain
                End if
            
        Loop While bRet
         
        FreeChains()

Link to comment
Share on other sites

Karl,

We do not have the “Break Many Pieces” functionality in the NET-Hook API.

We have created a Story for this -> S-53715 : API - NET-Hook - Add support for "Break Many Pieces"

 We do have a Mastercam 2018 C-Hook that can be called by a NET-Hook project that Breaks all currently selected (Line/Arc/Spline) entities “by tolerance” (0.001”) into lines/arcs.

Let me know if you would like a copy for 2017 and/or 2018

Link to comment
Share on other sites

Karl,

The source code for this C-Hook is not available. The offer is to supply a pre-built C-Hook DLL for either 2017 and/or 2018.

As mentioned, a story has been entered into our system to add this to the NET-Hook API in the future ->

We have created a Story for this -> S-53715 : API - NET-Hook - Add support for "Break Many Pieces"

 

Link to comment
Share on other sites
  • 6 months later...

Yea,  I've had some free time to work on this. So the next question I have is how to run an existing C-hook (.dll) file from within the menu c-hook. I have all the scripts and c-hooks from a custom folder displayed in a window. The scripts run when double clicked or selected and run button clicked. I looked at the ExternalAppsManager and found the postFT/RunFT but do not know how to feed it the program to run ( assuming this is even close to the right path ).

Link to comment
Share on other sites

Karl,

Is it critical that your VBScript run from within the C-Hook or Net-hook dialog box?

The reason I ask is that we've had the "Script Linker" utility available for a while. This utility allows you to map a VBScript to a Button in the Mastercam interface.

The beauty of this is that you just have a series of buttons on a Ribbon or Toolbar, and each button launches a script. Since the script runs through the normal VB launch process, you can manipulate the Mastercam geometry or toolpath database. 

Link to comment
Share on other sites

In the NET-Hook API, you have ->

PostFTCommand (String AppName, String CommandString);

RunFTCommand (String AppName, String CommandString); // in Mastercam 2019

In The C-Hook SDK, you have ->

post_FT_command (CString appName, CString entryName);

Just like it sounds, you’re firing a Function Table (FT) command.

You feed these functions with these parameters.

The name of the application and the name of the function in that application DLL.

In the target FT file, (showing a C-Hook style FT here) you have…

APPLICATION "CreatePlaneAddIn"                

FUNCTION CPP "m_main"

If you’re firing a function in a NET-Hook DLL, you would use…

APPLICATION "ImportOperationsExample"

FUNCTION NET "Run"

Link to comment
Share on other sites

Thanks for the prompt replies

Colin, I think at this time that it is important to have the scripts  run from within the c-hook. The ultimate goal of the app is to  check the user name and display a set of scripts / c-hooks depending on the user.

 

Roger, I'll have to play with this, I thought the application was always MasterCam but seems it can be any valid DLL that has a valid FT file. Is this correct?

Link to comment
Share on other sites
Quote

I thought the application was always MasterCam but seems it can be any valid DLL that has a valid FT file. Is this correct?

The application name is only "Mastercam" if it is Mastercam "internal". 

Never use "Mastercam" as the application name in a FT file that you have created.

As I described, you can call any function declared in any FT file. Which of course include your own FT/DLL combos.

Link to comment
Share on other sites

I have ran into something that is puzzling me with this project. 

It seems that the Application to be run ( as found in the ft file ) is case sensitive and that the app name does not always match the DLL name with regards to the case.

As of now  now the list is populated with the .DLL file name as found in the c-hook folder. If the application name exactly matches the dll file name then all works as it should.

If that's is true my workaround would be to create a collection of the *.FT files then parse each one for the application name. This name would feed the menu list  to fire the correct application.

This seems like a convoluted way to accomplish this task. Am I on the right path or is there a better / different way to get a list of all the Application Names from all the FT files in the c-hook directory?

Link to comment
Share on other sites
On 8/20/2018 at 4:44 PM, Karl@CP PISTONS said:

If the application name exactly matches the dll file name then all works as it should.

The APPLICATION "name" in the FT is a unique ID for the add-in.  It does not have to match, or even contain the name of the actual DLL file.

unique ID means exactly that, so the name given for this is case sensitive -> APPLICATION "MyAddIn"

The FUNCTION "name" is the actual name of the function (method) to be run in the Add-In DLL.

And of course function names are case sensitive.

Link to comment
Share on other sites

Thanks for all the help Roger. I have it parsing all the *FT files and extracting the "Application name" to populate the list box.  And script or Application firing works just fine.

My next step will be to have an INI file to add only script / programs that each user wants / needs. 

It's been a learning curve but glad I finally have a few days to actually work on this.

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