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

 /// <summary>
 /// Create a tool assembly
 /// </summary>
 /// <param name="buildParams"></param> // the parameter
 /// <returns>a tool assenbly object</returns>
    private TlAssembly AddNewAssemblyToDatabase(AssemblyBuilderParams buildParams)
        {
            // build path to tools
            var folder = System.IO.Path.Combine(Mastercam.IO.SettingsManager.SharedDirectory, "mill\\Tools");


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

            if (!System.IO.File.Exists(buildParams.geometryFile))
            {
                Mastercam.IO.DialogManager.Exception(new Mastercam.App.Exceptions.MastercamException($"File not found { buildParams.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)
                {
                    Mastercam.IO.DialogManager.Exception(new Mastercam.App.Exceptions.MastercamException($"Failed to open {toolDb}"));
                    return null;
                }

                var holder = new TlHolder
                {
                    // assign the name
                    Name = buildParams.name,

                    // assign the description
                    Description = buildParams.description,

                    // assign the path
                    GeometryFile = buildParams.geometryFile,
                };

                success = TlGeometryImportExport.ImportProfileFromFile(holder, buildParams.geometryFile);

                if (!success)
                {
                    Mastercam.IO.DialogManager.Exception(new Mastercam.App.Exceptions.MastercamException($"Failed to Import Profile From File { buildParams.geometryFile}"));
                    return null;
                }

                if (buildParams.deleteExistingLibraryTools)
                {
                    success = tls.DeleteAll();

                    if (!success)
                    {
                        Mastercam.IO.DialogManager.Exception(new Mastercam.App.Exceptions.MastercamException($"Failed to Delete All Tools { buildParams.geometryFile}"));
                        return null;
                    }
                }
                
                var assembly = this.CreateFlatEndMillToolAssembly(holder);
                // add to tool library
                success = tls.Add(assembly);
                tls.Update(assembly);

                if (success)
                {


                    if (buildParams.import)
                    {

                        var importedTools = new System.Collections.Generic.List<Cnc.Tool.Interop.TlTool>();

                        var importedAssemblies = new System.Collections.Generic.List<Cnc.Tool.Interop.TlAssembly>();

                        var idList = new System.Collections.Generic.List<System.Guid>();

                        if (importedAssemblies == null)
                        {
                            throw new System.Exception("Assemblies list is null");
                        }

                        tls.GetAllTlTools(importedTools);

                        tls.GetAllTlAssemblies(importedAssemblies);

                        for (var i = 0; i < importedAssemblies.Count; i++)
                        {

                            if (importedAssemblies[i] == null)
                            {
                                throw new System.Exception("Assembly list is null");
                            }
                            var importedassembly = new Cnc.Tool.Interop.TlAssembly();
                            var assembliees = importedAssemblies[i];

                            Cnc.Tool.Interop.TlServices.GetIToolSystem().Add(importedAssemblies[i]);

                            if (buildParams.assignToAllOperations)
                            {

                                var operations = Mastercam.Support.SearchManager.GetOperations();

                                foreach (var operation in operations)
                                {
                                    var op = operation as Mastercam.Operations.ChainBasedOperation;
                                    if(op != null)
                                    {
                                       var chans = op.GetChainArray();

                                        operation.AssignMillToolBySlot(importedAssemblies[i].GetMillTool().Slot);

                                        op.Commit();

                                        op.SetChainArray(chans);

                                        op.Commit();
                                    }

                                }

                            }

                        }

                    }

                    return assembly;

                }

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

            return null;
        }
        #endregion

This is the final function that is called by our nethook

Link to comment
Share on other sites
2 minutes ago, So not a Guru said:

Ok, is this a new file added to your github, or do I need to replace each of the sections in the file from Friday with these new sections?

It's a new file on github.

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

It works, but it works the same as the one Friday. It brings the holder in upside down. I tried rotating the step file 180°, but it still comes in upside down🙃Capture.thumb.PNG.e9ca55b3afcf321184f17ad03e5e8f4b.PNG

That's funny, mine didn't come in upside down. I'll check..

Link to comment
Share on other sites

Wow excellent work Peter. I am currently building tools for a job one by one. I need to strip out the Taper then save the holders in to the existing tool library then build a tool from the solid to then make the assembly. I have 10 hour so far going into NOVO to find and build them and then have my 2 Mastercam files. One file is the build the tools library and the other is the programming file for the part. I didn't want to clutter up the Mastercam file with everything in the one file. If you interested in seeing the work I can zip up the tool file and the stp files from the holders and email you them.

Link to comment
Share on other sites
2 minutes ago, crazy^millman said:

Wow excellent work Peter. I am currently building tools for a job one by one. I need to strip out the Taper then save the holders in to the existing tool library then build a tool from the solid to then make the assembly. I have 10 hour so far going into NOVO to find and build them and then have my 2 Mastercam files. One file is the build the tools library and the other is the programming file for the part. I didn't want to clutter up the Mastercam file with everything in the one file. If you interested in seeing the work I can zip up the tool file and the stp files from the holders and email you them.

Yes, you can shoot me an email Ron.

I'll take a look.

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

 

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);
        }

 

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

Not sure if you are aware or you are doing this for a specific need there are file open and file save dialogs that are simple to implement.

 

 

 

filedialog.png

Link to comment
Share on other sites
12 minutes ago, Mick George said:

Not sure if you are aware or you are doing this for a specific need there are file open and file save dialogs that are simple to implement.

 

 

 

filedialog.png

Mick, 

I think there were complaints about the implementation of the .net openfiledialog from my team of programmers, I think the quick access list wasn't accessible so the users had a hard time navigating, It's possible they updated it for windows 10.

It's hard to remember, I get a lot of complaints lol.

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

What does it mean? "Strip out the Taper."

All CAT, BT, HSK,CAPTO, KM holders come with the taper that attaches it to the machine. Mastercam doesn't support from the Gauge Length when running Machinesim or MT. Everything get put in them from the end of the holder so I have to strip out the Taper on any holder for any customer that I am not running the projects through External CAV. I keep the taper for customers that I use external CAV on, but anyone where I don't then it has to be stripped out. Sucks having one set of holders with the taper and another set of holders without them, but it is what it is. I may have 3 sets of holders for some customers. I have the original one. I have the taper removed one. Then I have the dumbed down to even work in the tool manager.

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

 I see, so you are swapping holders, this could be automated, you will save yourself a lot of work.

Well not only that, but the dumbing down process in my opinion could be automated as well. We know all the holders cannot have anythign above the gague line then intergate the mdoel and detrime what is above the gague line and do a automtaic mdoel prep to remove those features. Files fail to import into the holders so then use that same check when cleaning them up. They don't pass that test then check for that test and then you have a better process to make what you need and follow soemthign without all the manunal step involved to make it happen. That is the issue the developers don't have to do the grunt work we do they make all these cool things, but then never have to put it into real world use.They call it good enough, but seems to many are so disconnected from the end users they miss way and methods to improve the rpcoess and automate it.

Sorry no spell check today.

Link to comment
Share on other sites
3 minutes ago, crazy^millman said:

Well not only that, but the dumbing down process in my opinion could be automated as well. We know all the holders cannot have anythign above the gague line then intergate the mdoel and detrime what is above the gague line and do a automtaic mdoel prep to remove those features. Files fail to import into the holders so then use that same check when cleaning them up. They don't pass that test then check for that test and then you have a better process to make what you need and follow soemthign without all the manunal step involved to make it happen. That is the issue the developers don't have to do the grunt work we do they make all these cool things, but then never have to put it into real world use.They call it good enough, but seems to many are so disconnected from the end users they miss way and methods to improve the rpcoess and automate it.

Sorry no spell check today.

If your gaugle line is at a know coordinate z0.?

Then you could automate a boolean process to trim the solid.

I know how actually.

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

If your gaugle line is at a know coordinate z0.?

Then you could automate a boolean process to trim the solid.

I know how actually.

Yes from what I am seeing from many of the companies they are placing the GL on Zero. Problem might be they don't have aligned correctly through the Z axis then the tool would need to check and make sure that is happening. I think Hamier are the ones still exporting them along the Y axis for alignment verse Z like the majority are doing. Again only for MT and Mastercam Machinesim is this needed. 11 years had a conversation about this in Tolland so maybe we will see the GL supported soon since every manufacture goes through all the trouble of making holders the tapers on them. Just saying sure is a pain having to go through a step that wouldn't be needed if this was implemented.

Link to comment
Share on other sites
1 hour ago, crazy^millman said:

Yes from what I am seeing from many of the companies they are placing the GL on Zero. Problem might be they don't have aligned correctly through the Z axis then the tool would need to check and make sure that is happening. I think Hamier are the ones still exporting them along the Y axis for alignment verse Z like the majority are doing. Again only for MT and Mastercam Machinesim is this needed. 11 years had a conversation about this in Tolland so maybe we will see the GL supported soon since every manufacture goes through all the trouble of making holders the tapers on them. Just saying sure is a pain having to go through a step that wouldn't be needed if this was implemented.

I'm going to tackle the holder swapping first.

Maybe the boolean second, that one has a lot of moving parts

Link to comment
Share on other sites
  • 3 weeks later...
  • 2 weeks later...
On 2/15/2021 at 5:50 PM, crazy^millman said:

All CAT, BT, HSK,CAPTO, KM holders come with the taper that attaches it to the machine. Mastercam doesn't support from the Gauge Length when running Machinesim or MT. Everything get put in them from the end of the holder so I have to strip out the Taper on any holder for any customer that I am not running the projects through External CAV. I keep the taper for customers that I use external CAV on, but anyone where I don't then it has to be stripped out. Sucks having one set of holders with the taper and another set of holders without them, but it is what it is. I may have 3 sets of holders for some customers. I have the original one. I have the taper removed one. Then I have the dumbed down to even work in the tool manager.

 

On 2/16/2021 at 12:56 PM, crazy^millman said:

Well not only that, but the dumbing down process in my opinion could be automated as well. We know all the holders cannot have anythign above the gague line then intergate the mdoel and detrime what is above the gague line and do a automtaic mdoel prep to remove those features. Files fail to import into the holders so then use that same check when cleaning them up. They don't pass that test then check for that test and then you have a better process to make what you need and follow soemthign without all the manunal step involved to make it happen. That is the issue the developers don't have to do the grunt work we do they make all these cool things, but then never have to put it into real world use.They call it good enough, but seems to many are so disconnected from the end users they miss way and methods to improve the rpcoess and automate it.

Sorry no spell check today.

 

On 2/16/2021 at 2:13 PM, crazy^millman said:

Yes from what I am seeing from many of the companies they are placing the GL on Zero. Problem might be they don't have aligned correctly through the Z axis then the tool would need to check and make sure that is happening. I think Hamier are the ones still exporting them along the Y axis for alignment verse Z like the majority are doing. Again only for MT and Mastercam Machinesim is this needed. 11 years had a conversation about this in Tolland so maybe we will see the GL supported soon since every manufacture goes through all the trouble of making holders the tapers on them. Just saying sure is a pain having to go through a step that wouldn't be needed if this was implemented.

Crazy^Millman, 

When creating these projects, the programmer would need a plan to outline the app functionality.

 

1.Use a tool database called "DefaultCustomHolder.tooldb" in the mill/TOOLs folder OR Prompt the User to Select a tool database via a popup window (WIN32 FUNCTIONS)

2.Use a step/.stp file called "DefaultCustomStepFile.stp" in the mill/TOOLs folder OR Prompt the User to Select a step/.stp file via a popup window (WIN32 FUNCTIONS)

3.Import the step/.stp file into Mastercam and remove the upper portion of the 3d model using boolean remove (MASTERCAM FUNCTIONS)

4.Save the resulting step/.stp file in a new file called filename + result | For example "DefaultCustomStepFileResult.stp" (MASTERCAM FUNCTIONS)

5.Import the existing assemblies into Mastercam from "DefaultCustomHolder.tooldb" or the file the user chose in the popup window

6.Assign the new holder(s) resulting from the "trimmed" ,stp file into the existing assemblies in Mastercam

7.Save the Edited Assemblies in Mastercam into a new .tooldb file.

 

This is a non trivial request and would take a few weeks to complete, it's on my to do list near the top,

If I don't have the sequence right let me know..

Link to comment
Share on other sites
On 3/21/2021 at 7:18 AM, Thee Byte™ said:

 

 

Crazy^Millman, 

When creating these projects, the programmer would need a plan to outline the app functionality.

 

1.Use a tool database called "DefaultCustomHolder.tooldb" in the mill/TOOLs folder OR Prompt the User to Select a tool database via a popup window (WIN32 FUNCTIONS)

2.Use a step/.stp file called "DefaultCustomStepFile.stp" in the mill/TOOLs folder OR Prompt the User to Select a step/.stp file via a popup window (WIN32 FUNCTIONS)

3.Import the step/.stp file into Mastercam and remove the upper portion of the 3d model using boolean remove (MASTERCAM FUNCTIONS)

4.Save the resulting step/.stp file in a new file called filename + result | For example "DefaultCustomStepFileResult.stp" (MASTERCAM FUNCTIONS)

5.Import the existing assemblies into Mastercam from "DefaultCustomHolder.tooldb" or the file the user chose in the popup window

6.Assign the new holder(s) resulting from the "trimmed" ,stp file into the existing assemblies in Mastercam

7.Save the Edited Assemblies in Mastercam into a new .tooldb file.

 

This is a non trivial request and would take a few weeks to complete, it's on my to do list near the top,

If I don't have the sequence right let me know..

Looks good as an outline and agree not a trivial request. I figured 200-300 hours of development required just to get it kicked off. Then 400-600 hours of fine tuning after you have the base outline done.

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