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:

Script examples needed


Recommended Posts

I am still using old school ( VB SCRIPT) until I can get my new school ( .NET ) built.

Will anyone pass along some examples of scripts and / or .NET projects that change the machining

parameters of a pre-existing tool and toolpath?  Actually, I would appreciate ANY examples

anyone would be willing to share.  All help is very much appreciated.

Steven

 

Link to comment
Share on other sites

Jeff,

Thank you for responding.  After MUCH searching I did not find any examples to download.  I did however, find where users

were asking questions about their own concerns.  I did not find anything regarding changing tool and toolpath parameters.

Perhaps I was simply looking in the wrong place, or did not understand what I was looking at.  

Much appreciation to anyone willing to give some assistance.

 

Steven

Link to comment
Share on other sites

Did you click the link?  That should have asked you to login, then sent you to a page to select the version of Mastercam you'd like examples for.

The example NET-Hooks will be much more helpful than anything I can provide, but below is an example NET-hook that updates all of the selected contour operations' cutter comp parameters.

        public override MCamReturn Run(int param)
        {
            var contourOperations = SearchManager.GetOperations(OperationType.Contour);

            if (contourOperations.Any())
            {
                var compensationParameters = new CutterCompParams
                {
                    ToTip = true,
                    Optimize = true,
                    RollCorners = CutterCompRoll.CutterCompRollSharp,
                    Direction = CutterCompDir.CutterCompLeft,
                    Type = CutterCompType.CutterCompComputer
                };

                foreach (var operation in contourOperations)
                {
                    if (operation.Selected)
                    {
                        var contourOperation = operation as ContourOperation;

                        contourOperation.CutterComp = compensationParameters;

                        contourOperation.Commit();
                        contourOperation.Regenerate();      
                    }
                }

                return MCamReturn.NoErrors;
            }
            else
            {
                DialogManager.Error("No contour operations found.", "No Contour Operations");

                return MCamReturn.ErrorOccurred;
            }          
        }
Link to comment
Share on other sites

Were you able to access the example files?  Among the example files is the API Reference for NETHook V3 that's very helpful.

At what point are you banging your bare toes against the curb?  Did you create a solution and get the hook to run?  Is it  that you can't determine how to do something?

Have you contacted your reseller?

 

Link to comment
Share on other sites

Jeff,

Thank you for following up.

I did locate the sample files on the website.  The issue may have been that I didn't log in, or something.

I did get VISUAL STUDIO up and running, and was able to install the sample project.

As I mentioned to my retailer, this must have been a training exercise in itself because the projects were

from a previous version and all the data paths had to be changed as well as some other references.

I did get a project to compile and copy the files into the chook folder.  I still get a "COM" error when

trying to DEBUG.  I am looking into that as time permits.  The project compiled with no errors or warnings

so I take that as a good sign.

 

I will go and try to find the API reference you mentioned.  I believe that may be my key.  After kicking the

curb for so long, I may now have a toe-hold.  Thanks again.

Steven

Link to comment
Share on other sites

Jeff,

I finally got the download.  I logged on, but did not find the files.

I contacted my retailer and he had the same issue until he "jiggled the handle"\

by refreshing the "Mastercam Version" window a few times.

Thanks again, will make for some interesting reading.

 

Steven

Link to comment
Share on other sites
  • 1 month later...

Hello all,

I am progressing with converting from VBSCRIPT to using VISUAL STUDIO to create nethooks.

I am currently trying to convert one of my scripts to a nethook.  Since the script has been working well, I thought it a good project to start with.

Can someone please pass along a project that shows how to do the equivalent in visual basic as the "Startdbsearch" / "Nextdbsearch"

routine did in VBSCRIPT?  I would like to select all existing geometry and sort it out.  I am still trying to get an understanding of the the

API.

 

Thanks for any help provided.

Steven

Link to comment
Share on other sites

I don't use VB.net but here is a C# example that selects all wireframe geometry in a Mastercam file.

namespace ExampleNetHook
{
    using System.Linq;

    using Mastercam.App;
    using Mastercam.App.Types;
    using Mastercam.Support;
    using Mastercam.IO;
    using Mastercam.Curves;
    using Mastercam.BasicGeometry;
    using Mastercam.Database.Types;

    public class Main : NetHook3App
    {
        #region Public Override Methods

