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:

Holder .stp import


Recommended Posts

Hi,

 

Im trying to import .stp file as holder custom geometry.  Im using ToolNetApi.dll and this is some of my code:

 

                miTlib.OpenLibrary(Operadores.rutaPortas + @"\Master3DTool.tooldb",true);

                List<TlAssembly> ListaMontajes = new List<TlAssembly>();
                miTlib.GetAllTlAssemblies(ListaMontajes);

                TlHolder nuevoholder = new TlHolder();

                ListaMontajes[0].Name = "XXXXXX";
                nuevoholder = ListaMontajes[0].MainHolder;

                nuevoholder.Name = "KKKKKKK69990000";         

                nuevoholder.GeometryFile = @"D:\Escritorio\83-PORTA.stp";

                ListaMontajes[0].MainHolder = nuevoholder;

                miTlib.DeleteAll();

                miTlib.Add(ListaMontajes[0]);
                miTlib.UpdateLibrary();
                OperationsManager.ToolLibraryName = miTlib.GetLibraryPath();

 

However, the holder loads its custom name and stp geometry, but in Mastercam it still represents the original default holder.

image.png.fe6ef7a9a486fe691d3415f4a7fa94d9.png

image.png.a5f2210a43d852e011481aef0cddc593.png

 

 

Can someone help me?

 

Thank you very much.

 

83-PORTA.stp

Link to comment
Share on other sites
4 hours ago, RubenIAM said:

Hi,

 

Im trying to import .stp file as holder custom geometry.  Im using ToolNetApi.dll and this is some of my code:

 

                miTlib.OpenLibrary(Operadores.rutaPortas + @"\Master3DTool.tooldb",true);

                List<TlAssembly> ListaMontajes = new List<TlAssembly>();
                miTlib.GetAllTlAssemblies(ListaMontajes);

                TlHolder nuevoholder = new TlHolder();

                ListaMontajes[0].Name = "XXXXXX";
                nuevoholder = ListaMontajes[0].MainHolder;

                nuevoholder.Name = "KKKKKKK69990000";         

                nuevoholder.GeometryFile = @"D:\Escritorio\83-PORTA.stp";

                ListaMontajes[0].MainHolder = nuevoholder;

                miTlib.DeleteAll();

                miTlib.Add(ListaMontajes[0]);
                miTlib.UpdateLibrary();
                OperationsManager.ToolLibraryName = miTlib.GetLibraryPath();

 

However, the holder loads its custom name and stp geometry, but in Mastercam it still represents the original default holder.

image.png.fe6ef7a9a486fe691d3415f4a7fa94d9.png

image.png.a5f2210a43d852e011481aef0cddc593.png

 

 

Can someone help me?

 

Thank you very much.

 

83-PORTA.stp

I don't see that setting that value implicitly tells mastercam to load the 3d holder, I'm not sure this is supported.

