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:

Recommended Posts

I have a problem when mirroring geometry in C#, MX9.

The graphics change and appear mirrored, but any operation or analysis uses the original location.

var allGeometry = SearchManager.GetGeometry();

foreach (var geo in allGeometry)
{
   geo.Mirror(new Line3D(new Point3D(0, 0, 0), new Point3D(1, 0, 0)), SearchManager.GetSystemView(Mastercam.IO.Types.GraphicsViewType.Top));
   geo.Commit();
}

post-61480-0-96692600-1448994860_thumb.png

 

And after mirror:

 

post-61480-0-36031600-1448994865_thumb.png

 

How does one properly mirror geometry?

Link to comment
Share on other sites

There appears to be a defect with the Mirror member method in the Geometry class.
The Geometry.Mirror and Geometry.Rotate methods can take a lot of time if you have hundreds of entities.
A faster way (that also works!) is to use the XForm methods in GeometryManipulationManager -> 

/// <summary> Mirror all geometry. </summary>
///
/// <returns> Success / Failure status. </returns>
private bool MirrorAll()
  {
  // The GeometryManipulationManager XForm methods work on the 'selected' geometry.
  Mastercam.IO.SelectionManager.SelectAllGeometry();

  var line = new Line3D(new Point3D(0, 0, 0), new Point3D(1, 0, 0));
  var view = SearchManager.GetSystemView(Mastercam.IO.Types.GraphicsViewType.Top);
  var result = Mastercam.GeometryUtility.GeometryManipulationManager.MirrorGeometry(line, view, false);

  if (result)
    {
    // If we need to manipulate these geometry items further (as NET-Hook Geometry objects),
    // we can retrieve the Result of the last XForm operation ->
    var xFormResultGeometry = Mastercam.Support.SearchManager.GetResultGeometry();
    // Do something with this geometry?
    }

  return result;
  }
Link to comment
Share on other sites

In case anyone else runs into this, here's a C# NET-Hook function that mirrors specific geometry with GeometryManipulationManager while retaining user selections.

public static void mirrorGeometry(Geometry[] geometry)
        {
            var line = new Line3D(new Point3D(0, 0, 0), new Point3D(1, 0, 0));
            var view = SearchManager.GetSystemView(Mastercam.IO.Types.GraphicsViewType.Top);
            var selectedGeometry = SearchManager.GetSelectedGeometry();

            SelectionManager.UnselectAllGeometry();

            foreach (var geo in geometry)
            {
                geo.Selected = true;
                geo.Commit();
            }

            Mastercam.GeometryUtility.GeometryManipulationManager.MirrorGeometry(line, view, false);

            SelectionManager.UnselectAllGeometry();

            foreach (var geo in selectedGeometry)
            {
                geo.Retrieve();
                geo.Selected = true;
                geo.Commit();
            }

            GraphicsManager.ClearColors(new GroupSelectionMask(true));
            GraphicsManager.Repaint(true);
        }
  • Like 1
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...