        /// <summary>
        /// The main entry point for your NETHook.
        /// </summary>
        /// <param name="param">System parameter.</param>
        /// <returns>A <c>MCamReturn</c> return type representing the outcome of your NetHook application.</returns>
        public override MCamReturn Run(int param)
        {
            // Instanciate a GeomtryMask to select only wireframe geometry 
            var wireframeMask = new GeometryMask
            {
                Points = true,
                Lines = true,
                Arcs = true,
                PSplines = true,
                xlines = true,
                Surfs = false,
                Solids = false
            };

            // Get all the wireframe entities in the current Mastercam file
            var allWireframeEntities = SearchManager.GetGeometry(wireframeMask);

            // Check if any wireframe entities exist in the allWireframeEntities array
            if (allWireframeEntities.Any())
            {
                // Iterate through each wireframe entity 
                foreach (var wireframeEntity in allWireframeEntities)
                {
                    // Switch on each wireframe entity to determine it's type
                    switch (wireframeEntity)
                    {
                        case PointGeometry point:
                            // Do something with the point geometry
                            break;

                        case ArcGeometry arc:
                            // Do something with the arc geometry
                            break;

                        case LineGeometry line:
                            // Do something with the line geometry
                            break;

                        case NURBSCurveGeometry nurbsCurve:
                            // Do something with the NURBS geometry
                            break;

                        case SplineGeometry spline:
                            // Do something with the spline geometry
                            break;
      
                        case null:
                            break;

                        default:
                            break;
                    }
                }

                return MCamReturn.NoErrors;
            }
            else
            {
                DialogManager.Error("No wireframe found in .mcam file.", "No Wireframe Found");
                return MCamReturn.ErrorOccurred;
            }           
        }

        #endregion
    }
}

 

Link to comment
Share on other sites
  • 2 weeks later...

Jeff,

I must be as dense as a block of lead.  I cannot get my system to allow me to enter the code without

producing errors.  I am sure this is due to my inexperience with both the MASTERCAM API and the

VISUAL BASIC 2015 that I am using.

 

I am attempting to take VBSCRIPTS that have been working well and translate them into nethooks.

I initially thought it would not be as difficult to translate scripts that were proven to work.

 

If there Is anything additional you can add It would be very helpful.

 

best regards,

Steven

 

 

 

 

Link to comment
Share on other sites
1 hour ago, srbeyke said:

Jeff,

I must be as dense as a block of lead.  I cannot get my system to allow me to enter the code without

producing errors.  I am sure this is due to my inexperience with both the MASTERCAM API and the

VISUAL BASIC 2015 that I am using.

 

I am attempting to take VBSCRIPTS that have been working well and translate them into nethooks.

I initially thought it would not be as difficult to translate scripts that were proven to work.

 

If there Is anything additional you can add It would be very helpful.

 

best regards,

Steven

 

 

 

 

Hi Steven,

Can you upload your solution here so I can take a look?

Link to comment
Share on other sites

Jeff,

 

Here is a short and clean version of the code I am  working on:

 

 


            Dim WireFrameMask = New GeometryMask(True, True, True, True, True, False, False)
            Dim allWireframeEntities = SearchManager.GetGeometry(WireFrameMask)


            For Each (Dim wireframeEntity In allWireframeEntities())
                
                Select Case wireframeEntity


                    Case PointGeometry point
                            ' Do something with the point geometry
                            
                    Case ArcGeometry arc
                            ' Do something with the arc geometry
                            
                    Case LineGeometry line
                            ' Do something with the line geometry
                End Select

            Next

 

 

The first and second lines seem to be correct.  No errors shown.

The third line containing the "For Each" statement returns several errors including :

      "expression expected"

     "')' expected"

     "number of indices less than the number of dimension in indexed array."

 

My guess is that the WireFrameEntity is not properly dimensioned or something.

I tried to use your example as a guide, but I have obviously missed something .

 

Thank you for taking the time to assist., me

 

Steven

Link to comment
Share on other sites

Hi Steven,

I'm not a VB guy, but try the below code.

For Each wireframeEntity As Geometry In allWireframeEntities

            Select Case wireframeEntity.GetType()

                Case GetType(PointGeometry)
                    Dim point = CType(wireframeEntity, PointGeometry)
                    point.Color = 110
                    point.Commit()

                Case GetType(ArcGeometry)
                    Dim arc = CType(wireframeEntity, ArcGeometry)
                    arc.Color = 115
                    arc.Commit()

                Case GetType(LineGeometry)
                    Dim line = CType(wireframeEntity, LineGeometry)
                    line.Color = 125
                    line.Commit()

                Case Else

            End Select

        Next

 

 

Link to comment
Share on other sites

Jeff,

I deleted my code to make way for your code.

I cut and pasted your example.

I still had an error in the "For Each" line.  So I added an

"imports mastercam.database"  and it seems to have cleared the problem.

I think the "imports" statement in VB is similar to the "Using" statement in C#.

 

I will test this as it is, and then start the process of tweaking it to  do what I hope to do.

You have been a great mentor and I appreciate the help.  

regards,

Steven

Link to comment
Share on other sites

Hello all,

Thanks to everyone who has provided any assistance to me.  I have been making progress (believe it, or not) and I am starting to grasp some of the more simple concepts of Visual Basics and  the Masteram API.

I am trying to create surfaces from a single solid that has been selected.  The surfaces are created, but a prompt appears on the screen "Set options, press <ENTER>, Apply, or OK".  I wish for my project to enter the appropriate response and keep moving.  

Can someone point me in the direction I need to go?

Again, all help and advice is much appreciated.

 

Steven

 

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