namespace CreateMillToolAddIn
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Windows.Forms;

    using Cnc.Tool.Interop; // ToolNetApi.dll

    using Mastercam.App;
    using Mastercam.App.Types;

    /// <summary> CreateMillTool Class (implements the NetHook3App interface) </summary>
    public class CreateMillToolAddIn : NetHook3App
    {
        #region Public Methods

        /// <summary> The REQUIRED main entry point 'Run' method for the NETHook. </summary>
        ///
        /// <remarks> This is the only really required method that you must override in order
        ///           to implement the NETHook3App interface. </remarks>
        ///
        /// <param name="param"> Parameter supplied via a (optional) FT File PARAM command. </param>
        ///
        /// <returns> A MCamReturn return type representing the outcome of the NetHook application. </returns>
        public override MCamReturn Run(int param)
        {
            try
            {

                var folder = Mastercam.IO.SettingsManager.SharedDirectory + @"mill\Tools\";

                var library = "Master3DTool.tooldb";

                var file = "83-PORTA.stp";
                // If the library does not exist, it will be created.
                var tls = new ToolLibrarySystem();

                tls.OpenLibrary(folder + library, true);

                TlAssembly toolAssembly = null;

                MessageBox.Show("1");

                toolAssembly = this.DemonstrateCreatingFlatEndMillToolAssembly();

                MessageBox.Show("2");
                var result = false;

                if (toolAssembly != null)
                {
                        if (tls.IsOpen())
                        {
                            result = tls.Add(toolAssembly);
                        }

                        MessageBox.Show(
                            $"Result => {result}",
                            "Add Tool Assembly to library",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
                }

                 List<TlAssembly> ListaMontajes = new List<TlAssembly>();

                tls.GetAllTlAssemblies(ListaMontajes);
                
                TlHolder nuevoholder = new TlHolder();

                ListaMontajes[0].Name = "XXXXXX";

                nuevoholder = ListaMontajes[0].MainHolder;

                nuevoholder.Name = "KKKKKKK69990000";

                nuevoholder.GeometryFile = folder + file;

               ListaMontajes[0].MainHolder = nuevoholder;

                // tls.DeleteAll();???
                // ** IMPORTANT ***
                // If the assembly was a default assembly before making this change, we need to set the "IsDefault" property
                // on the assembly to make Mastercam understand that this is now a user defined assembly.  Default assemblies
                // in Mastercam are treated as regular tools with a default holder.  Non-default assemblies are presented
                // differently in the tool lists throughout Mastercam through the filtering options and name outputs.
                // This step will not be required in the long-term, but for the short-term, setting this property is necessary
                var set = ListaMontajes[0].SetAsDefaultAssembly(false);

                tls.Update(ListaMontajes[0]);

                tls.UpdateLibrary();
                
                Mastercam.Operations.OperationsManager.ToolLibraryName = tls.GetLibraryPath();

            }
            catch(System.Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Error!" + e.Message);
            }

            return MCamReturn.NoErrors;
        }

        #endregion Public Methods
        private TlAssembly DemonstrateCreatingFlatEndMillToolAssembly()
        {
            var tls = new ToolLibrarySystem();
            // Create a "default" tool assembly of the specified type.
            var assembly = Cnc.Tool.Interop.TlServices.CreateITlAssemblyFactory().Create(Cnc.Tool.Interop.MCToolType.FlatEndmill, false);

            assembly.Name = "Programmatically created Assembly";
            // And set some of the parameters of the tool in this assembly...
            var millTool = assembly.GetMillTool(); // Get the tool from the assembly
            // Cast it to the type to access specific properties!
            var tool = millTool as TlToolEndmill;
            Debug.Assert(tool != null, "Cast to TlToolEndmill type was invalid!");

            tool.ToolNumber = 1;
            tool.Name = "My End Mill Tool";

            // If you are changing the "length" of the tool ->
            // It is best to update both the OverallLength and TruePhysicalLength properties.
            // Setting them apart will tell the containing assembly that the projection of that tool
            // is whatever is in the overall length property.
            // If the overall length is set to be greater than the current true physical length,
            // the true physical length is updated to match the overall length value.

            // Set the Overall dimensions
            tool.OverallDiameter = 0.9125; // Cutting diameter
            tool.TruePhysicalLength = tool.OverallLength = 4.125; // Overall length
            tool.CuttingDepth = 0.735; // Flute Length / Cutting Length

            // Set the Cutting geometry dimensions
            tool.TipDiameter = 0.505;

            // Set the Non-cutting geometry dimensions
            tool.ShoulderLength = 1.15; // Shoulder length
            tool.ShoulderDiameter = 0.5; // Shoulder diameter
            tool.ArborDiameter = 0.75; // Shank diameter

            // Set the Shank Type
            tool.ShankType = TlShankType.Straight; // Straight / Tapered / Reduced

            // tool.ShankType = TlShankType.Tapered; // Straight / Tapered / Reduced
            // tool.TaperAngle = 45.0;
            //// or...
            // tool.TaperLength = 0.135;

            // tool.ShankType = TlShankType.Reduced; // Straight / Tapered / Reduced
            // tool.NeckDiameter = 0.5; // Neck Diameter
            // tool.TaperLength = 0.575; // Neck length

            // Set Feed/Speed parameters
            var toolOpParams = tool.OpParams;
            toolOpParams.FeedRate = 7.55;
            toolOpParams.PlungeRate = 4.4;
            toolOpParams.RetractRate = 13.5;
            toolOpParams.SpindleSpeed = 2555;

            tool.OpParams = toolOpParams;

            // Set the changed Tool into the Assembly.
            assembly.MainTool = tool;

            // Add a segment to the default holder that was created
            // and set the altered holder into the assembly.
            var holder = assembly.MainHolder;
            holder.Name = "My Holder";
            holder.AddSegment(3, 3, 1);

            // Add more segments?
            assembly.MainHolder = holder; // Set the Holder into the Assembly

            // ** IMPORTANT ***
            // If the assembly was a default assembly before making this change, we need to set the "IsDefault" property
            // on the assembly to make Mastercam understand that this is now a user defined assembly.  Default assemblies
            // in Mastercam are treated as regular tools with a default holder.  Non-default assemblies are presented
            // differently in the tool lists throughout Mastercam through the filtering options and name outputs.
            // This step will not be required in the long-term, but for the short-term, setting this property is necessary
            var set = assembly.SetAsDefaultAssembly(false);
            Debug.Assert(set, "Assembly is still set as a default assembly");

            return assembly;
        }
      
    }
}

I got the same result running the above code, the other information was updated

Link to comment
Share on other sites
12 hours ago, RubenIAM said:

