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

Why does my list appear to be empty?

I can tell the error is before line "foreach (var t in chainEntityList){" and after "foreach (var chain in selectedChains)["

 

                var selectedChains = ChainManager.ChainAll(75);
                foreach (var chain in selectedChains){
                    ChainData data = new ChainData();
                    var chainEntityList = data.ChainEntities;
                    foreach (var t in chainEntityList){
                        var chainKey = t.Key;
                        var chainValue = t.Value;
                        templist10.Add(chainKey.GetEntityID());
                        System.Windows.Forms.MessageBox.Show("ChainGeometry");
                        foreach (var chainEntity in templist10){
                            var entity = Geometry.RetrieveEntity(chainEntity);

 

Link to comment
Share on other sites

- try this -

var chainDetails = new Mastercam.Database.Interop.ChainDetails();
foreach (var chain in selectedChains)
 {
 // The GetData method in the ChainDetails class returns a ChainData object.
 var chainData = chainDetails.GetData(chain);
 var chainEntityList = chainData.ChainEntities;
 var startPoint = chainData.StartPoint;
 var endPoint = chainData.EndPoint;
 . . .
 }

 

Link to comment
Share on other sites

Roger,

As I understand this, 'var chainEntityList = chainData.ChainEntities' is a geometry entity and also a bool for the "flip". It is however a list.

I'm not sure how to go about using the list, or extracting those entityIDs into another list.

Is this a key/map/array situation?

Thanks

                    foreach (var t in chainEntityList){
                        templist10.Add(Geometry.RetrieveEntity(t));

 

Link to comment
Share on other sites

We can see that it is a List of KeyValue pairs. ->

ChainEntities = gcnew List<KeyValuePair<Mastercam::Database::Geometry ^, bool>> ();

The Key is the geometry entity. (Not the ID of the entity.)
The Value is a flag that lets us know if this entity is marked “flipped” in the chain.
If you really want to “extract” add these entities to another List.
foreach (var t in chainEntityList){
        templist10.Add(t.Key);

  • Thanks 1
Link to comment
Share on other sites
Quote

Meaning, I could call t.key[0] for example and t.key[1] would be the connecting entity?

No.
A (.NET) List is like a (C++) std::vector and is “in order”.
You do not [index] the “Key”, as it is not a list or array.
You loop through the ChainEntities  list for each item. The Key is the geometry entity, and the Value is the (bool) “am I flipped” flag for that entity.
 

  • Thanks 1
Link to comment
Share on other sites

Roger, I appreciate your patience. My studies have been in Javascript and Kotlin 😅 so it's a little bit of a culture shock.

I'd just like to confirm that it's possible for entities to be flipped in the middle of a chain.

For example, for lack of better explanation, entity1 = false, entity2 = true, entity3 = false.

Link to comment
Share on other sites

Almost a complete understanding.

Shouldn't it be coloring ALL the entities in the chain? It's only changing the color for the FirstEntity. (there are 4 chains on level 75).

                var chainDetails = new Mastercam.Database.Interop.ChainDetails();// Preps the ChainDetails plugin
                var selectedChains = ChainManager.ChainAll(75);// Chains all geometry on level 75
                var chainDirection = ChainDirectionType.CounterClockwise;// Going to be used to make sure all chains go the same direction
                foreach (var chain in selectedChains)// For each of the chains selected
                {
                    templist10.Clear();
                    chain.Direction = chainDirection;//Makes all chains go same direction
                    var chainData = chainDetails.GetData(chain);//Gets the data of the chain
                    var chainEntityList = chainData.ChainEntities;//Creates a list of entities in (geometry format) the selected chain
                    foreach (var t in chainEntityList)// For each entity in that chain
                    {
                        (t.Key).Color = 9;
                        (t.Key).Commit();
                    }

 

Link to comment
Share on other sites

You are getting the same result? Or would you like me to send you another set of files?

Using the same logic as the templist10.add(t.key)         I also tried                         var chainEntity = Mastercam.Database.Geometry.RetrieveEntity(t.key);

It gives a 'protection level' access error though.

Link to comment
Share on other sites
  • 3 weeks later...

I'm struggling to change the start entity of a chain. (closed chain).

Wanting it to be the farthest entity that is to the left (most negative X), I use the logic as follows

                foreach (var chain in selectedChains){
                    var chainData = chainDetails.GetData(chain);
                    var chainStartGeo = Geometry.RetrieveEntity(chain.FirstEntityId);
                    if (chainStartGeo is ArcGeometry arcGeo){
                        var chainStartGeoEP1 = arcGeo.EndPoint1;
                        var chainStartGeoEP2 = arcGeo.EndPoint2;
                        var chainStartGeoMidpoint = new Point3D(((chainStartGeoEP1.x + chainStartGeoEP2.x) / 2),((chainStartGeoEP1.y + chainStartGeoEP2.y) / 2),0.0);
                        var chainEntity = ChainManager.GetGeometryInChain(chain);
                        foreach (var entity in chainEntity){
                            if (entity is ArcGeometry tempArc){
                                var entityGeoEP1 = tempArc.EndPoint1;
                                var entityGeoEP2 = tempArc.EndPoint2;
                                var entityGeoMidpoint = new Point3D(((entityGeoEP1.x + entityGeoEP2.x) / 2), ((entityGeoEP1.y + entityGeoEP2.y) / 2), 0.0);
                                if (chainStartGeoMidpoint.x > entityGeoMidpoint.x){
                                    chainData.FirstEntity = entity;
                               }
                            }

I am using "ChainManager.RelinkChains(ref selectedChains);" after it goes through the checks, but it's not changing.

Link :: https://github.com/UberGamz/CustomNethook

Why am I trying to do this? When I select rightToLeft, it selects the colors of the chains correctly but when I select leftToRight, it colors 3 of the 4 chains correctly.

I've narrowed it down to it being the start point of the chains inside the 'ColorCrossovers()'

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

I'm struggling to change the start entity of a chain. (closed chain).

Wanting it to be the farthest entity that is to the left (most negative X), I use the logic as follows

                foreach (var chain in selectedChains){
                    var chainData = chainDetails.GetData(chain);
                    var chainStartGeo = Geometry.RetrieveEntity(chain.FirstEntityId);
                    if (chainStartGeo is ArcGeometry arcGeo){
                        var chainStartGeoEP1 = arcGeo.EndPoint1;
                        var chainStartGeoEP2 = arcGeo.EndPoint2;
                        var chainStartGeoMidpoint = new Point3D(((chainStartGeoEP1.x + chainStartGeoEP2.x) / 2),((chainStartGeoEP1.y + chainStartGeoEP2.y) / 2),0.0);
                        var chainEntity = ChainManager.GetGeometryInChain(chain);
                        foreach (var entity in chainEntity){
                            if (entity is ArcGeometry tempArc){
                                var entityGeoEP1 = tempArc.EndPoint1;
                                var entityGeoEP2 = tempArc.EndPoint2;
                                var entityGeoMidpoint = new Point3D(((entityGeoEP1.x + entityGeoEP2.x) / 2), ((entityGeoEP1.y + entityGeoEP2.y) / 2), 0.0);
                                if (chainStartGeoMidpoint.x > entityGeoMidpoint.x){
                                    chainData.FirstEntity = entity;
                               }
                            }

I am using "ChainManager.RelinkChains(ref selectedChains);" after it goes through the checks, but it's not changing.

Link :: https://github.com/UberGamz/CustomNethook

Why am I trying to do this? When I select rightToLeft, it selects the colors of the chains correctly but when I select leftToRight, it colors 3 of the 4 chains correctly.

I've narrowed it down to it being the start point of the chains inside the 'ColorCrossovers()'

Just create a new chain using the entities you want, 

I asked the same question a while ago :

 

 

 

  • Thanks 1
Link to comment
Share on other sites
  • 2 weeks later...
On 12/22/2022 at 6:50 AM, ___ said:

Just create a new chain using the entities you want, 

I asked the same question a while ago :

 

 

 

In the ChainInterop though, 

	Mastercam::Database::Geometry ^ChainData::FirstEntity::get ()
		{
		return m_FirstEntity;
		}

	// Note: The setter is for internal use only!
	void ChainData::FirstEntity::set (Mastercam::Database::Geometry ^entity)
		{
		m_FirstEntity = entity;
		}

So I was hoping it really was that easy.

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

In the ChainInterop though, 

	Mastercam::Database::Geometry ^ChainData::FirstEntity::get ()
		{
		return m_FirstEntity;
		}

	// Note: The setter is for internal use only!
	void ChainData::FirstEntity::set (Mastercam::Database::Geometry ^entity)
		{
		m_FirstEntity = entity;
		}

So I was hoping it really was that easy.

You can get the first chain_ent from an entity, then get the associated ->eptr to get a database pointer, then you can get the list of entites and remove some elements or re-arrange them , then pass that new list in order, it's not much work I suppose..

 

Link to comment
Share on other sites

In the name of progress! Will it work? Who knows! Not clear on how the predicate works though and finding specific examples instead of a general definition.

            Chain[] chainSorter(Chain inChain, Chain[] outChain, int startId) {
                var tempListIn = new List<int>();
                var tempListOut = new List<Geometry>();

                var geo = ChainManager.GetGeometryInChain(inChain);
                foreach (var ids in geo)
                {
                    var geoId = ids.GetEntityID();
                    tempListIn.Add(geoId);
                }

                if (tempListIn[0] != startId)
                {
                    Predicate<int> predicate = startId; // <- Error
                    var index = tempListIn.FindIndex(predicate);  
                    var listSize = tempListIn.Count;
                    for (var i=index; i<listSize; i++){
                        tempListOut.Add(Geometry.RetrieveEntity(i));
                    }
                    for (var i = 0; i < index; i++){
                        tempListOut.Add(Geometry.RetrieveEntity(i));
                    }

                }
                outChain = ChainManager.ChainGeometry((tempListOut.ToArray()));
                return outChain;
            }

 

Link to comment
Share on other sites
Just now, ___ said:

I was thinking more in the context of doing it in c++, then wrapping it in a InteropDll,

It's possible it could be done using your exisiting code, what's predicate?

Exactly my question 🤣

I guess it's a bool that needs to be defined.

Why are lists so difficult 🤦‍♂️

I'll probably have to have the result of the function be a list though. I can't get it to return a single chain, only an array of chains. 🤷‍♂️

 

                    bool predicate(int i){
                        if (i == startId){
                            return true;
                        }
                        return false;
                    }

 

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