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

Hi,

I am new to Mastercam NetHook Development.

I am trying to get a 3d-point (x,y,z) of the Solid Geometry, but I am not able to find any function for that. 

I tried the "BasePoint" function, but it always gives (x,y,z ) points as (0,0,0), though my geometry is not at 0.

Which function is there to get the exact x,y,z points? please help..

Link to comment
Share on other sites

Hi there,

I have been trying the same thing on a door panel which is an extruded box or should I call it a block with handle holes in it. Part thickness is 16mm laying flat on the xy plane. Now I want to move it to the origin using a script. I am not able to pick a base point on the bottom face of the part. Please guide if possible.

Link to comment
Share on other sites

If it is a Simple (primitive) type Solid: Cylinder, Block, Sphere, Cone, or Torus, it will have a BasePoint.
If it was not created using one of the above methods, it does not have a real BasePoint and you'll always get 0,0,0 if you ask for the BasePoint.

Create some Solids that are of the "simple" type and some that are not. (e.g. Extruded from a Chain)
This code will report some info about the geometries you select.

namespace GetGeometryAddIn
{
    using Mastercam.App.Types;
    using Mastercam.Database;
    using Mastercam.IO;
    using Mastercam.Database.Types;
    using Mastercam.Solids;
    using System.Windows.Forms;

