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:

CopyAndTranslate


Recommended Posts

I'm feeling pretty dumb about this one.

My code will copy an entity X+0.001 and Y+0.001 but that result will then be moved back down X-0.001 and Y-0.001 instead of the original geometry.

The tooltip says the method does not move the original geometry so I'm confused.

                var freshChain = ChainManager.GetMultipleChains("");
                var origin = new Point3D(0, 0, 0);
                var tempList1 = new List<int>();
                var tempList2 = new List<int>();
                foreach (var chain in freshChain) {
                    var freshGeo = ChainManager.GetGeometryInChain(chain);
                    foreach (var entity in freshGeo){
                        var changePoint1 = new Point3D(0.001,0.001, 0);
                        var changePoint2 = new Point3D(-0.001, -0.001, 0);
                        var tempGeo1 = entity.CopyAndTranslate(origin, changePoint1, new MCView(), new MCView());
                        var tempGeo2 = entity.CopyAndTranslate(origin, changePoint2, new MCView(), new MCView());
                        tempGeo1.Commit();
                        tempGeo2.Commit();
                        tempList1.Add(tempGeo1.GetEntityID());
                        tempList2.Add(tempGeo2.GetEntityID());
                    }
                }

 

Link to comment
Share on other sites
On 1/5/2023 at 10:29 AM, JKLINE said:

I'm feeling pretty dumb about this one.

My code will copy an entity X+0.001 and Y+0.001 but that result will then be moved back down X-0.001 and Y-0.001 instead of the original geometry.

The tooltip says the method does not move the original geometry so I'm confused.

                var freshChain = ChainManager.GetMultipleChains("");
                var origin = new Point3D(0, 0, 0);
                var tempList1 = new List<int>();
                var tempList2 = new List<int>();
                foreach (var chain in freshChain) {
                    var freshGeo = ChainManager.GetGeometryInChain(chain);
                    foreach (var entity in freshGeo){
                        var changePoint1 = new Point3D(0.001,0.001, 0);
                        var changePoint2 = new Point3D(-0.001, -0.001, 0);
                        var tempGeo1 = entity.CopyAndTranslate(origin, changePoint1, new MCView(), new MCView());
                        var tempGeo2 = entity.CopyAndTranslate(origin, changePoint2, new MCView(), new MCView());
                        tempGeo1.Commit();
                        tempGeo2.Commit();
                        tempList1.Add(tempGeo1.GetEntityID());
                        tempList2.Add(tempGeo2.GetEntityID());
                    }
                }

 

I don't think you should be calling Commit()

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

CopyAndTranslate sends back Geometry Entities, so I thought I'd have to commit them to the database. I'll give that a try later tonight. 

 

Thanks

oh i see thing , you are passing a new McView as a parameter, use the active contruction plane or top plane instead

Link to comment
Share on other sites

this works,

 var freshChain = ChainManager.GetMultipleChains("");

                var origin = new Point3D(0, 0, 0);
 
                var tempList1 = new List<int>();
                var tempList2 = new List<int>();
                foreach (var chain in freshChain) {
                    var freshGeo = ChainManager.GetGeometryInChain(chain);
                    
                    foreach (var entity in freshGeo){
                        var entityref2 = entity;
                        var changePoint2 = new Point3D(-0.001, -0.001, 0);
                        var tempGeo2 = entityref2.CopyAndTranslate(origin, changePoint2,  ViewManager.CPlane,  ViewManager.CPlane);
                      
                        tempGeo2.Commit();
                        tempList2.Add(tempGeo2.GetEntityID());
                    }
                    var freshGeo2 = ChainManager.GetGeometryInChain(chain);
                    
                    foreach (var entity in freshGeo2){
                        var entityref1 = entity;
                        var changePoint1 = new Point3D(0.001,0.001, 0);
                        var tempGeo1 = entityref1.CopyAndTranslate(origin, changePoint1,  ViewManager.CPlane,  ViewManager.CPlane);
                        tempGeo1.Commit();
                        tempList1.Add(tempGeo1.GetEntityID());
                    }
                }

the re-use of entity is causing a problem, when you copyandtranslate the entity data is changed to the new entity, so you need to do one translation, then retrieve a new copy of entity from the chain

image.thumb.png.76d6a3f523f486afcf91889b73fda24a.png

Link to comment
Share on other sites

More struggles 🤔

I'm getting the offset correctly, but I'm trying to hold the geo somewhere.

Assuming the entity data is changed to the new entity, resultLineGeo1 should change colors.

The original geometry changes to color 25 and then color 30 even though the spacing of everything is correct 🤦‍♂️

Basically, I want the original geo one color, the chain that's offset 0.010 to be another, and the last chain another color.