Hi,

 

Im trying to import .stp file as holder custom geometry.  Im using ToolNetApi.dll and this is some of my code:

 

                miTlib.OpenLibrary(Operadores.rutaPortas + @"\Master3DTool.tooldb",true);

                List<TlAssembly> ListaMontajes = new List<TlAssembly>();
                miTlib.GetAllTlAssemblies(ListaMontajes);

                TlHolder nuevoholder = new TlHolder();

                ListaMontajes[0].Name = "XXXXXX";
                nuevoholder = ListaMontajes[0].MainHolder;

                nuevoholder.Name = "KKKKKKK69990000";         

                nuevoholder.GeometryFile = @"D:\Escritorio\83-PORTA.stp";

                ListaMontajes[0].MainHolder = nuevoholder;

                miTlib.DeleteAll();

                miTlib.Add(ListaMontajes[0]);
                miTlib.UpdateLibrary();
                OperationsManager.ToolLibraryName = miTlib.GetLibraryPath();

 

However, the holder loads its custom name and stp geometry, but in Mastercam it still represents the original default holder.

image.png.fe6ef7a9a486fe691d3415f4a7fa94d9.png

image.png.a5f2210a43d852e011481aef0cddc593.png

 

 

Can someone help me?

 

Thank you very much.

 

83-PORTA.stp

Mick figured it out, we need to call the method to store the profile->  TlGeometryImportExport.ImportProfileFromFile( (HOLDER) , (Path To File) );

Here is a working example that will create a new library and tool if none are found or if one is found, swap out the holder.


