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 Error


Recommended Posts

My geometry disappears after the dashed line. 🤷‍♂️

If I run all the methods before the dash line, everything is great.
If I run all the methods after the dash line, everything is great.
If I run all the methods before the dash line, save and exit, then run all the methods after the dash line, everything is great.
If I run all the methods, geometry goes missing and my file becomes corrupt.

Because it works after a reload, that would suggest there is no error in the code.

Perhaps it's a memory leak? There is no memory usage increase while running the NetHook though.

I could separate it into two different files, but I need the data stored in the first half.

 

            translate();
            findIntersectionOfLines();
            findIntersectionOfArcs();
            clearTempLinesAndArcs();
            breakArcsWithPoints();
            selectNewGeo();
            colorCrossovers();
            movePoints();
            seperateGeometry();
            -------------------
            offsetCutchain80();
            offsetCutchain81();
            shortenChains500();
            shortenChains501();

 

Link to comment
Share on other sites
Quote

If I run all the methods, geometry goes missing and my file becomes corrupt.

Corrupt in what way?

If you do Statistics  on the file after the run, are the missing entities included in the count?

If you remove the shortenChain### calls, does that make a difference?

If you do a rebuild graphics after the run, does that make a difference? 

Since I have almost nothing to go on there, I'm reduced to guessing.

 

Link to comment
Share on other sites

The geometry ends up on a different level. 

 

It gets corrupt because there is no geometry on the certain level of activities. That part is completely my fault. 

 

But the moving geometry is odd. Because it only moves if the whole thing is ran. 

I've tried Graphics.clear(true) after each method as well. Also tried a sleep. 

Link to comment
Share on other sites
Quote

Because it only moves if the whole thing is ran.

Break it down...
Create a method that does just the "move" of the geometry.
Work out that process out in isolation of all the 'other' code.
Once you know that it works and how it works, you can concentrate your efforts on the other code in your add-in.

Quote

I've tried Graphics.clear(true) after each method as well.

This is "Clear Color" that clears the Group/Result markings on geometry.
Probably not going to help and maybe *not* want you want. See NOTE below.

Quote

Also tried a sleep. 

No. Just no.

Is this what is happening?
I am restating basically what x4g said here. ->
"If you translate something make sure you call retrieve on the entity if you are holding a list of pointers to the entities,"

Your add-in has selected geometry, then is translates/rotates/moves that geometry using some XForm method.
After the XForm operation are you then still "looking" at the original geometry your add-in holds in a list?

Looking at the docs for:
GeometryManipulationManager.TranslateGeometry Method
GeometryManipulationManager.CopySelectedGeometryToLevel Method
Etc.
->
NOTE!
Any Geometry objects that get altered will NOT be reflected in that entity's data "on the NET-Hook side" if that entity's data is being held in a NET-Hook Geometry object!
You can use GetResultGeometry() to retrieve the result of the XForm operation.

 

Link to comment
Share on other sites

That's where I keep getting lost.

At no point do I tell it anything about level 81, but the geometry on level 81 gets moved.

The geometry on level 75 gets duplicated in translate() and those duplicates are deleted in clearTempLinesAndArcs(). The geometry on level 75 is then broken in breakArcsWithPoints(). The geometry on level 75 is then colored in colorCrossovers() and then half of the geometry is moved to level 80 and the other half is moved to level 81 in seperateGeometry().

After all of this is done, there are no errors but when I run offsetCutChain80() it completes the void but the geometry on level 81 gets moved. offsetCutChain80() offsets the geometry on level 80, not on level 81.

And when I run offsetCutChain81() instead of offsetCutChain80(), the geometry on level 80 gets moved 🤦‍♂️

59 minutes ago, Roger Martin from CNC Software said:

Any Geometry objects that get altered will NOT be reflected in that entity's data "on the NET-Hook side" if that entity's data is being held in a NET-Hook Geometry object!

I believe this is the root of all my issues 😅 How do you reset/update the geometry?

                var levels = LevelsManager.GetLevelNumbersWithGeometry();
                foreach (var i in levels){
                    var geometryFound = SearchManager.GetGeometry(i);
                    foreach (var t in geometryFound){
                        t.Commit();
                        t.Retrieve();
                    }
                    GraphicsManager.Repaint(true);
                }

