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:

Is it possible to create an offset contour with a C# Nethook or Vbsript command?


Recommended Posts

I've been trying to find a function to offset a 2D closed chain of arcs and lines so far the best I could do is execute the create boundary CHook and Enter the parameters and close the prompts using sendkeys from an external vba Module, however I would like to ideally find a better solution as its really slow. (maybe 15 seconds) I would be interested in any suggestions.

Link to comment
Share on other sites

I was looking at that one actually ,  but I wasn't clear how to use it properly, in the last nethook I made I used

ChainManager.SortChains(chains, ChainManager.SortType.Area, ChainManager.SortOrder.Descending);

To find the outside contour on the part and assign it to a new level for chaining , now I wanted to offset the contour but I got errors when I tried to implement it.

Link to comment
Share on other sites
{
            for (int i5 = 1; i5 < 6; i5++)

            {
                int currentactivelevel = 500 * i5;
                var chains = ChainManager.ChainAll(true, false, null, Mastercam.Database.Types.ChainDirectionType.CounterClockwise, currentactivelevel);
                if (chains == null || chains.Length == 0)
                {
                    return MCamReturn.ErrorOccurred;
                }

                ChainManager.SortChains(chains, ChainManager.SortType.Area, ChainManager.SortOrder.Descending);
               
                int numberofchains = chains.Length;
                
                int i = 0;
                {
                    
                    Geometry[] chaingeometry = ChainManager.GetGeometryInChain(chains[i]);

                    for (int i1 = 0; i1 < chaingeometry.Length; i1++)
                    {
                        
                        Geometry wireframeentiy = chaingeometry[i1];
                        wireframeentiy.Color = 12; // Set the Color of this entity
                        wireframeentiy.Level = 100000 * i5;// Set the Level of this entity
                        wireframeentiy.Commit(); // Commit the change to the database
                      

                    }


                }
            }

         
           Chain.OffsetChain2D(OffsetSideType.Left, .245, CornerRoll: OffsetRollCornerType.None, Depth: .5, IncrementalDepth: false, Tolerance: .005, InfiniteLookAhead: true);//I would like to Offset the chain at this point

I am currently working with Mastercam 2018 

Link to comment
Share on other sites

Yeah, that won't work. 

The OffsetChain2D method returns the offset chain and you're not using the returned value.  

Once you get the returned (offset) chain, you'll still need to use the ChainManager to get the geometry in the chain, then commit each entity in the chain.

Below is a working example, hope it helps! 

namespace OffsetExample
{
    using Mastercam.App;
    using Mastercam.App.Types;

    using Mastercam.Database;
    using Mastercam.Database.Types;

    public class Main : NetHook3App
    {
        public override MCamReturn Run(int param)
        {
            var selectedChain = ChainManager.GetOneChain("Select a Chain");

            var offsetChain = selectedChain.OffsetChain2D(OffsetSideType.Left,
                                                          .245,
                                                          OffsetRollCornerType.None,
                                                          .5,
                                                          false,
                                                          .005,
                                                          false);

            var offsetGeometry = ChainManager.GetGeometryInChain(offsetChain);

            foreach (var entity in offsetGeometry)
            {
                entity.Commit();
            }

            return MCamReturn.NoErrors;
        }

    }
}

 

Link to comment
Share on other sites

Thank you so much for helping me! That is exactly what I needed to know. I've been working on this project to automate programming for months at my work and I finally finished it, but this issue was slowing my program quite a bit. Now i'll be able to program a part in seconds!! :D

Link to comment
Share on other sites

My final code looked like this:

 public override MCamReturn Run(int param)
        {

            int currentactivelevel = 500;
                var chains = ChainManager.ChainAll(true, false, null, Mastercam.Database.Types.ChainDirectionType.Clockwise, currentactivelevel);
                if (chains == null || chains.Length == 0)
                {
                    return MCamReturn.ErrorOccurred;
                }
            foreach (var chain in chains)
            {
                var selectedChain = chain;
                var offsetChain = selectedChain.OffsetChain2D(OffsetSideType.Left,
                                                                          .245,
                                                                          OffsetRollCornerType.None,
                                                                          .5,
                                                                          false,
                                                                          .005,
                                                                          false);

                var offsetGeometry = ChainManager.GetGeometryInChain(offsetChain);
                foreach (var entity in offsetGeometry)
                {
                    entity.Commit();
                }
            }
            

            

            
        
            





                //const string ScriptName = @"C:\Users\Public\Input\Input.vbs";

                // Mastercam.Support.ExternalAppsManager.RunVBScript(ScriptName);



                return MCamReturn.NoErrors;
            }



            #endregion
        }

    }

That will grab the entities off the level and offset the contour, thanks again.

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