namespace CreateMillToolAddIn
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Windows.Forms;

    using Cnc.Tool.Interop; // ToolNetApi.dll

    using Mastercam.App;
    using Mastercam.App.Types;

    /// <summary> CreateMillTool Class (implements the NetHook3App interface) </summary>
    public class CreateMillToolAddIn : NetHook3App
    {
        #region Public Methods

        /// <summary> The REQUIRED main entry point 'Run' method for the NETHook. </summary>
        ///
        /// <remarks> This is the only really required method that you must override in order
        ///           to implement the NETHook3App interface. </remarks>
        ///
        /// <param name="param"> Parameter supplied via a (optional) FT File PARAM command. </param>
        ///
        /// <returns> A MCamReturn return type representing the outcome of the NetHook application. </returns>
        public override MCamReturn Run(int param)
        {
            try
            {

                var folder = Mastercam.IO.SettingsManager.SharedDirectory + @"mill\Tools\";

                var library = "Master3DTool.tooldb";

                bool CreateNewTool = false;

                if (!System.IO.File.Exists(folder + library))
                {
                    CreateNewTool = true;
                }

                var file = "83-PORTA.stp";
                
                // If the library does not exist, it will be created.
                var tls = new ToolLibrarySystem();

                var success = tls.OpenLibrary(folder + library, true);

                if (!success) { Mastercam.IO.DialogManager.Exception(new Mastercam.App.Exceptions.MastercamException($"Failed to open {library}")); }



                List<TlAssembly> ListaMontajes = new List<TlAssembly>();

                tls.GetAllTlAssemblies(ListaMontajes);
                //only create a new tool if the library does not exist or is empty
                if (CreateNewTool == true || ListaMontajes.Count <= 0)
                {
                    TlAssembly toolAssembly = null;

                    toolAssembly = this.DemonstrateCreatingFlatEndMillToolAssembly();

                    var result = false;

                    if (toolAssembly != null)
                    {
                        if (tls.IsOpen())
                        {
                            result = tls.Add(toolAssembly);
                        }

                        MessageBox.Show(
                            $"Result => {result}",
                            "Add Tool Assembly to library",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
                            ListaMontajes.Add(toolAssembly);
                    }
                }
                
                TlHolder nuevoholder = new TlHolder();

                ListaMontajes[0].Name = "XXXXXX";

                nuevoholder = ListaMontajes[0].MainHolder;

                nuevoholder.Name = "KKKKKKK69990000";

                nuevoholder.GeometryFile = folder + file;

                success = TlGeometryImportExport.ImportProfileFromFile(nuevoholder, folder + file);

                if (!success) { Mastercam.IO.DialogManager.Exception(new Mastercam.App.Exceptions.MastercamException($"Failed to load holder from path -> {folder + file}")); }

                ListaMontajes[0].MainHolder = nuevoholder;

                // tls.DeleteAll();???
                // ** IMPORTANT ***
                // If the assembly was a default assembly before making this change, we need to set the "IsDefault" property
                // on the assembly to make Mastercam understand that this is now a user defined assembly.  Default assemblies
                // in Mastercam are treated as regular tools with a default holder.  Non-default assemblies are presented
                // differently in the tool lists throughout Mastercam through the filtering options and name outputs.
                // This step will not be required in the long-term, but for the short-term, setting this property is necessary
                var set = ListaMontajes[0].SetAsDefaultAssembly(false);

                tls.Update(ListaMontajes[0]);

                tls.UpdateLibrary();
                
                Mastercam.Operations.OperationsManager.ToolLibraryName = tls.GetLibraryPath();

                Mastercam.Operations.OperationsManager.RefreshOperationsManager();
            }
            catch(System.Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Error!" + e.Message);
            }

            return MCamReturn.NoErrors;
        }

        #endregion Public Methods
        private TlAssembly DemonstrateCreatingFlatEndMillToolAssembly()
        {
            var tls = new ToolLibrarySystem();
            // Create a "default" tool assembly of the specified type.
            var assembly = Cnc.Tool.Interop.TlServices.CreateITlAssemblyFactory().Create(Cnc.Tool.Interop.MCToolType.FlatEndmill, false);

            assembly.Name = "Programmatically created Assembly";
            // And set some of the parameters of the tool in this assembly...
            var millTool = assembly.GetMillTool(); // Get the tool from the assembly
            // Cast it to the type to access specific properties!
            var tool = millTool as TlToolEndmill;
            Debug.Assert(tool != null, "Cast to TlToolEndmill type was invalid!");

            tool.ToolNumber = 1;
            tool.Name = "My End Mill Tool";

            // If you are changing the "length" of the tool ->
            // It is best to update both the OverallLength and TruePhysicalLength properties.
            // Setting them apart will tell the containing assembly that the projection of that tool
            // is whatever is in the overall length property.
            // If the overall length is set to be greater than the current true physical length,
            // the true physical length is updated to match the overall length value.

            // Set the Overall dimensions
            tool.OverallDiameter = 0.9125; // Cutting diameter
            tool.TruePhysicalLength = tool.OverallLength = 4.125; // Overall length
            tool.CuttingDepth = 0.735; // Flute Length / Cutting Length

            // Set the Cutting geometry dimensions
            tool.TipDiameter = 0.505;

            // Set the Non-cutting geometry dimensions
            tool.ShoulderLength = 1.15; // Shoulder length
            tool.ShoulderDiameter = 0.5; // Shoulder diameter
            tool.ArborDiameter = 0.75; // Shank diameter

            // Set the Shank Type
            tool.ShankType = TlShankType.Straight; // Straight / Tapered / Reduced

            // tool.ShankType = TlShankType.Tapered; // Straight / Tapered / Reduced
            // tool.TaperAngle = 45.0;
            //// or...
            // tool.TaperLength = 0.135;

            // tool.ShankType = TlShankType.Reduced; // Straight / Tapered / Reduced
            // tool.NeckDiameter = 0.5; // Neck Diameter
            // tool.TaperLength = 0.575; // Neck length

            // Set Feed/Speed parameters
            var toolOpParams = tool.OpParams;
            toolOpParams.FeedRate = 7.55;
            toolOpParams.PlungeRate = 4.4;
            toolOpParams.RetractRate = 13.5;
            toolOpParams.SpindleSpeed = 2555;

            tool.OpParams = toolOpParams;

            // Set the changed Tool into the Assembly.
            assembly.MainTool = tool;

            // Add a segment to the default holder that was created
            // and set the altered holder into the assembly.
            var holder = assembly.MainHolder;
            holder.Name = "My Holder";
            holder.AddSegment(3, 3, 1);

            // Add more segments?
            assembly.MainHolder = holder; // Set the Holder into the Assembly

            // ** IMPORTANT ***
            // If the assembly was a default assembly before making this change, we need to set the "IsDefault" property
            // on the assembly to make Mastercam understand that this is now a user defined assembly.  Default assemblies
            // in Mastercam are treated as regular tools with a default holder.  Non-default assemblies are presented
            // differently in the tool lists throughout Mastercam through the filtering options and name outputs.
            // This step will not be required in the long-term, but for the short-term, setting this property is necessary
            var set = assembly.SetAsDefaultAssembly(false);
            Debug.Assert(set, "Assembly is still set as a default assembly");

            return assembly;
        }
      
    }
}

 

Link to comment
Share on other sites
16 hours ago, Thee Byte™ said:

Mick figured it out, we need to call the method to store the profile->  TlGeometryImportExport.ImportProfileFromFile( (HOLDER) , (Path To File) );

Here is a working example that will create a new library and tool if none are found or if one is found, swap out the holder.



