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

Everything posted by Zaffin_D

  1. Can you provide an example? The below works for me. std::wstring filename (geo_filename);
  2. To normalize/unitize is to make the Vector have a length of 1unit.
  3. If you want to know how alike two 3D vectors are, normalize them, then dot them. If the dot product is 0 (or very close to it, remember not to trust floating point numbers) then the vectors are orthogonal. If the dot product is -1 then they are 180 degree apart.
  4. Maybe the update I just pushed will correct this behavior.
  5. I just tested 2021 and it worked with the most basic example... pheader$ sparameter$ = opinfo(1051, 0) ">>>" sparameter$, e$ I'd send a zip2go over to [email protected], perhaps they can sort it out.
  6. Here is a link to a full refactor on GitHub. I'm not sure if it's doing what you want, but it does something!
  7. 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. Can you share a bit more about what you are trying to do?
  8. 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
  9. Try right clicking on the tool parameters tab, the option is there.
  10. 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.
  11. No, chamfer drill cannot produce a canned cycle.
  12. 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.
  13. The tt_ variables are only numeric if I recall correctly. The opinfo function is the way to go here.
  14. You don’t need a buffer. Search the documentation for opinfo, you can query the next operations tool description easily.
  15. 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
  16. That’s far too much for what you want to do. Create a loop to look for the next tool, and keep track of how far forward you looked for it. Then use that as your look ahead to grab the next tool’s 20002.
  17. The 20002 data is only written to the NCI when there is a physical tool change. Post this on the official forum so someone from CNC’s post team can have a look.
  18. At this point it really is a proof of concept; I had a few hours last weekend so I decided to take a whack at it.
  19. 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.
  20. 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); } }
  21. 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.
  22. I know enough to be dangerous, but I don’t understand what you are trying to do. Can you provide an example?
  23. 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.
  24. It counts all tool changes, not just the physical ones. A stack is my preferred method for tracking the number of times a tool has been used.

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