I've tried running this before offsetCutChain80()

Link to comment
Share on other sites

if you change something in the geometry and want to update the entity, you would change a class members value then commit, after you can dipose of the list and translate it or whatever you want, here is an example where you select the entities on a level and move them up an inch on the y axis in top plane, 

if the geomtry is not present, you can throw an error then catch it and report it to the user without too much typing

try
{
//ask for unselection of all geometry
Mastercam.IO.SelectionManager.UnselectAllGeometry();
//repaint
Mastercam.IO.GraphicsManager.Repaint(false,true);//force rebuild
//ask for a list of geometry
var geometryFound = SearchManager.GetGeometry(100);
//handle any errors retrieving geometry and report them to the user
if(geometryFound == null || geometryFound.Length == 0)
{
    throw new System.Exception("Error Finding Geometry!");
}
else
{
    var views = Mastercam.IO.ViewManager.GetAllViews(false);
    if(views == null)
    {
        throw new System.Exception("Error Finding Views!");
    }    
    else
    {
        foreach (var t in geometryFound)
        {
        //set the entity as selected
        t.Selected = true;
        //commit the changes to the database
        t.Commit();
        }
        //invalidate the list of geometry
        geometryFound = null;
        //ask to reclaim the memory from the list
        System.GC.Collect();
        //repaint the scren
        Mastercam.IO.GraphicsManager.Repaint(false,true);//force rebuild
        Mastercam.GeometryUtility.GeometryManipulationManager.TranslateGeometry(
        new Mastercam.Math.Point3D(0.0,0.0,0.0),//from point    
        new Mastercam.Math.Point3D(0.0,1.0,0.0),//to point
        views[0],views[0],false);
        
        views = null;
        System.GC.Collect();
    }

}
}
catch(System.Exception e)
{
    
    Mastercam.IO.EventManager.LogEvent(
    Mastercam.IO.Types.MessageSeverityType.ErrorMessage,
    "Error Manager",e.Message);
}

 

 

 

Link to comment
Share on other sites
        //invalidate the list of geometry
        geometryFound = null;
        //ask to reclaim the memory from the list
        System.GC.Collect();

These are new terms for me, and I appreciate the knowledge :D

I've tried this in different areas of the program to no avail.

https://github.com/UberGamz/CustomNethook

MCAM file included. -- if ran AS IS, geometry from level 81 gets moved to level 501.

Link to comment
Share on other sites
24 minutes ago, JKLINE said:
        //invalidate the list of geometry
        geometryFound = null;
        //ask to reclaim the memory from the list
        System.GC.Collect();

These are new terms for me, and I appreciate the knowledge :D

I've tried this in different areas of the program to no avail.

https://github.com/UberGamz/CustomNethook

MCAM file included. -- if ran AS IS, geometry from level 81 gets moved to level 501.

You don't need to call Gc.Collect, the garbage collector should take care of the memory when u set it to null, 

it is just a polite way to ask the garbage collector to release the memory,

 

I don't see that the function that youi wrote called commit() actually does anything

 

 

 

Here you are iterating through a list and in the first loop invalidating the list

 

 foreach (var geometry in selectedGeometry)
                {
                    if (geometry.Color == 10)
                    {
                        geometry.Level = 80;
                        geometry.Selected = false;
                        geometry.Commit();
                    }
                    if (geometry.Color == 11)
                    {
                        geometry.Level = 81;
                        geometry.Selected = false;
                        geometry.Commit();
                    }
                    //invalidate the list of geometry
                    selectedGeometry = null;//ERROR!!!!!!!!!!!!!
                    //ask to reclaim the memory from the list
                    System.GC.Collect();//ERROR!!!!!!!!!!!!!
                    //repaint the scren
                    Mastercam.IO.GraphicsManager.Repaint(true);//force rebuild
                }

 

This is a repaint,

GraphicsManager.Repaint(true);

This is a rebuild, you could try to use this instead, your are flipping the select bit over and over,