namespace CreateMillToolAddIn
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Windows.Forms;

    using Cnc.Tool.Interop; // ToolNetApi.dll

    using Mastercam.App;
    using Mastercam.App.Types;

    /// <summary> CreateMillTool Class (implements the NetHook3App interface) </summary>
    public class CreateMillToolAddIn : NetHook3App
    {
        #region Public Methods

        /// <summary> The REQUIRED main entry point 'Run' method for the NETHook. </summary>
        ///
        /// <remarks> This is the only really required method that you must override in order
        ///           to implement the NETHook3App interface. </remarks>
        ///
        /// <param name="param"> Parameter supplied via a (optional) FT File PARAM command. </param>
        ///
        /// <returns> A MCamReturn return type representing the outcome of the NetHook application. </returns>
        public override MCamReturn Run(int param)
        {
            try
            {

                var folder = Mastercam.IO.SettingsManager.SharedDirectory + @"mill\Tools\";

                var library = "Master3DTool.tooldb";

                bool CreateNewTool = false;

                if (!System.IO.File.Exists(folder + library))
                {
                    CreateNewTool = true;
                }

                var file = "83-PORTA.stp";
                
                // If the library does not exist, it will be created.
                var tls = new ToolLibrarySystem();

                var success = tls.OpenLibrary(folder + library, true);

                if (!success) { Mastercam.IO.DialogManager.Exception(new Mastercam.App.Exceptions.MastercamException($"Failed to open {library}")); }



                List<TlAssembly> ListaMontajes = new List<TlAssembly>();

                tls.GetAllTlAssemblies(ListaMontajes);
                //only create a new tool if the library does not exist or is empty
                if (CreateNewTool == true || ListaMontajes.Count <= 0)
                {
                    TlAssembly toolAssembly = null;

                    toolAssembly = this.DemonstrateCreatingFlatEndMillToolAssembly();

                    var result = false;

                    if (toolAssembly != null)
                    {
                        if (tls.IsOpen())
                        {
                            result = tls.Add(toolAssembly);
                        }

                        MessageBox.Show(
                            $"Result => {result}",
                            "Add Tool Assembly to library",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
                            ListaMontajes.Add(toolAssembly);
                    }
                }
                
                TlHolder nuevoholder = new TlHolder();

                ListaMontajes[0].Name = "XXXXXX";

                nuevoholder = ListaMontajes[0].MainHolder;

                nuevoholder.Name = "KKKKKKK69990000";

                nuevoholder.GeometryFile = folder + file;

                success = TlGeometryImportExport.ImportProfileFromFile(nuevoholder, folder + file);

                if (!success) { Mastercam.IO.DialogManager.Exception(new Mastercam.App.Exceptions.MastercamException($"Failed to load holder from path -> {folder + file}")); }

                ListaMontajes[0].MainHolder = nuevoholder;

                // tls.DeleteAll();???
                // ** IMPORTANT ***
                // If the assembly was a default assembly before making this change, we need to set the "IsDefault" property
                // on the assembly to make Mastercam understand that this is now a user defined assembly.  Default assemblies
                // in Mastercam are treated as regular tools with a default holder.  Non-default assemblies are presented
                // differently in the tool lists throughout Mastercam through the filtering options and name outputs.
                // This step will not be required in the long-term, but for the short-term, setting this property is necessary
                var set = ListaMontajes[0].SetAsDefaultAssembly(false);

                tls.Update(ListaMontajes[0]);

                tls.UpdateLibrary();
                
                Mastercam.Operations.OperationsManager.ToolLibraryName = tls.GetLibraryPath();

                Mastercam.Operations.OperationsManager.RefreshOperationsManager();
            }
            catch(System.Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Error!" + e.Message);
            }

            return MCamReturn.NoErrors;
        }

        #endregion Public Methods
        private TlAssembly DemonstrateCreatingFlatEndMillToolAssembly()
        {
            var tls = new ToolLibrarySystem();
            // Create a "default" tool assembly of the specified type.
            var assembly = Cnc.Tool.Interop.TlServices.CreateITlAssemblyFactory().Create(Cnc.Tool.Interop.MCToolType.FlatEndmill, false);

            assembly.Name = "Programmatically created Assembly";
            // And set some of the parameters of the tool in this assembly...
            var millTool = assembly.GetMillTool(); // Get the tool from the assembly
            // Cast it to the type to access specific properties!
            var tool = millTool as TlToolEndmill;
            Debug.Assert(tool != null, "Cast to TlToolEndmill type was invalid!");

            tool.ToolNumber = 1;
            tool.Name = "My End Mill Tool";

            // If you are changing the "length" of the tool ->
            // It is best to update both the OverallLength and TruePhysicalLength properties.
            // Setting them apart will tell the containing assembly that the projection of that tool
            // is whatever is in the overall length property.
            // If the overall length is set to be greater than the current true physical length,
            // the true physical length is updated to match the overall length value.

            // Set the Overall dimensions
            tool.OverallDiameter = 0.9125; // Cutting diameter
            tool.TruePhysicalLength = tool.OverallLength = 4.125; // Overall length
            tool.CuttingDepth = 0.735; // Flute Length / Cutting Length

            // Set the Cutting geometry dimensions
            tool.TipDiameter = 0.505;

            // Set the Non-cutting geometry dimensions
            tool.ShoulderLength = 1.15; // Shoulder length
            tool.ShoulderDiameter = 0.5; // Shoulder diameter
            tool.ArborDiameter = 0.75; // Shank diameter

            // Set the Shank Type
            tool.ShankType = TlShankType.Straight; // Straight / Tapered / Reduced

            // tool.ShankType = TlShankType.Tapered; // Straight / Tapered / Reduced
            // tool.TaperAngle = 45.0;
            //// or...
            // tool.TaperLength = 0.135;

            // tool.ShankType = TlShankType.Reduced; // Straight / Tapered / Reduced
            // tool.NeckDiameter = 0.5; // Neck Diameter
            // tool.TaperLength = 0.575; // Neck length

            // Set Feed/Speed parameters
            var toolOpParams = tool.OpParams;
            toolOpParams.FeedRate = 7.55;
            toolOpParams.PlungeRate = 4.4;
            toolOpParams.RetractRate = 13.5;
            toolOpParams.SpindleSpeed = 2555;

            tool.OpParams = toolOpParams;

            // Set the changed Tool into the Assembly.
            assembly.MainTool = tool;

            // Add a segment to the default holder that was created
            // and set the altered holder into the assembly.
            var holder = assembly.MainHolder;
            holder.Name = "My Holder";
            holder.AddSegment(3, 3, 1);

            // Add more segments?
            assembly.MainHolder = holder; // Set the Holder into the Assembly

            // ** IMPORTANT ***
            // If the assembly was a default assembly before making this change, we need to set the "IsDefault" property
            // on the assembly to make Mastercam understand that this is now a user defined assembly.  Default assemblies
            // in Mastercam are treated as regular tools with a default holder.  Non-default assemblies are presented
            // differently in the tool lists throughout Mastercam through the filtering options and name outputs.
            // This step will not be required in the long-term, but for the short-term, setting this property is necessary
            var set = assembly.SetAsDefaultAssembly(false);
            Debug.Assert(set, "Assembly is still set as a default assembly");

            return assembly;
        }
      
    }
}

 

