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:

Line Geometry Parameters


Recommended Posts

I'm interested in getting the coordinates of the two ends of a line, and then moving those points (making the line shorter). I'm lost on where to begin.

Do I select the geometry, pull the parameters and then change them?

Thought I would be clever and display the coordinates in a MessageBox but that requires a string.

How do you get the 3D position of the ends of a chain?

 

            var selectedChain = ChainManager.GetOneChain("Select a Chain");

            var Endpoint1 = CurveGeomEndpointFlag.Endpoint2;
            var Endpoint2 = CurveGeomEndpointFlag.Endpoint2;

            System.Windows.Forms.MessageBox.Show(Endpoint1);
            System.Windows.Forms.MessageBox.Show(Endpoint2);

 

Link to comment
Share on other sites

Altering a line -

        /// <summary> Shows the line end points. </summary>
        /// 
        /// <remarks> Using a custom format. </remarks></remarks>
        /// 
        /// <param name="line"> The line. </param>
        private void ShowLineEndPoints(Mastercam.Curves.LineGeometry line)
        {
            MessageBox.Show($"ep1 > X:{line.EndPoint1.x:N4}  Y:{line.EndPoint1.y:N4}  Z:{line.EndPoint1.z:N4}{Environment.NewLine}ep2 > X:{line.EndPoint2.x:N4}  Y:{line.EndPoint2.y:N4}  Z:{line.EndPoint2.z:N4}",
                "Line Endpoints", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        /// <summary> Shows the line data. </summary>
        ///
        /// <remarks> Using the ToString() method in the LineGeometry class. </remarks></remarks>
        ///
        /// <param name="line"> The line. </param>
        private void ShowLineData(Mastercam.Curves.LineGeometry line)
        {
            MessageBox.Show(line.ToString(), "Line Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        /// <summary> Demo altering the endpoint of a line. </summary>
        private void DemoAlterLine()
        {
            var geomask = new Mastercam.Database.Types.GeometryMask
            {
                Lines = true
            };

            var geo = Mastercam.IO.SelectionManager.AskForGeometry("Select a line", geomask);
            if (geo != null)
            {
                // Downcast the geometry object to a LineGeometry so we can access its "line specific" properties.
                var line = (Mastercam.Curves.LineGeometry)geo;
                ShowLineData(line);
                // Alter endpoint #2
                line.Data.Point2.x += 1.1;
                line.Data.Point2.y += 0.5;
                line.Commit();
                Mastercam.IO.GraphicsManager.Repaint(true);
                ShowLineEndPoints(line);

            }
        }

 

  • Thanks 1
Link to comment
Share on other sites

Getting “details” about a Chain using the NET-Hook API.
You can get the geometry in a Chain, but you do not know if the first or last entity has been “flipped”.
You need that to know the true endpoint.
This functionality is available in a C-Hook add-in (using the C-Hook API).
There is a story in our backlog to add this to the NET-Hook API.
What version of Mastercam are you running?
For now…. You can use a “interop” DLL that will gather up more *details about a Chain.
You add a reference to your NET-Hook project (just like you do for the NETHook3_0.dll) to this ChainDaraInterop.dll

*Chain detail properties include:
GetFirstEndPoint, GetLastEndPoint, GetFirstEntityID, GetLastEntityID, IsFirstEnttyFlipped, IsLastEntityFlipped.

If you email us -> [email protected] with your company contact information and we can see about getting you this “ChainDataInterop” project.

Link to comment
Share on other sites

That worked out great! It is a little slow at the end, but that's okay.

The popup messages helped with troubleshooting.

            void DemoAlterLine()
            {
                var geomask = new Mastercam.Database.Types.GeometryMask{
                    Lines = true
                };
                var geo = SearchManager.GetGeometry(geomask);
                if (geo != null) {
                    foreach (var singleGeo in geo) {
                        var line = (Mastercam.Curves.LineGeometry)singleGeo;
                        if (line.Data.Point1.x == line.Data.Point2.x){
                            if (line.Data.Point1.y >= line.Data.Point2.y){
                                line.Data.Point1.y += -1;
                                line.Data.Point2.y += +1;
                                line.Selected = false;
                            };
                            if (line.Data.Point1.y <= line.Data.Point2.y){
                                line.Data.Point1.y += +1;
                                line.Data.Point2.y += -1;
                                line.Selected = false;
                            };
                        };
                        if (line.Data.Point1.y == line.Data.Point2.y){
                            if (line.Data.Point1.x >= line.Data.Point2.x){
                                line.Data.Point1.x += -1;
                                line.Data.Point2.x += +1;
                                line.Selected = false;
                            };
                            if (line.Data.Point1.x <= line.Data.Point2.x){
                                line.Data.Point1.x += +1;
                                line.Data.Point2.x += -1;
                                line.Selected = false;
                            };
                        };
                        line.Commit();
                        Mastercam.IO.GraphicsManager.Repaint(true);
                    }
                }
            }
            DemoAlterLine();

 

Roger,

Why would it matter if the geometry has been "flipped"? Are you referring to the direction of a chain?

When would I use that DLL?

Thanks,

Jeremy

Link to comment
Share on other sites

Move this line out so that it is only called once after the loop that processes the geometry.
>Mastercam.IO.GraphicsManager.Repaint(true);
The 'true' makes it do a "full rebuild" of the graphics and that can be (time) expensive depending on the geometry in the part file.

>Why would it matter if the geometry has been "flipped"? Are you referring to the direction of a chain?
Not the direction of the chain itself, but the “direction” of the entities at the ends of the chain.
Think of a chain that ends with a line.
The endpoint #2 of that defined geometry line may not be the same position as the end of the chain it is in. 
It is possible that the end of the chains is at the endpoint #1 position of the line.
When that happens (we cannot change the line geometry entity itself), the Chain Entity (which "points" to that line) is marked as “flipped”, 
so the system can know travelling down that line (in the chain) actually goes from endpoint #2 -> endpoint #1 of that line.

The ChainDataInterop mentioned is a C++/CLI project. This type of "hybrid" project allows for creating code that uses functionality in the C-Hook SDK that is not in the NET-Hook API.
It creates a .NET Assembly that your NET-Hook project can use just like it does for the std. NET-Hook API.
You would add a Reference in your NET-Hook project to this ChainDataInterop.dll, just like you do for the NET-Hook API when you add the NETook3_0.DLL in your project.
 

Link to comment
Share on other sites
  • 3 weeks later...

I'm having a weird result when I offset my chains ( I made sure everything is in the same CW direction) and it only happens in 2 places even though 2 of the same exact shapes turned out to be correct. The top left shape and the bottom right shape are correct but the top right shape and bottom left shape are wrong, and only in that one radius.

Is this an example of a 'flipped' chain?

 

ExampleFull.png

ExampleRight.png

ExampleWrong.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

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