this can cause selection to bug rebuilding should force things to work even

GraphicsManager.Repaint(false,true);

Link to comment
Share on other sites
29 minutes ago, x4g said:

GraphicsManager.Repaint(false,true);

I've tried that, but there's an error. "no overload for method 'repaint' takes 2 arguments"

That second overload was added in the 2023 package. 😕

 

36 minutes ago, x4g said:

Here you are iterating through a list and in the first loop invalidating the list

 

I've changed this and level 81 still went missing 😅

If you ommit offSetCutChain80() and only run those first few it completes level 80 and 81. 🤷‍♂️

Link to comment
Share on other sites

Below is an image of the end-result Level Manager I get.
I see 49 entities on Level #80 and 49 entities on Level #81.
So where is “geometry on level 81 gets moved” ?

image.png

--------------------------------

Quote

How do you reset/update the geometry?

After you have done an XForm operation the resulting entities are marked by Mastercam as a “result” group.
You should be able to retrieve those entities that are a “result of the last Xform” doing this.
var resultGeom = SearchManager.GetResultGeometry();
-------------------------

Get rid of the lines setting an array = null
e.g. The last 4 lines of the translate method -
// NOT needed
tempSelectedGeometry1Result = null
tempSelectedGeometry1 = null;
tempSelectedGeometry2Result = null;
tempSelectedGeometry2 = null;


And other locations in the code -
selectedGeometry = null; // NOT needed
//ask to reclaim the memory from the list
System.GC.Collect(); // NOT needed

Will these cause problems? Probably not, but the are not needed and just add "noise" to the code.

Edited by Roger Martin from CNC Software
Link to comment
Share on other sites

Running 

            translate();
            findIntersectionOfLines();
            findIntersectionOfArcs();
            clearTempLinesAndArcs();
            breakArcsWithPoints();
            selectNewGeo();
            colorCrossovers();
            movePoints();
            seperateGeometry();

Results in

 

Untitled1.png

--------------------------------------------------------------------------------------

Running

            translate();
            findIntersectionOfLines();
            findIntersectionOfArcs();
            clearTempLinesAndArcs();
            breakArcsWithPoints();
            selectNewGeo();
            colorCrossovers();
            movePoints();
            seperateGeometry();
            offsetCutchain80();

Results in (level 81 got moved to level 501)

 

Untitled2.png

--------------------------------------------------------------------------------------

Running

            translate();
            findIntersectionOfLines();
            findIntersectionOfArcs();
            clearTempLinesAndArcs();
            breakArcsWithPoints();
            selectNewGeo();
            colorCrossovers();
            movePoints();
            seperateGeometry();
            offsetCutchain81();

Results in (level 80 got moved to level 501)

 

Untitled3.png

--------------------------------------------------------------------------------------

15 hours ago, Roger Martin from CNC Software said:

Below is an image of the end-result Level Manager I get.
I see 49 entities on Level #80 and 49 entities on Level #81.
So where is “geometry on level 81 gets moved” ?

This is not the result you are having Roger?

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

After you have done an XForm operation the resulting entities are marked by Mastercam as a “result” group.
You should be able to retrieve those entities that are a “result of the last Xform” doing this.
var resultGeom = SearchManager.GetResultGeometry();

This has been what I have been doing

                            var cutResultGeometry = SearchManager.GetResultGeometry();
                            foreach (var entity in cutResultGeometry)
                            {
                                entity.Color = 11;
                                entity.Selected = true;
                                entity.Commit();
                            }

 

Link to comment
Share on other sites
3 minutes ago, x4g said:

Can you share the ChainData project with me?

Are you referring to the ChainData API kit? I'm not sure if I'm allowed to give it out 😅 I sent SDK@Mastercam an email requesting that and the surfaces API kit.

If Roger says I can then I'll email it over to you.

I haven't gotten the surface kit yet though.

Link to comment
Share on other sites
6 minutes ago, JKLINE said:

Are you referring to the ChainData API kit? I'm not sure if I'm allowed to give it out 😅 I sent SDK@Mastercam an email requesting that and the surfaces API kit.

If Roger says I can then I'll email it over to you.

