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:

Geometry ID #s


Recommended Posts

I added some geometry ID numbers to a list, but I'm not seeing a way to retrieve the information of the geometry by referencing their ID #.

I thought this would get the first ID# from the list, and then get it's geometry. It gets both ends of a line, alternating between two lines. (Want to draw a line between points 1&3 and 2&4)

Example: 

            void connectLines(){
                var set = 0;
                foreach (var Line in CreaseID){
                    var geomask = new Mastercam.Database.Types.GeometryMask
                    {
                        Lines = true
                    };

                    if (set == 0){
                        var creaseGeo = SearchManager.GetGeometry(geomask);
                        foreach (var singleGeo in creaseGeo){
                            var line = (LineGeometry)singleGeo;
                            creaseX1 = line.EndPoint1.x;
                            creaseX2 = line.EndPoint2.x;
                            creaseY1 = line.EndPoint1.y;
                            creaseY2 = line.EndPoint2.y;
                            set = 1;
                        }

                    }
                    if (set == 1){
                        var creaseGeo = SearchManager.GetGeometry(geomask);
                        foreach (var singleGeo in creaseGeo){
                            var line = (LineGeometry)singleGeo;
                            creaseX3 = line.EndPoint1.x;
                            creaseX4 = line.EndPoint2.x;
                            creaseY3 = line.EndPoint1.y;
                            creaseY4 = line.EndPoint2.y;
                            set = 0;
                            CreateLine();
                        }

                    }
                }
            }

 

Link to comment
Share on other sites
17 hours ago, JKLINE said:

I'm not seeing a way to retrieve the information of the geometry by referencing their ID #.

 var geom = Mastercam.Database.Geometry.RetrieveEntity(id);

        /// <summary> Alter the color and or level of the lines. </summary>
        ///
        /// <param name="geoIDs"> The list of geometry IDs to process. </param>
        /// <param name="color">  (Optional) The color to set the entity to (0 = no change). </param>
        /// <param name="level">  (Optional) The level to set the entity to (0 = no change). </param>
        private void AlterLines(List<int> geoIDs, int color = 2, int level = 100)
        {
            if (color <= 0 && level <= 0)
            {
                return; // nothing to do!

            }

            // Retrieve the entities "by their ID"
            foreach (var id in geoIDs)
            {
                var geom = Mastercam.Database.Geometry.RetrieveEntity(id);
                if (color > 0)
                {
                    geom.Color = (color < 255) ? color++ : color = 1;
                }

                if (level > 0)
                {
                    geom.Level = level++;
                }

            geom.Commit();
            }

            Mastercam.IO.LevelsManager.RefreshLevelsManager(); // optional
        }


        /// <summary> Ask the use to select some lines and then gather up
        ///           the IDs of the user selected entities. </summary>
        private void Demo()
        {
            var geomask = new Mastercam.Database.Types.GeometryMask
            {
                Lines = true
            };

            var userSelectedGeometry = Mastercam.IO.SelectionManager.AskForMultipleGeometry("Select lines", geomask);
            if (userSelectedGeometry != null)
            {
                Mastercam.IO.SelectionManager.UnselectAllGeometry(); // optional

                var geoIDs = new List<int>();
                foreach (var entity in userSelectedGeometry)
                {
                    geoIDs.Add(entity.GetEntityID());
                }

                AlterLines(geoIDs);
            }
        }

 

  • Thanks 1
Link to comment
Share on other sites

This worked like a champ. I was getting tripped up by the fact that it stores GetEntityID numbers, example 1490.

I thought it would save that Entity number, but in the list it would be [0] instead of [1490]. 

var GetEntityID()[0] = 1490 instead of pulling the item number from the list at index and then asking for that entity information.

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