Ok, how do I use this code inside MC? Is it saved as a dll file to use as a chook?

Link to comment
Share on other sites

Here is a snippet of code that will create a new holder, assign a stp file to the geometry and add it to the the tool db

 

        /// <summary> Adds new holder to database. </summary>
        ///
        /// <returns> A TlHolder. </returns>
        private TlHolder AddNewHolderToDatabase()
        {
            // build path to tools
            var folder = Path.Combine(SettingsManager.SharedDirectory, "mill\\Tools");

            // tool db
            const string library = "micks.tooldb";

            // build path to db
            var toolDb = Path.Combine(folder, library);

            // part file for holder geometry
            const string file = "83-PORTA.stp";

            // build path to stp file
            var geometryFile = Path.Combine(folder, file);
            if (!File.Exists(geometryFile))
            {
                DialogManager.Exception(new MastercamException($"File not found {geometryFile}"));
                return null;
            }

            // If the library does not exist, it will be created.
            var tls = new ToolLibrarySystem();

            try
            {
                // verify it opened successfullly
                var success = tls.OpenLibrary(toolDb, true);
                if (!success)
                {
                    DialogManager.Exception(new MastercamException($"Failed to open {toolDb}"));
                    return null;
                }

                var holder = new TlHolder
                {
                    Name = "micks holder with geometry",
                    Description = "created via toolnetapi",

                    // assign the path
                    GeometryFile = geometryFile
                };

                // import the actual file
                success = TlGeometryImportExport.ImportProfileFromFile(holder, geometryFile);
                if (!success)
                {
                    DialogManager.Exception(new MastercamException($"Failed to Import Profile From File {geometryFile}"));
                    return null;
                }

                // add to tool library
                success = tls.Add(holder);
                if (success)
                {
                    return holder;
                }

                DialogManager.Exception(new MastercamException($"Failed to add holder {holder.Name}"));
                return null;
            }
            catch (Exception e)
            {
                DialogManager.Exception(new MastercamException(e.Message, e.InnerException));
            }
            finally
            {
                // clean up
                if (tls.IsOpen())
                {
                    tls.CloseLibrary();
                }
            }

            return null;
        }

 

Edited by Mick George
code edit - added clean up
Link to comment
Share on other sites
6 minutes ago, So not a Guru said:

@Thee Byte™ I don't understand how I get this to operate. I opened it & built it in VS. Where do I go from here?

 

