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:

Zaffin_D

Verified Members
  • Posts

    374
  • Joined

  • Days Won

    1

Posts posted by Zaffin_D

  1. On 11/16/2022 at 4:41 AM, SlaveCam said:

    Still same...

    It's odd that only if Contour Ramp is included, the scanning fails. Feels like a bug, anyone else?

    I looked at the NCI and each operation (even contour ramp) contains a 1051 after the 999.  I've also had no trouble doing the following...

    #// Postblock
    op_index       : 0
    
    operation_id   : 0
    s_machine_name : ""
    
    p_write_machine_names
        op_index = 0
        while s_machine_name <> "-99999",
        [
            operation_id = opinfo(1, op_index)
            s_machine_name = opinfo(1051, op_index)
    
            *operation_id, s_machine_name, e$
    
            op_index = op_index + 1
            s_machine_name = opinfo(1051, op_index)
        ]
    
    #// Call
    pheader$         #Call before start of file
        p_write_machine_names
      
    // Sample output
    operation_id 1. Mill Default
    operation_id 2. Mill Default
    %
    O0000(T)
    (DATE=DD-MM-YY - 19-11-22 TIME=HH:MM - 11:07)
    (MCAM FILE - T)

     

    My operations.

    image.png

     

    Can you share a bit more about what you are trying to do?

    • Like 1
  2. I haven't done a full refactor of your code, but you are repeating yourself a lot.

    I refactored one of your methods, offsetCutchain.

    First, I created two service classes: SelectionUtilities...

    // File: SelectionUtilities.cs
    
    using Mastercam.Database.Types;
    using Mastercam.GeometryUtility;
    using Mastercam.IO;
    using Mastercam.Support;
    
    namespace eMastercamRateMyCode
    {
        internal class SelectionUtilities
        {
            public void UnselectAll() 
                => SelectionManager.UnselectAllGeometry();
    
            public void TurnOffVisibleLevels(bool refreshLevelsList = true)
            {
                var shown = LevelsManager.GetVisibleLevelNumbers();
                foreach (var level in shown)
                {
                    LevelsManager.SetLevelVisible(level, false);
                }
                if (refreshLevelsList)
                    LevelsManager.RefreshLevelsManager();
            }
    
            public void SetMainLevel(int levelNumber, bool makeVisible = true, bool refreshLevelsList = true)
            {
                LevelsManager.SetMainLevel(levelNumber);
                LevelsManager.SetLevelVisible(levelNumber, makeVisible);
    
                if (refreshLevelsList)
                    LevelsManager.RefreshLevelsManager();
    
                GraphicsManager.Repaint(true);
            }
    
            public bool CreateLevel(int levelNumber, string levelName, bool setAsMain = true, bool makeVisible = true)
            {
                var result = LevelsManager.SetLevelName(levelNumber, levelName);
    
                if (setAsMain)
                    LevelsManager.SetMainLevel(levelNumber);
    
                LevelsManager.SetLevelVisible(levelNumber, makeVisible);
    
                LevelsManager.RefreshLevelsManager();
    
                return result;
            }
    
            public int MoveSelectedToLevel(int levelNumber, bool clearSelection = true, bool clearColors = true)
            {
                var numberOfEntsCopied = GeometryManipulationManager.MoveSelectedGeometryToLevel(levelNumber, clearSelection);
    
                if (clearColors)
                    GraphicsManager.ClearColors(new GroupSelectionMask(true));
    
                return numberOfEntsCopied;
            }
    
            public int ColorAndSelectResultGeometry(int colorID, bool isSelected = true)
            {
                var numberOfEntsCommitted = 0;
    
                var resultGeometry = SearchManager.GetResultGeometry();
                foreach (var geometryEntity in resultGeometry)
                {
                    geometryEntity.Color = colorID;
                    geometryEntity.Selected = isSelected;
                    
                    if (geometryEntity.Commit())
                        numberOfEntsCommitted++;
                }
    
                return numberOfEntsCommitted;
            }
        }
    }

    ...and GeometryUtilities...

    // File: GeometryUtilities.cs
    
    using Mastercam.Curves;
    using Mastercam.Database;
    using Mastercam.Database.Types;
    using Mastercam.Math;
    using System.Collections.Generic;
    using System.Linq;
    
    namespace eMastercamRateMyCode
    {
        internal class GeometryUtilities
        {
            public bool CreateLine(Crease crease)
            {
                var lowerPoint = new Point3D(crease.LowerPoint.X, crease.UpperPoint.Y, 0.0);
                var upperPoint = new Point3D(crease.UpperPoint.X, crease.UpperPoint.Y, 0.0);
                var line = new LineGeometry(lowerPoint, upperPoint);
                line.Selected = true;
                return line.Commit();         
            }
    
            public List<Chain> ChainAllByLevel(int levelToChain) 
                => ChainManager.ChainAll(levelToChain).ToList();
    
    
            public Chain OffsetChainLeft(Chain chainToOffset, double radius)
            {
                return OffsetChain(chainToOffset, OffsetSideType.Left, radius);
            }
    
            public Chain OffsetChainRight(Chain chainToOffset, double radius)
            {
                return OffsetChain(chainToOffset, OffsetSideType.Right, radius);
            }
    
            private Chain OffsetChain(Chain chainToOffset, OffsetSideType offsetSide, double radius)
            {
                return chainToOffset.OffsetChain2D(offsetSide, radius, OffsetRollCornerType.None, .5, false, .005, false);
            }
        }
    }

    The I created the UtilitiesFacade facade... 

    // File: UtilitiesFacade.cs
    
    namespace eMastercamRateMyCode
    {
        internal class UtilitiesFacade
        {
            public SelectionUtilities Selection;
            public GeometryUtilities Geometry;
    
            public UtilitiesFacade()
            {
    
            }
        }
    }

    I also created two small structs to hold common chain data.

        public struct LevelData
        {
            public int Number { get; set; }
            public string Name { get; set; }
        }
    
        public struct ChainData
        {
            public LevelData Level { get; set; }
    
            public int ColorID { get; set; }
    
            public double SmallOffsetRadius { get; set; }
    
            public double LargeOffsetRadius { get; set; }
        }

    With that done, the refactored method offsetCutchain looks like this...

                void OffsetCutChain(int cutChainlevel, ChainData lower, ChainData upper)
                {
                    var utilities = new UtilitiesFacade();
    
                    utilities.Selection.UnselectAll();
                    utilities.Selection.TurnOffVisibleLevels();
    
                    utilities.Selection.SetMainLevel(cutChainlevel);
    
                    utilities.Selection.CreateLevel(lower.Level.Number, lower.Level.Name);
    
                    utilities.Selection.CreateLevel(upper.Level.Number, upper.Level.Name);
    
                    foreach (var chain in utilities.Geometry.ChainAllByLevel(cutChainlevel))
                    {
                        utilities.Geometry.OffsetChainRight(chain, lower.SmallOffsetRadius);
                        utilities.Geometry.OffsetChainLeft(chain, lower.LargeOffsetRadius);
    
                        utilities.Selection.ColorAndSelectResultGeometry(11);
                        utilities.Selection.MoveSelectedToLevel(lower.Level.Number);
    
                        utilities.Geometry.OffsetChainLeft(chain, upper.SmallOffsetRadius);
                        utilities.Geometry.OffsetChainRight(chain, upper.LargeOffsetRadius);
    
                        utilities.Selection.ColorAndSelectResultGeometry(upper.ColorID);
                        utilities.Selection.MoveSelectedToLevel(upper.Level.Number);
                    }
                }

     

    This still is not ideal (could use more abstraction, less dependencies, etc.), but it's far less repetitive.
      
    Hope that helped,

    Zaffin

    • Like 2
  3. 2 hours ago, metzenwest said:

    So, I've been getting more into basic post edits. It's appears I've stepped into something that my extremely limited knowledge of coding has stumped me. First off, I don't even know the proper terminology for what I'm trying to do. So please bear with me here.

    I'm trying to convert? an Operation comment into a string so I can do a Regex to set a flag to do something.

    Basically if the operation comment has the word Rough in it. I want it to turn on the cover coolant of the machine. Cause I'm lazy and don't want to setup Misc Int's.

    My search on the forum hasn't yielded anything, cause im probably searching for the wrong thing.

     

    Thanks,

    What have your tried?

    The abstract; at tool change, read the operation comment into a variable using opinfo.  Once you have the comment, use the regex function to parse it.

  4. 10 minutes ago, Doug Funny said:

    I modeled the appropriate chamfers and used a Chamfer Drill operation. The only downside is that Chamfer Drill long codes everything out instead of using canned cycles. Most of the machinist here are a bunch of old curmudgeons. If the see programs like this, I'll never hear the end of it.  Is there a way to get Chamfer Drill to output a canned cycle?

    No, chamfer drill cannot produce a canned cycle.

    • Thanks 1
    • Like 1
  5. I’m riffing this (I don’t have access to a PC till next week), so I expect it to be about 80% correct.

    Get the next tool number using opinfo, if you want the next operation, use a 1 for the number of ops to look ahead.  Compare that to the current tool number, if they are equal (or the next tool number is -99999) do nothing.  If the next tool number is different than the current tool number (and not -99999), get the next tool’s description and output it.

    You always want to look ahead to the next operation, and there is no easy license plate setting to get the next operations parameter if the tool changed.

     

     

    • Like 1
  6. On 11/25/2021 at 12:20 PM, Master Disaster said:

    Thanks @Zaffin_D I tried what you suggested but unfortunately I don't know how to get the next op_id$, what I need to query the 20002 parameter. The problem of op_id$ is that this is not an ordered number. Would be happy if you can give me more hints 😀

    You do not need the op_id$ in this case; your only concern is how many operations are between the current operation and the next physical tool change.

    In the below example, I set up a postblock to populate the s_next_20002 variable;  p_get__s_next_20002.  This postblock takes one parameter by reference and loops through the upcoming operations looking for the next physical tool change.  Once the next physical tool change has been found, the lookahead_index variable contains the number of operations needed to look ahead for the next 20002.  The parameter p_get__s_next_20002 modifies is a bool telling the caller if a valid 20002 was found or not. 

    This is  as much as I can help; your reseller and the official forums are great resources if you have follow up questions.  

    Implementation example: 

    lookahead_index         :  0
    next_tool_change_gcode  :  0
    invalid                 := -99999
    
    s_next_20002            :  ""
    s_invalid               := "-99999"
    
    is_valid_arg            :  no$
    
    p_get__s_next_20002(!is_valid_arg)
        lookahead_index = 1
        next_tool_change_gcode = opinfo(92, lookahead_index)
    
       while next_tool_change_gcode <> invalid,
            [
            if next_tool_change_gcode = 1002,
                [
                next_tool_change_gcode = invalid
                ]
            else,
                [
                lookahead_index = lookahead_index + 1
                next_tool_change_gcode = opinfo(92, lookahead_index)
                ]
            ]
    
        s_next_20002 = opinfo(20002, lookahead_index)
        is_valid_arg = (s_next_20002 <> s_invalid)

     

    Calling example:

    psof$            #Start of file for non-zero tool number
          p_get__s_next_20002(!result)
          if result, "Next 20002->", s_next_20002, e$
      
    ptlchg$          #Tool change
          p_get__s_next_20002(!result)
          if result, "Next 20002->", s_next_20002, e$

     

    Output Example:

    ( T1 | 0.5 FLAT ENDMILL | H1 )
    ( T239 |  1/2 FLAT ENDMILL | H239 )
    Next 20002-> Tool code 2
    N100 G20
    N110 G0 G17 G40 G49 G80 G90
    ( FINISH OUTER WALLS )
    N120 M8
    N130 T1 M6
    
    ...
    
    N280 G91 G28 Z0.
    N290 A0.
    Next 20002-> Tool code 1
    N300 M01
    ( CONTOUR 2 )
    N310 T239 M6
    N320 G0 G90 G17 G56 X-2.8424 Y-.789 A0. S1069 M3
    N330 G43 H239 Z.25
    
    ...
    
    N570 G91 G28 Z0.
    N580 A0.
    N590 M01
    ( MANUAL ENTRY TEXT COMMENT )
    ( FINISH OUTER WALLS )
    N600 M8
    N610 T1 M6
    N620 G0 G90 G17 G56 X-2.8424 Y-.789 A0. S15000 M3

     

    • Like 3
  7. On 9/8/2021 at 5:15 PM, Metallic said:

    …Back on topic, if anyone has a QUICK way to grab CSV tooling data from either standalone Tool Manager or Mastercam 2022 I would be eternally grateful. The export tool data switch that used to live in Advanced Config apparently doesnt exist there anymore. I'm sorry if i sound dumb but I really don't know scripting (want to learn) and don't understand exactly what that example above was describing exactly

    Can you use json or xml, or do you need a csv?

    For fun, I took a quick look at exporting a csv this weekend (importing from a csv doesn’t seem  practical), and this proof of concept is what I came up with.

    • Thanks 1
  8. On 8/31/2021 at 5:46 PM, Metallic said:

    I would like someone *anyone* to make a quick youtube tutorial on how to export Mastercam tooling data in .CSV format or something similar so that I can harness excel in my tooling management workflow.

     

    If you only want to extract information and you're using Mastercam 2022 a script can do this.

    You'd want more information, but here is an example.

    #r "C:\Program Files\Mastercam 2022\Mastercam\ToolNetApi.dll"
    
    using System.IO;
    using System.Linq;
    
    using Cnc.Tool.Interop;
    
    
    var filePath = Path.ChangeExtension(FileManager.CurrentFileName, ".csv");
    
    var tlMgr = TlServices.GetTlMgr();
    
    var isHeaderWritten = false;
    
    using (var writer = new StreamWriter(filePath))
    {
        foreach (var tlAssembly in tlMgr.GetAssemblies()
                                        .Where(t => t.GetMillTool() != null))
        {
            if (!isHeaderWritten)
            {
                var header = $"TOOL NUMBER, " +
                             $"OVERALL DIAMETER, " +
                             $"OVERALL LENGTH, " +
                             $"NAME";
    
                writer.WriteLine(header);
    
                isHeaderWritten = true;
            }
    
            var millTool = tlAssembly.GetMillTool();
    
            var outputToolData = $"{millTool.ToolNumber}, " +
                                 $"{millTool.OverallDiameter}, " +
                                 $"{millTool.OverallLength}, " +
                                 $"\"{millTool.Name}\"";
    
            writer.WriteLine(outputToolData);
        }
    }
                

     

    • Like 4
  9. Ok I’m taking a shot in the dark without knowing how the data is represented, but this may get you started.

    In order to move the positions between coordinate systems you need move the point to world, then move the point to the new system.  
     

    This can done by multiplying the point through the inverse (same as the transpose if the matrix is orthonormal) of the original coordinate system’s matrix (that will put the point in world; X=1,0,0; Y=0,1,0; Z=0,0,1), then multiply the point in world through the new matrix to put it in that space.

    It sounds like the new matrix will be a rotation matrix based on the machines angles, but again; this is a shot in the dark.

     

    Hope that helps get you going.

  10. 37 minutes ago, Flycut said:

    But even if I change this setting to 2.5 I see no difference in my backplot, verify or nc code.

    Correct.  I’m not sure what the original intent of this setting was; but I don’t think it’s done anything in recent releases.

    In Mastercam 2022 it has been removed.

    • Like 1

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