I haven't gotten the surface kit yet though.

That's okay If its's a CNC Software I can email them and see if they will share it,

8 minutes ago, JKLINE said:

 

I haven't gotten the surface kit yet though.

What do you want to do to a surface?

most of the data you can get through the surfaCE union and some simple helpers, well "simple"

Link to comment
Share on other sites

 

Don’t know “why” at this point, but it makes a difference.

In -> offsetCutChain80() 

Original:

GraphicsManager.Repaint(true);
int createdUpperLevel = 500;
int createdLowerLevel = 501;
 

image.png.212f3fdd41f564ee7e7b7239b8cc9fd8.png

Altered:
GraphicsManager.Repaint(false); // or remove this call 
int createdUpperLevel = 500;
int createdLowerLevel = 501;

Result ->
image.png.c37defcc75199656b4d42316702bbf0d.png

Quote

Can you share the ChainData project with me?

Yes, you can share the ChainDataInterop project.

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

Don’t know “why” at this point, but it makes a difference.

 

And to think, I added all that nonsense to prevent such a thing from happening 🤣 It definitely fixed it.

 

4 minutes ago, Roger Martin from CNC Software said:

Also...

It does not appear to make a different in the output in "this" case, but...

// Be careful doing '=' or '!=' comparisons of floating point values.
//if (chain.Area != t.Area) // No
if (Math.Abs(chain.Area - t.Area) < Mastercam.IO.SettingsManager.SystemTolerance)  // Yes, check against some tolerance

You're absolutely right, I've forgotten about that. First I tried the 'equals' method but that didn't work so I switched to calculating the area. Wanting it to offset everything except for the bounding box when selecting the 'area'.

 

--------

Thankfully we've all been using the same resolution or the cursor point wouldn't have worked 🤣

I greatly appreciate the help! This has completed all my tickets I've emailed in except for the last one, asking about converting. (I think it'll just be a matter of refactor/rename/find+replace but I'm a rookie)

22 minutes ago, x4g said:

That's okay If its's a CNC Software I can email them and see if they will share it,

What do you want to do to a surface?

most of the data you can get through the surfaCE union and some simple helpers, well "simple"

I've sent it to your sales email.

As for surfaces, I've asked about creating a draft surface. 98% of what this company does is offset chains (worked my way through that) and then drafting surfaces from those chains. There's an API that might be able to help since there are no Surface Creation tools in the Nethook API kit.

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

And to think, I added all that nonsense to prevent such a thing from happening 🤣 It definitely fixed it.

 

You're absolutely right, I've forgotten about that. First I tried the 'equals' method but that didn't work so I switched to calculating the area. Wanting it to offset everything except for the bounding box when selecting the 'area'.

 

--------

Thankfully we've all been using the same resolution or the cursor point wouldn't have worked 🤣

I greatly appreciate the help! This has completed all my tickets I've emailed in except for the last one, asking about converting. (I think it'll just be a matter of refactor/rename/find+replace but I'm a rookie)

I've sent it to your sales email.

As for surfaces, I've asked about creating a draft surface. 98% of what this company does is offset chains (worked my way through that) and then drafting surfaces from those chains. There's an API that might be able to help since there are no Surface Creation tools in the Nethook API kit.

Are we talking about a flat surface from a chain?

Link to comment
Share on other sites
16 hours ago, x4g said:

Are we talking about a flat surface from a chain?

That's a negative. It's angled at either 10, 15, 20, or 30 degrees at a negative depth.

This here is an example of an end result. White line is the supplied geometry. We offset the green geometry. And then draft a surface down.

Untitled.png

Link to comment
Share on other sites
53 minutes ago, JKLINE said:

I'm not against taking the first steps towards a Chook instead of a NetHook if you can introduce me 😅

Chooks are not cross platform, I would need to know what version of Mastercam and Visual Studio

There are templates for generating a working Chook for Mastercam 2023 on the Visual Studio Marketplace, you just need the appropriate development tools for c++;

 

 

There is a new Mastercam Project Template that will create a chook-InteropDll and c# project like what you are used to, this will make it easier to manage your c++ code

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