So, when you run the add-in a new toollibrary will be created, it's looking for an stp file in the same folder as the tool library.

 

c:/users/public/documents/shared mastercam 2021/mill/tools/

needs to contain the .stp file named in the application.

 

So you would put a file called "83-PORTA.stp" in that folder and it will be stored in the newly created library


 
Link to comment
Share on other sites
1 minute ago, So not a Guru said:

Run it from where? I don't see it in my chooks folder. Was I supposed to save some file into the folder?

 

You have to copy the DLL file from the x64/release folder to the chook folder along with the accompanying .ft file if you wish to add an icon to the qat.

Link to comment
Share on other sites
9 minutes ago, Thee Byte™ said:

x64/release folder

I can't find this folder. I have:

C:\Users\Programmer PC\Documents\MASTERCAM\AddToolStoreProfile-main\AddToolStoreProfile-main\CreateMillTool\obj\x64\Debug\TempPE

And there is a "Properties.Resources.Designer.cs.dll" file in that directory, but no ft files

I'm using Widows 7

Link to comment
Share on other sites
1 hour ago, Thee Byte™ said:

I got an error when I imported your geometry, i remerged the surfaces and ran optimize, reads okay now.

I also updated the example with the openfiledialog to just add the holder into a library.

Let me know where you want to go from there.

https://github.com/xx4g/AddToolStoreProfile/tree/main

STP-22907-6-CAT40xSLN1_8_-6_.STP

ToolLibrary.tooldb

I'm outta thanks today.👍

I'll give it a go on Monday.

Link to comment
Share on other sites
On 2/12/2021 at 1:58 PM, So not a Guru said:

I'm outta thanks today.👍

I'll give it a go on Monday.

Zeke,I added some options to the logic in the solution to

-> delete existing library tools

-> programmatically create a new library tool and holder assembly

->assign a custom profile to the assembly from a .stp file using the wubdiws open file dialog

-> import library tool(s) into Mastercam

->assign the tools to existing operations in the file

 

 

I create a struct with a set of switches to control the behavior

      /// <summary>
        /// The parameter struct for our add-in
        /// </summary>
        public struct AssemblyBuilderParams
        {
            public string geometryFile;//the file to import
            public string library;//the library to create/store tool in
            public string name;//the assembly name
            public string description;//the assembly 
            public bool import;//import newly created tool into Mastercam
            public bool assignToAllOperations;//Assign the last tool in the library to all operations
            public bool deleteExistingLibraryTools;//delete existing tools in the library
        }

Then in the run method a bit farther down

   #region Public Methods

        /// <summary> The REQUIRED main entry point 'Run' method for the NETHook. </summary>
        ///
        /// <remarks> This is the only really required method that you must override in order
        ///           to implement the NETHook3App interface. </remarks>
        ///
        /// <param name="param"> Parameter supplied via a (optional) FT File PARAM command. </param>
        ///
        /// <returns> A MCamReturn return type representing the outcome of the NetHook application. </returns>
        public override MCamReturn Run(int param)
        {
            //intialize thje string variables
            string library = "ToolLibrary.tooldb", name = "Pocket Nc holder with geometry", description = "created via toolnetapi";
            //instantiate the open file dialog class
            OpenFileName ofn = new OpenFileName();
            //allocate memory
            ofn.structSize = Marshal.SizeOf(ofn);
            //Set the file extension filter
            ofn.filter = "Stp files\0*.stp";
            //set more params
            ofn.file = new String(new char[256]);
            //set more params
            ofn.maxFile = ofn.file.Length;
            //set more params
            ofn.fileTitle = new String(new char[64]);
            //set more params
            ofn.maxFileTitle = ofn.fileTitle.Length;
            //starting directory
            ofn.initialDir = "C:\\";
            //user defined popup window title
            ofn.title = "OpeN FilE DialoG";
            //file extension
            ofn.defExt = "stp";
            //we could do something here with the found filename
            //the resulting path selected by the user is stored in the ofn.file variable
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            if (LibWrap.GetOpenFileName(ofn))
            {
                //define our user defined struct
                AssemblyBuilderParams bParams;
                //set the parameters
                bParams.library = library;
                bParams.name = name;
                bParams.description = description;
                bParams.geometryFile = ofn.file;
                bParams.assignToAllOperations = true;
                bParams.deleteExistingLibraryTools = true;
                bParams.import = true;
                //pass the parameters to our function
                var Assembly = AddNewAssemblyToDatabase(bParams);
             
            }
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///
            //---------------------------------------------///

            return MCamReturn.NoErrors;
        }
    };
 #endregion

This portion of code creates the libwrap class, I re-use this portion a lot, since this interface is nice than the one you get from .NET.