foreach (var chain in angleChain)
{
  var resultChain1 = chain.OffsetChain2D(OffsetSideType.Left,0.010,OffsetRollCornerType.None, 0, true, 0.005, true);
  var resultChainGeo1 = ChainManager.GetGeometryInChain(resultChain1);
  foreach (var resultEntity in resultChainGeo1)
  {
    resultEntity.Color = 25;
    resultEntity.Commit();
    resultLineGeo1 = resultEntity.GetEntityID();
  }
}
foreach (var chain in angleChain)
{
  var resultChain2 = chain.OffsetChain2D(OffsetSideType.Left, 0.020, OffsetRollCornerType.None, 0, true, 0.005, true);
  var resultChainGeo2 = ChainManager.GetGeometryInChain(resultChain2);
  foreach (var resultEntity in resultChainGeo2)
  {
    resultEntity.Color = 30;
    resultEntity.Commit();
    resultLineGeo2 = resultEntity.GetEntityID();
  }
}

 

Link to comment
Share on other sites

I thought OffsetChain2D returned the 'new' geo.

So there's no way to get it without SearchManager.Result?

The tooltip::

Return Value

Type: Chain
The "offset" Chain, else null if failed.

I found DllImpExp bool OffsetChains (CHAIN *pChains, OffsetChainsParams &params, EptrArray &resultEptrs); if there's no way to do it through NET.

Link to comment
Share on other sites
1 minute ago, JKLINE said:

I thought OffsetChain2D returned the 'new' geo.

So there's no way to get it without SearchManager.Result?

The tooltip::

Return Value

Type: Chain
The "offset" Chain, else null if failed.

While it may say that in the description, the truth is that it returns the chain that you passed to it

 

Just get the result geometry and you will be back in business

Link to comment
Share on other sites
1 minute ago, JKLINE said:

It could be reffering to the chain that was offset, and not the actual result chain. 

 

Using result geometry causes issues when I start adding process threading. 

 

CLI it is! 

You can wrap the function yourself, but it likely does the same thing, there is likely a problem with your code

I believe the chook function also creates geometry not a chain

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

While it may say that in the description, the truth is that it returns the chain that you passed to it

 

Just get the result geometry and you will be back in business

Don't worry, I even screwed that up too 🤣 I'm working on getting the middle line to work (resultGeo1). But it seems linked to the original geometry, because it hates me 🤣🤣🤣

foreach (var chain in angleChain)
{
  chain.OffsetChain2D(OffsetSideType.Left,0.010,OffsetRollCornerType.None,0,false,0.005,false);
  var resultGeo1 = SearchManager.GetResultGeometry();
  angleGeoResult1.Add(resultGeo1[0]);
  GraphicsManager.ClearColors(new GroupSelectionMask(true));
  foreach (var tempEnt in angleGeoResult1)
  {
    tempEnt.Color = 50;
    tempEnt.Commit();
  }
}
foreach (var chain in angleChain)
{
  chain.OffsetChain2D(OffsetSideType.Left, 0.020, OffsetRollCornerType.None, 0, false, 0.005, false);
  var resultGeo2 = SearchManager.GetResultGeometry();
  angleGeoResult2.Add(resultGeo2[0]);
  GraphicsManager.ClearColors(new GroupSelectionMask(true));
  foreach (var tempEnt in angleGeoResult2)
  {
    tempEnt.Color = 60;
    tempEnt.Commit();
  }
}

 

Untitled.png

Link to comment
Share on other sites
2 minutes ago, byte said:

Would clearing the result bit before hand help?

I definitely would 🤦‍♂️ I hate it here 🤣

GetResultGeometry is the pure evil.

-- The issue I'll have with threading is when more than one thread ends up with a result. A problem for tomorrow though.

I appreciate the help!

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

I definitely would 🤦‍♂️ I hate it here 🤣

I had this Austrian boss when I started working, he would tell employees if they complain, "if you don't like it the doors right there",

This API is very hard to learn, like Mastercam it's very powerful, there are a lot of nuances to getting it to work across all the versions

 

I got lost somewhere for sure so many times

Link to comment
Share on other sites

I do actually love my job and the challenge of both the Net and C++ side of things :D

In my entire life, I've been quick at learning things because of Murphy's Law 🤣 I find that most people only see certain problems once in a while so it takes a while to learn things. Meanwhile, I face every problem as soon as it CAN be a problem.

Would've have gotten this far without support though, that's for sure.

Project Based Learning. Just over 3 months old.

Link to comment
Share on other sites

My experience was I was initially able to build a lot of working code in short order, but my abilities degraded overtime due to a sort of overload of information, so it takes me longer to find solutions now I find I have too many ideas and it's too much now

I spent 80% - 90% of my waking time writing code

Link to comment
Share on other sites

Not all functions with ft items are directly accessible via a simple sdk function, if they do, they won't likely have the same name

There are several ways to break geometry, you will have to figure out which one best suits your purpose

I can't say which functions specifically break geometry,

in the ft file

Link to comment
Share on other sites

I just heard back from the SDK team. They say it'll be a part of the new SDK package for Mastercam 2024, so I'm lost in the sauce until then.

Sounds like I'll just have to create my own C++ package.

Given geo and point,

if geoID = L, newLine (line.endpoint1, point), newLine (line.endpoint2,point), deleteGeo

return list of new IDs

if geoID = A, newArc (arc.endpoint1, point), newLine (arc.endpoint2,point), deleteGeo

IDK, something like this I suppose.

I started something like this yesterday, but I couldn't figure out the store_ent given an a_2d or l_2d

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