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:

Roger Martin from CNC Software

CNC Software
  • Posts

    2,870
  • Joined

  • Last visited

  • Days Won

    6

Posts posted by Roger Martin from CNC Software

  1. Rui,

     

    You do not want your C-Hook to be a CWinApp.

    A C-Hook for “modern” Mastercam is a MFC extension style DLL.

     

    You’ll not need these old pretranslate callbacks.

    Having never heard of these pretranslate callbacks, I searched back and found that they were removed after Mastercam X2 (8 years and 2 weeks ago!).

     

    Using Visual Studio 2013 (required for X9 and the upcoming 2017) create a new C-Hook project using the CHookWizard (Project Template) that the C-Hook SDK installs into VS-2013.

    It may be easier just to move your code over to this new project instead of retro-fitting you old project

     

     

  2. In X9, in a NET-Hook you cannot really know when all of the operations have completed (or not) .

     

    In Mastercam 2017 there will be a new Notify method jut for this purpose ->

     

    public override MCamReturn MultiThreadOpStateNotify(int opId, MCamMultiThreadOpState state)
    {
        string status = "Unknown";
        switch (state)
        {
            case Mastercam.App.Types.MCamMultiThreadOpState.Success:
                status = "Success";
                break;
            case Mastercam.App.Types.MCamMultiThreadOpState.Stopped:
                status = "Stopped";
                break;
            case Mastercam.App.Types.MCamMultiThreadOpState.Failed:
                status = "Failed";
                break;
        }
     
        MessageBox.Show(
            string.Format("opID: {0}\nState: {1}", opId, status), 
            "MultiThread Manager",
            MessageBoxButtons.OK, 
            MessageBoxIcon.Information);
     
        return Mastercam.App.Types.MCamReturn.NoErrors;
    }
     
    You'd make note of the opIDs that you submitted to be regenerated and then using the MultiThreadOpStateNotify method you can determine their status.
  3. Is there a way to turn a level visibility off in the nethook such that the mastercam user will be able to toggle it back on with one click in the level manager?

     

    Doesn’t appear to be. I was a bit surprised myself.

    It must have never come up before. (The behavior was the same in X8.)

    I’ll log a request that this be investigated further to see what can be done in the future.

     

    Is there a way to create geometry on an invisible level then chain it using the references?

     

    You can create geometry on an invisible level, but you cannot chain entities that are not visible.

     

     

    Roger Martin

    CNC Software, Inc.

     

    API/SDK support survey

    • Like 1
  4. SetEntityLevel sets the level of an entity.

    ​You have not told it which entity to alter.

    You need to run through the entities that you've 'selected' and change them.

    '////////////////////////////////////////////////////////////////////////////////
    '// File Name:  MoveToLevel.vbs
    '// Date:       02/19/2016
    '//
    '// Description:   
    '// This script demonstrates changing the Level of entities.
    '// So we are "moving" all entities (that are NOT on Level #1) to Level #6 
    '//
    '//////////////////////////////////////////////////////////////////////////////// 
    Const DEF_GIVE_ME_EVERYTHING = -1
    
    ' -- Start Script
    Call Main()
    
    ' ////////////////////
    ' Sub Declaration
    ' ////////////////////
    Sub Main()   
    
    Dim bRet
    
    ' Turn off Level #1 so we do NOT select anything on this level
    Call SetLevelVisibleByNumber(1, False)
    
    ' This selects all "visible" entities
    SelectAll
    
    ' Run through the database looking for selected entities
    bRet = StartDBSearch(mc_selected, DEF_GIVE_ME_EVERYTHING)
    
    If bRet Then
    Do 
     ' Change the level on each "selected" entity that we find. 
      Call SetEntityLevel(6) 
      bRet = NextDBSearch    
      Loop While bRet  
    End If
    
    ' Like is says...
    UnselectAll
    
    ' Here we assume that the data we "moved" was on Level #7
    ' So we want to remove that level from the levels list.
    ' Usually we do not need to do anything as the level has no entities, but...
    ' If a level has a name, Mastercam will not auto-purge it as an empty level
    Call SetLevelName (7, "")
    
    ' Refresh (and FIT) the graphics display
    Call RepaintScreen(True)
    
    End Sub
    
    
    • Like 1
  5. Forget about *UpdateToolSettings, as it’s not going to do anything useful for  here.

    Even if it actually completely successfully…

    It updates the tool info in the operation, except for these Operation values ->

    LengthOffset

    DiameterOffset

    SpindleSpeed

    FeedRate

    PlungeRate

    RetractRate

    op.OperationTool = tool;
    op.Commit();
    bool result = op.UpdateToolSettings(); // Check the return of this method. It is true?
    
    
  6. No, it's not quite exactly like -> choosing "Re-initialize feeds and speeds" in the operation parameters window

     

    Unless I'm missing something, I would not expect this to really do anything.

     



    op.OperationTool = tool;
    op.Commit();
    op.UpdateToolSettings();



    You set the Tool into the Operation and Commit the Operation (all good).

    The op.UpdateToolSettings() after is only going to push data from the Tool that is already in the Operation.

  7. Indeed it does fail when attempting to process a Makino TECH file.

    There are some thickness values in those Makino TECH files that fail this 'convert text to double' -

    let t = Convert.ToDouble(record.Element("thickness").Value)

    So... if wish wish to process those files, we'll need some additional logic it determine the thickness value(s).

     

    Try it on one the Mitsubishi named TECH files and it works. [e.g. Mitsubishi (FA-S).tech]

    *You may not see any difference the _OUT file, as most (if not all) of the TECH files are already ordered by increasing material 'thickness'.

  8. You can launch a NET-Hook from within a PST.

     

    For manipulating XML data, .NET is the easy way to go.

     

    This (C#) method reorders the <record> items within each <record_block> by the Material Thickness.

    You can find examples of the data this works with in ->

    C:\Users\Public\Documents\shared mcamx9\wire\Power

    Those .TECH files you see there are XML data.

     

    You can use the free Visual Studio Community Edition to build NET-Hooks ->

     
    bool ReorderByMaterialThickness(string inFile, string outFile)
        {
            bool result = false;
            try
            {
                XDocument document = XDocument.Load(inFile);

                foreach (var rb in document.Descendants("record_block"))
                {
                    // A LINQ statement to select and sort the record items in the TECH (XML) data file.
                    var records = from record in rb.Elements("record")
                        let t = Convert.ToDouble(record.Element("thickness").Value)
                        orderby (t)
                        select record;

                    int cnt = 1;
                    foreach (XElement rec in records)
                    {
                        // reset the num attribute on the record
                        rec.Attribute("num").Value = (cnt++).ToString();

                        // We've done something, so assume that it's good. ;)
                        result = true;
                    }

                    // We need the reordered data to be an Array format.
                    var reordered = records.ToArray();

                    // Reove the old records.
                    rb.Elements("record").Remove();

                    // And repalce them with the new reordered ones.
                    rb.Add(reordered);
                }

                document.Save(outFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ReorderByMaterialThickness");
            }

            return result;
        }

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