Here we are importing directly from The Windows Api

  #region Private Methods
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public class OpenFileName
        {
            public int structSize = 0;
            public IntPtr dlgOwner = IntPtr.Zero;
            public IntPtr instance = IntPtr.Zero;

            public String filter = null;
            public String customFilter = null;
            public int maxCustFilter = 0;
            public int filterIndex = 0;

            public String file = null;
            public int maxFile = 0;

            public String fileTitle = null;
            public int maxFileTitle = 0;

            public String initialDir = null;

            public String title = null;

            public int flags = 0;
            public short fileOffset = 0;
            public short fileExtension = 0;

            public String defExt = null;

            public IntPtr custData = IntPtr.Zero;
            public IntPtr hook = IntPtr.Zero;

            public String templateName = null;

            public IntPtr reservedPtr = IntPtr.Zero;
            public int reservedInt = 0;
            public int flagsEx = 0;
        }

        public class LibWrap
        {
            //BOOL GetOpenFileName(LPOPENFILENAME lpofn);

            [DllImport("Comdlg32.dll", CharSet = CharSet.Auto)]
            public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
        }

 

1 minute ago, Thee Byte™ said:

bParams.assignToAllOperations = true;

bParams.deleteExistingLibraryTools = true;

bParams.import = true;

You may want to set these switches to false at first,

Link to comment
Share on other sites

Demonstrates create a new tool assembly and adding an existing holder to it,

 private TlAssembly CreateFlatEndMillToolAssembly(TlHolder holder)
        {
            if (holder != null)
            {
                var tls = new ToolLibrarySystem();
                // Create a "default" tool assembly of the specified type.
                var assembly = Cnc.Tool.Interop.TlServices.CreateITlAssemblyFactory().Create(Cnc.Tool.Interop.MCToolType.FlatEndmill, false);

                assembly.Name = "Pocket Nc Assembly";
                // And set some of the parameters of the tool in this assembly...
                var millTool = assembly.GetMillTool(); // Get the tool from the assembly
                                                       // Cast it to the type to access specific properties!
                var tool = millTool as TlToolEndmill;
                Debug.Assert(tool != null, "Cast to TlToolEndmill type was invalid!");

                tool.ToolNumber = 1;
                tool.Name = "Pocket Nc Tool 1/8";

                // If you are changing the "length" of the tool ->
                // It is best to update both the OverallLength and TruePhysicalLength properties.
                // Setting them apart will tell the containing assembly that the projection of that tool
                // is whatever is in the overall length property.
                // If the overall length is set to be greater than the current true physical length,
                // the true physical length is updated to match the overall length value.

                // Set the Overall dimensions
                tool.OverallDiameter = 0.125; // Cutting diameter
                tool.TruePhysicalLength = tool.OverallLength = .8; // Overall length
                tool.CuttingDepth = 0.5; // Flute Length / Cutting Length

                // Set the Cutting geometry dimensions
                tool.TipDiameter = 0.125;

                // Set the Non-cutting geometry dimensions
                tool.ShoulderLength = .75; // Shoulder length
                tool.ShoulderDiameter = .125; // Shoulder diameter
                tool.ArborDiameter = .125; // Shank diameter

                // Set the Shank Type
                tool.ShankType = TlShankType.Straight; // Straight / Tapered / Reduced

                // tool.ShankType = TlShankType.Tapered; // Straight / Tapered / Reduced
                // tool.TaperAngle = 45.0;
                //// or...
                // tool.TaperLength = 0.135;

                // tool.ShankType = TlShankType.Reduced; // Straight / Tapered / Reduced
                // tool.NeckDiameter = 0.5; // Neck Diameter
                // tool.TaperLength = 0.575; // Neck length

                // Set Feed/Speed parameters
                var toolOpParams = tool.OpParams;
                toolOpParams.FeedRate = 50.0;
                toolOpParams.PlungeRate = 5.0;
                toolOpParams.RetractRate = 50.0;
                toolOpParams.SpindleSpeed = 500;

                tool.OpParams = toolOpParams;

                // Set the changed Tool into the Assembly.
                assembly.MainTool = tool;
                // Add more segments?
                assembly.MainHolder = holder; // Set the Holder into the Assembly

                // ** IMPORTANT ***
                // If the assembly was a default assembly before making this change, we need to set the "IsDefault" property
                // on the assembly to make Mastercam understand that this is now a user defined assembly.  Default assemblies
                // in Mastercam are treated as regular tools with a default holder.  Non-default assemblies are presented
                // differently in the tool lists throughout Mastercam through the filtering options and name outputs.
                // This step will not be required in the long-term, but for the short-term, setting this property is necessary
                var set = assembly.SetAsDefaultAssembly(false);
                Debug.Assert(set, "Assembly is still set as a default assembly");

                return assembly;
            }
            return null;
        }

 

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