Zaffin_D

Verified Members
  • Content count

    359
  • Joined

  • Last visited

  • Days Won

    1

Zaffin_D last won the day on May 8

Zaffin_D had the most liked content!

Community Reputation

223 Excellent

5 Followers

About Zaffin_D

  • Rank
    Advanced Member

Recent Profile Visitors

1,581 profile views
  1. 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
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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); } }
  7. Zaffin_D

    New Coordinate System Math

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

    New Coordinate System Math

    I know enough to be dangerous, but I don’t understand what you are trying to do. Can you provide an example?
  9. Zaffin_D

    Dia. (for simulation)

    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.
  10. 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.
  11. Zaffin_D

    wrapping a flat hole pattern to a cylinder

    Segment length / radius should give you the angle in radians. The file you uploaded has 40.365 degrees between the close holes; my math lands at 39.4261degrees. 1.18699992 / 1.725 = 0.6881158956521739 radians or 39.4261366 degrees. I used the roll function to confirm, what am I missing?
  12. That was provided just to show the math; you don't actually need it. The below method leverages the provided math stuff and achieves the same result. public Point3D ConvertToViewCoordinates(Point3D point, MCView destinationView) { var destinationViewMappedOrigin = ViewManager.ConvertToViewCoordinates(destinationView.ViewOrigin, destinationView); return ViewManager.ConvertToViewCoordinates(point, destinationView) - destinationViewMappedOrigin; }
  13. ViewManager.ConvertToViewCoordinates only appears to map the point; it doesn't seem to include the origin. Below is a short example showing how to take the shift into account. using Mastercam.App; using Mastercam.App.Types; using Mastercam.IO; using Mastercam.IO.Types; using Mastercam.Math; using Mastercam.Database; namespace pointMappingExample { public class Main : NetHook3App { public override MCamReturn Run(int param) { var selectedPoint = new Point3D(0, 0, 1); SelectionManager.AskForPoint("Select a point", PointMask.Null, ref selectedPoint); PromptManager.WriteString("Select the source view"); var sourceView = ViewManager.SelectFromPlaneList(); PromptManager.WriteString("Select the destination view"); var destinationView = ViewManager.SelectFromPlaneList(); PromptManager.Clear(); var pointService = new PointService(); var convertedPoint = pointService.ConvertToViewCoordinates(selectedPoint, destinationView); var transformedPoint = pointService.TransformToViewCoordinates(selectedPoint, sourceView, destinationView); DialogManager.OK($"Selected point(world)\n" + $" X:{selectedPoint.x}\n" + $" Y:{selectedPoint.y}\n" + $" Z:{selectedPoint.z}" + $"\n" + $"Converted point({destinationView.ViewName})\n" + $" X:{convertedPoint.x}\n" + $" Y:{convertedPoint.y}\n" + $" Z:{convertedPoint.z}" + $"\n" + $"Transformed point({destinationView.ViewName})\n" + $" X:{transformedPoint.x}\n" + $" Y:{transformedPoint.y}\n" + $" Z:{transformedPoint.z}", $"Results"); return MCamReturn.NoErrors; } } public class PointService { //Short method public Point3D ConvertToViewCoordinates(Point3D point, MCView destinationView) { var destinationViewMappedOrigin = destinationView.ViewMatrix.MapPoint(destinationView.ViewOrigin); return ViewManager.ConvertToViewCoordinates(point, destinationView) - destinationViewMappedOrigin; } //Long method public Point3D TransformToViewCoordinates(Point3D point, MCView sourceView, MCView destinationView) { var sourceViewMappedOrigin = sourceView.ViewMatrix.MapPoint(sourceView.ViewOrigin); var pointInSource = sourceView.ViewMatrix.MapPoint(point) - sourceViewMappedOrigin; var pointInTranspose = sourceView.ViewMatrix.GetTranspose().MapPoint(pointInSource) + sourceView.ViewOrigin; var destinationViewMappedOrigin = destinationView.ViewMatrix.MapPoint(destinationView.ViewOrigin); var pointInDestination = destinationView.ViewMatrix.MapPoint(pointInTranspose) - destinationViewMappedOrigin; return pointInDestination; } } public static class Matrix3DExtensions { public static Matrix3D GetTranspose(this Matrix3D m) { var rowOne = new Point3D(m.Row1.x, m.Row2.x, m.Row3.x); var rowtwo = new Point3D(m.Row1.y, m.Row2.y, m.Row3.y); var rowthree = new Point3D(m.Row1.z, m.Row2.z, m.Row3.z); return new Matrix3D(rowOne, rowtwo, rowthree); } public static Point3D MapPoint(this Matrix3D m, Point3D p) { var mappedX = (p.x * m.Row1.x) + (p.y * m.Row1.y) + (p.z * m.Row1.z); var mappedY = (p.x * m.Row2.x) + (p.y * m.Row2.y) + (p.z * m.Row2.z); var mappedZ = (p.x * m.Row3.x) + (p.y * m.Row3.y) + (p.z * m.Row3.z); return new Point3D(mappedX, mappedY, mappedZ); } } }
  14. I think you’ll need to map the point yourself if it’s not in world coordinates to begin with. Try multiplying the point through the transpose/inverse (They are the same in a unitized, orthogonal DCM) of the source view’s DCM (matrix), then multiply that point through the destination matrix. With this method you can convert a point in any view to any other view; the source point doesn’t need to be in world coordinates. Side note; you’re typing too much. Add some using directives so you don’t need to type out the namespaces.
  15. Just so you are aware, this is not an ideal use for opinfo. When you tell opinfo to query an NCI line it searches the NCI file that’s on disc. I’m almost positive you can get the value you are looking from a traditional parameter in memory, have you done a parameter dump? Using opinfo on an NCI line should only be done if the data isn’t available in memory.

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