Zaffin_D
-
Posts
374 -
Joined
-
Days Won
1
Content Type
Profiles
Forums
Downloads
Store
eMastercam Wiki
Blogs
Gallery
Events
Posts posted by Zaffin_D
-
-
16 minutes ago, Compaq007 said:
Thanks for the example code, it would have taken me a gazillion hours to figure the Matrix part of it.
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; }
- 2
-
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); } } }
- 1
-
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.
- 1
-
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.
-
On 3/27/2021 at 4:34 AM, Thee Byte™ said:
The View Names Template is a good improvement.
The User who suggested this improvement to me,
also had an idea the ability to automatically rename the existing transformation Degree number in the name to the new tranformation #;
For example,
Original Planes Name 1 -> "Custom User Plane a0." or "Custom User Plane X0."
The user typed 45.
Copied and transformed Planes Name 2 -> "Custom User Plane a45." or "Custom User Plane X45."
The add-in should probably take the old rotation angle if there was one,
and add the two angles together, then change the x or a # to the result of the equation
So if the user had a plane with the name x45 in it and the user entered another 45 degrees,
the new planes name would be x90
The Topic from Mastercam.com is here if you care to look.
That’s an interesting idea, but I’m not hot on it.
Are you going to implement it?
-
On 3/23/2021 at 9:24 PM, Thee Byte™ said:
I see you added multiple instances as well, that's so useful.
The U.I. looks amazing, I'm still stuck with 90's graphics with my winfotms.
Thanks!
Multiple instances was the driving force behind this add-in, as everything else can be done in Mastercam OOTB. I didn't like programing HMC's TOP-FRONT and wanted a quick way to create any number of views from an existing view and one of it's axes.
I actually went a bit crazy the past few evenings reworking the UI to reduce clicks and adding a view name template so the resulting views' names can be customized.
- 1
-
I did something similar awhile back, very cool!
- 1
-
On 3/19/2021 at 5:57 PM, motor-vater said:
singularity issue maybe???
I'd expect the motion on the inside corners to be erratic. Start at the lower right of the below image; notice how the flags (dark purple) are nicely flowing? Once we hit the corner, big swings start to happen.
This could be avoided by fixturing the part at an angle, or by smoothing the instability across multiple moves. The result of the latter is shown below.
-
I'm not familiar with scandic characters, so I grabbed some random non-ascii ones for this example.
s_return : "" s_replacement_char : "" flktbl 1 4 "A" "Ä" "E" "Ë" "I" "Ï" "O" "Ö" s_string : "STRÏNG ÖF MÏXËD CHÄRÄCTERS" p_sanitize_s_string s_return = regex("([^\x00-\x7F])", s_string, 0) while strlen(s_return), [ s_replacement_char = flook(1, s_return) s_string = regex(s_return, s_replacement_char, 2) s_return = regex("([^\x00-\x7F])", s_string, 0) ] psof$ "BEFORE: ", s_string, e$ p_sanitize_s_string *e$ "AFTER: ", s_string, e$
Sample output
BEFORE: STRÏNG ÖF MÏXËD CHÄRÄCTERS AFTER: STRING OF MIXED CHARACTERS
You would have to add all the replacement characters to the look up table, and if the replacements are outside the ascii range the regex would need to be modified; but you get the idea.
- 1
-
1 hour ago, Thee Byte™ said:
Perhaps using inline functions would help? Was this done in an managed or unmanaged environment? Or both?
I've tried this both managed and native add-ins. The result is the same; MP takes time to spool up the process. Also because of the serial nature of MP, nothing is happing until the called app returns. It's not a big deal if you are doing it a handful of times, but it can get bothersome.
In this case (parsing a string) MP's regex function would be very useful and much quicker than sending it out to an external app.
Not to derail this, but I think you should look into what inline-ing does.
-
That would work, but in my testing repeatedly using the launch or dll function will make the posting time much longer.
The dll function will allow you to pass three arguments between an add-in and the post; no need to write anything to disk in most cases.
-
You are out luck on both counts.
Strings can’t be passed as arguments.
MP post blocks can only operate on arguments; they cannot truly return a value.
-
8 minutes ago, crazy^millman said:
Yes that is going to be the issue because code expert is written to support $ as a defined variables in the MP language or end of line. Since you really need it to define a Spindle Variable going to be real tricky to get a Editor written to understand the dollar sign one way to do it a completely different way.
Might look to Cimco Editor Pro it handles Streams. Beyond Compare is a different editor that allows you to write your own scripts and other things.
Code expert’s highlighting is file dependent; nc files highlight differently than post files.
The $ sign is not a problem, a proper regular expression needs to be used to identify the sync points.
- 2
-
A $ in a regular expression asserts the end of a line, so that’s not going to work. Escape the $ with a \.
I highly suggest you use a site like regex101.com to help you if you are new to regular expressions.
- 1
- 1
-
6 hours ago, byte me said:
You need to get setup with the CycleTime chook for accurate times..
Not exactly.
The CycleTime add-in was created as a simple way to get a variety of cycle time information during posting. The times it provides are not more accurate.
-
10 minutes ago, JParis said:
If you can use G68.2 you can get helixes
For that to be true the post would have to be configured to build the helical arcs from the linear data. The NCI only contains linear moves with the axis control set to 4 or 5-axis.
-
The ‘C’ in threadC means contour, so using it with a single entity is not really it’s intended use.
Your reseller is correct, a custom post is required; I’m not aware of any CNC post that supports threadC. This is because threadC writes it’s parameters to the NCI and doesn’t fill out the normal threading NCI lines.
- 1
-
9 hours ago, keedo said:
Thanks for the replys
I have not altered anything yet
Yes its a special character and its cumming from my tool library (tool comment)
I just hoped that i could add a line of code, instead of going trough all my tool library's and manual deleting the ( ø )
The thing is that in all my old tool library's i have given all my tools names like " ø12 r2 " ø for the Diameter.
The old Haas machines that we have no problem. But the new Haas machine don't like this ø character and errors out. Evan though its only a comment inside ()
If you are using Mastercam 2019 or later, use a regular expression to sanitize the string.
s_regex := "[^\x00-\x7F]" s_replacement := "" psof$ *e$ "Before: ", ~strtool$, e$ strtool$ = regex(s_regex, s_replacement, 2) "After : ", ~strtool$, e$
Sample output.
Before: Ø12 R0,2 *60 ISCAR After : 12 R0,2 *60 ISCAR
- 3
-
Change fs2 to fmt.
-
1 hour ago, Dstan said:
Yeah I forgot to say I initialized “nos” above in the code by inserting “nos :0” I also tried formatting without the dollar sign and got the same error. I also tried doing it the way it was suggested 2 posts up and still got errors when posting.
Remove that line, you initialized nos when you set it equal to mi5$
-
Remove the dollar sign from the nos variable in the format statement.
-
1 hour ago, M.Bluedorn said:
Hello all. This is my first posting but I've been gleaming knowledge from this forum for quite some time. So a belated thank you is due. What I'm trying to do is grab and store my POCO grab position which is param 13212, and then use that number in basically a comment at the beginning of the program. I've tried several different combinations of strategies I've learned from the MP Post Documentation and cannot get it to post anything other than the dreaded '-9999.' Any help would be greatly appreciated.
Part handling operations don't have tool change lines. The lack of a tool change means that opinfo doesn't 'see' part handling operations in it's offset(default) mode. This means that you need to read the operation stream to look at all the operations.
If you have questions about this I recommend you contact your reseller or post on CNC Software's forum.
- 1
-
8 hours ago, @Mastercam said:
\bM([1-9][0-9][1-9]|[1-9][1-9][0-9]|[2-9][0-9][0-9])\b { Current range is 101-999}
Hi,
How i can increase the range to 1000-1099
Regex Programming Language-
1. Python
2.Java
3. Javascript
4.PHP
5.c/c++
Which Programming Language is used to Creating regex for Mastercam ?
The following regex will match M1000 - M1099
\bM10[0-9][0-9]\b
Here is a link to it being checked against common M-codes
As far as what language is used; in this case it probably doesn't matter. They all should support what you are trying to do. One difference I'm aware of is the the C++ standard library regex implementation doesn't support lookbehind. I think this goes for javascript also, but google will have a better answer if you care to get into the minutiae.
- 1
-
Shot in the dark. You have an arc format issue; have you tried calling G91.1?
Aside from that it sounds like you're asking for a post; have you talked to your local reseller?
wrapping a flat hole pattern to a cylinder
in Industrial Forum
Posted
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?