    public class GetGeometry : Mastercam.App.NetHook3App
    {
        /// <summary> Displays some type data about the Geometry object. </summary>
        ///
        /// <remarks> If we want "type specific details" about it, we need to cast it to its specific type. If you just need
        ///           the Level #, Color#, etc., those are available and the "base" Geometry level. </remarks>
        ///
        /// <param name="geometry">     The geometry object to be processed. </param>
        /// <param name="moveToOrigin"> (Optional) True to move to the origin, only if a "simple" Solid. </param>
        private void ShowEntityData(Geometry geometry, bool moveToOrigin = false)
        {
            if (geometry != null)
            {
                var msg = string.Empty;

                // Cast it to its specific type...
                if (geometry is Mastercam.BasicGeometry.PointGeometry)
                    { msg = "It is a Point!"; }
                else if (geometry is Mastercam.Curves.LineGeometry)
                    { msg = "It is a Line!"; }
                else if (geometry is Mastercam.Curves.ArcGeometry)
                    { msg = "It is an Arc!"; }
                else if (geometry is SurfaceGeometry)
                {
                    // Cast it to a SurfaceGeometry type object
                    var surf = (SurfaceGeometry)geometry;
                    var isReversed = surf.IsNormalReversed; // type specific property
                    msg = surf is Mastercam.Surfaces.TrimmedSurface
                           ? "It is a Trimmed Surface!"
                           : "It is a Surface!";
                }
                else if (geometry is SolidGeometry solid) // Cast it to a SolidGeometry type object
                {
                    if (solid is BlockSolid)
                        { msg = $"It is a primitive 'Block' solid! - Base: {solid.BasePoint}"; }
                    else if (solid is SphereSolid)
                        { msg = $"It is a primitive 'Sphere' solid! - Base: {solid.BasePoint}"; }
                    else if (solid is ConeSolid)
                        { msg = $"It is a primitive 'Cone' solid! - Base: {solid.BasePoint}"; }
                        else if (solid is TorusSolid)
                        { msg = $"It is a primitive 'Torus' solid! - Base: {solid.BasePoint}"; }
                    else if (solid is CylinderSolid)
                        { msg = $"It is a primitive 'Cylinder' solid! - Base: {solid.BasePoint}"; }
                    else
                        { msg = $"It is a Solid! - Base: {solid.BasePoint}"; }

                    if (moveToOrigin)
                    {
                        solid.BasePoint = new Mastercam.Math.Point3D();
                        solid.Commit();
                    }
                }

                // For non-specific type properties, we don't need to cast the Geometry object.
                var level = geometry.Level;
                var color = geometry.Color;
                msg += "\n" + string.Format($"It is on Level#:{level} and is Color#:{color}");
                MessageBox.Show(msg, "Entity Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        public override MCamReturn Run(int param)
        {
            GeometryMask geomMask = new GeometryMask(true);
            geomMask.xlines = false;
            geomMask.PMeshes = false;
            geomMask.PSplines = false;
            var geom = SelectionManager.AskForGeometry("Select a Geometry item", geomMask);
            ShowEntityData(geom);

            return MCamReturn.NoErrors;
        }
    }
}


 

  • Like 1
Link to comment
Share on other sites
On 4/28/2021 at 2:07 AM, Roger Martin from CNC Software said:

If it is a Simple (primitive) type Solid: Cylinder, Block, Sphere, Cone, or Torus, it will have a BasePoint.
If it was not created using one of the above methods, it does not have a real BasePoint and you'll always get 0,0,0 if you ask for the BasePoint.

Create some Solids that are of the "simple" type and some that are not. (e.g. Extruded from a Chain)
This code will report some info about the geometries you select.


namespace GetGeometryAddIn
{
    using Mastercam.App.Types;
    using Mastercam.Database;
    using Mastercam.IO;
    using Mastercam.Database.Types;
    using Mastercam.Solids;
    using System.Windows.Forms;

    public class GetGeometry : Mastercam.App.NetHook3App
    {
        /// <summary> Displays some type data about the Geometry object. </summary>
        ///
        /// <remarks> If we want "type specific details" about it, we need to cast it to its specific type. If you just need
        ///           the Level #, Color#, etc., those are available and the "base" Geometry level. </remarks>
        ///
        /// <param name="geometry">     The geometry object to be processed. </param>
        /// <param name="moveToOrigin"> (Optional) True to move to the origin, only if a "simple" Solid. </param>
        private void ShowEntityData(Geometry geometry, bool moveToOrigin = false)
        {
            if (geometry != null)
            {
                var msg = string.Empty;

                // Cast it to its specific type...
                if (geometry is Mastercam.BasicGeometry.PointGeometry)
                    { msg = "It is a Point!"; }
                else if (geometry is Mastercam.Curves.LineGeometry)
                    { msg = "It is a Line!"; }
                else if (geometry is Mastercam.Curves.ArcGeometry)
                    { msg = "It is an Arc!"; }
                else if (geometry is SurfaceGeometry)
                {
                    // Cast it to a SurfaceGeometry type object
                    var surf = (SurfaceGeometry)geometry;
                    var isReversed = surf.IsNormalReversed; // type specific property
                    msg = surf is Mastercam.Surfaces.TrimmedSurface
                           ? "It is a Trimmed Surface!"
                           : "It is a Surface!";
                }
                else if (geometry is SolidGeometry solid) // Cast it to a SolidGeometry type object
                {
                    if (solid is BlockSolid)
                        { msg = $"It is a primitive 'Block' solid! - Base: {solid.BasePoint}"; }
                    else if (solid is SphereSolid)
                        { msg = $"It is a primitive 'Sphere' solid! - Base: {solid.BasePoint}"; }
                    else if (solid is ConeSolid)
                        { msg = $"It is a primitive 'Cone' solid! - Base: {solid.BasePoint}"; }
                        else if (solid is TorusSolid)
                        { msg = $"It is a primitive 'Torus' solid! - Base: {solid.BasePoint}"; }
                    else if (solid is CylinderSolid)
                        { msg = $"It is a primitive 'Cylinder' solid! - Base: {solid.BasePoint}"; }
                    else
                        { msg = $"It is a Solid! - Base: {solid.BasePoint}"; }

                    if (moveToOrigin)
                    {
                        solid.BasePoint = new Mastercam.Math.Point3D();
                        solid.Commit();
                    }
                }

                // For non-specific type properties, we don't need to cast the Geometry object.
                var level = geometry.Level;
                var color = geometry.Color;
                msg += "\n" + string.Format($"It is on Level#:{level} and is Color#:{color}");
                MessageBox.Show(msg, "Entity Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        public override MCamReturn Run(int param)
        {
            GeometryMask geomMask = new GeometryMask(true);
            geomMask.xlines = false;
            geomMask.PMeshes = false;
            geomMask.PSplines = false;
            var geom = SelectionManager.AskForGeometry("Select a Geometry item", geomMask);
            ShowEntityData(geom);

            return MCamReturn.NoErrors;
        }
    }
}


 

Thanks Roger, I'll give it a try.!! will get back to you if I face any issue..

Link to comment
Share on other sites
On 4/29/2021 at 7:01 PM, AnshuP said:

Thanks Roger, I'll give it a try.!! will get back to you if I face any issue..

Hey Roger,

If let's say that geometry isn't created with any of the given method and as u said Based point will always be 0,0,0 for such geometry.

In that case, how can I get the geometry points? 

Link to comment
Share on other sites
1 hour ago, Roger Martin from CNC Software said:

If the geometry in question is a  "non-primitive" Solid (i.e. created doing an extrude of some chain), what would be the points on this? 

It does not have any defined "base" point. It is a Solid Body with Faces and Edges.

 

So, when I ask user to select the point on the geometry, for eg :

 

PointMask endPoint = Mastercam.IO.Types.PointMask.EndPoint;

Point3D p1 = new Point3D ();

bool v = SelectionManager.AskForPoint("Select point", endPoint, ref p1);

I get the values in p1.x, p1.y and p1.z.

Similarly, I want those points without asking USER to select them...that way I am not able to find.

I don't wanna askForPoint, I want to get all the points directly..What would be the way here?

Link to comment
Share on other sites
9 minutes ago, Roger Martin from CNC Software said:

See the SearchManager.GetGeometry methods in the API

Looked at all the methods, none of them is giving any reference to points...

Do u see any method which gives me the ref..?

Link to comment
Share on other sites
1 hour ago, Roger Martin from CNC Software said:

See the SearchManager.GetGeometry methods in the API

Basically, I am trying to automate the steps I am doing manually as attached in the video.

If I would've got the BasePoint, then it would have been easy for me to MoveToOrigin. But as it doesn't have BasePoint, it is getting difficult for me to get the points.

And I can't even give hardcoded values for Points in MoveToOrigin API, because those points might change for another geometry.

Any help you can do here..?

Link to comment
Share on other sites

With SearchManger you can retrieve point "entities".
What you show in the video is not finding/selecting point entities.
Using Dynamic you are snapping to a location (is this case the end of an edge) and then telling Mastercam to make (move) the location to the origin.
You cannot do this with a NET-Hook type add-in unless you have a From point position and here there is no point entities to find.
With a C-Hook add-in you could create the edges of the Solid and then go through the endpoints of each edge.
You would need to have some criteria to know which edge endpoint you want to use.
(i.e. Always using the upper-left in XY endpoint location?)
What happens if the Solid is not a rectangular shaped, but some arbitrary shaped solid?
(i.e. You have a free-form chained output that was using to created an extruded solid.)
 

Link to comment
Share on other sites
19 hours ago, Roger Martin from CNC Software said:

With SearchManger you can retrieve point "entities".
What you show in the video is not finding/selecting point entities.
Using Dynamic you are snapping to a location (is this case the end of an edge) and then telling Mastercam to make (move) the location to the origin.
You cannot do this with a NET-Hook type add-in unless you have a From point position and here there is no point entities to find.
With a C-Hook add-in you could create the edges of the Solid and then go through the endpoints of each edge.
You would need to have some criteria to know which edge endpoint you want to use.
(i.e. Always using the upper-left in XY endpoint location?)
What happens if the Solid is not a rectangular shaped, but some arbitrary shaped solid?
(i.e. You have a free-form chained output that was using to created an extruded solid.)
 

I am not seeing any API in searchManager to retrieve point "entities". 

Can you please give an example if you have or direct me to the API..?

Link to comment
Share on other sites

NET-Hook API Reference Guide (Std. customer log-in required.)

SearchManager is in the Mastercam.Support namespace.

And it has methods to find/retrieve geometry entities.

SearchManager.GetGeometry

There are 6 versions of the GetGeometry method.

using Mastercam.BasicGeometry;
using Mastercam.Database;
using Mastercam.Database.Types;
using Mastercam.Support;

public void DemoGetAllPoints()
{
    GeometryMask PointMask = new GeometryMask(false);
    PointMask.Points = true; // Just getting Point Entities
    Geometry[] FoundPoints = SearchManager.GetGeometry(PointMask);
    // GetGeometry can retrieve multiple types of geometry objects.
    // Thus the data we get is a list (array) of generic “Geometry” objects.
    // If we need to access the details of a specific type of geometry,
    // we need to cast it to that specific type.
    foreach (var point in FoundPoints)
    {
        // We know it is a point, so the cast to PointGeometry will work.
        var pt = (PointGeometry)point;
        // Do something with this PointGeometry object.
        var x = pt.Data.x;
        var y = pt.Data.y;
        var z = pt.Data.z;
    }
}

 

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