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:

Cycling throught groups in X4


Recommended Posts

In X3 my C code cycled through groups as follows:

code:

extern DllImpExp TpGrpMgr TpMainGrpMgr;

op_group *pGroup = TpMainGrpMgr.m_MainGrpList.GetAt(0);

int i = 0;

while (pGroup != NULL)

{

...

i++;

pGroup = TpMainGrpMgr.m_MainGrpList.GetAt(i);

}

This code get an error in X4:

error C2039: 'm_MainGrpList' : is not a member of 'TpGrpMgr'

 

How do I do the same thing in X4?

 

Thanks

Link to comment
Share on other sites

For more information...

Definatley look at the declarations in these .h files ->

 

 

For Operations:

TpOpMgr_ch.h

TpPartOpList_ch.h

 

For Tools:

TpToolMgr_ch.h

TpPartToolList_ch.h

 

code:

// walk through the ops

void WalkOperationList()

{

//INT_PTR opListSize = TpMainOpMgr.m_MainOpList.GetSize(); // X3

TpPartOpList opList = TpMainOpMgr.GetMainOpList(); // X4

INT_PTR opListSize = opList.GetSize(); // X4

if (opListSize > 0)

{

operation *op = NULL;

for (INT_PTR opCount = 0; opCount < opListSize; ++opCount)

{

//op = TpMainOpMgr.m_MainGrpList[opCount]; // X3

//op = opList[opCount]; // or this... op = opList.GetAt(opCount);

op = opList.GetAt(opCount);

if (op == NULL)

{ continue; }

// Do whatever need with this operation information....

 

// Like get the tool used in the operation - 'by slot'

tp_tool *tool = TpMainToolMgr.GetMainMillToolList().ToolBySlot(op->tl.slot); // X4

if (tool != NULL)

{

//Do whatever need with this tool information....

}

 

// - Or -

 

// Get the tool 'ent' using the DatabaseRetrieve function

ent toolEnt; // OUT

bool result = TpMainToolMgr.GetMainMillToolList().DatabaseRetrieve(op->tl.slot, toolEnt);

if (result)

{

//Do whatever need with this tool information....

}

}

}

}

 

 

// walk through the ops - (very) slight 'variation in calling' style = same result

void WalkOperationList_Variation2()

{

INT_PTR opListSize = TpMainOpMgr.GetMainOpList().GetSize();

if (opListSize > 0)

{

for (INT_PTR opCount = 0; opCount < opListSize; ++opCount)

{

operation *op = TpMainOpMgr.GetMainOpList().GetAt(opCount);

if (op == NULL)

{ continue; }

// Do whatever need with this operation information....

 

// Like get the tool used in the operation - 'by slot'

tp_tool *tool = TpMainToolMgr.GetMainMillToolList().ToolBySlot(op->tl.slot);

if (tool != NULL)

{

//Do whatever need with this tool information....

}

 

}

}

}

Link to comment
Share on other sites

Thanks for the reply, Roger.

 

I used code similar to this

code:

op_group *pGroup = TpMainGrpMgr.GetMainGrpList().RetrieveFirstOperationGroup();

 

ix1 = 1;

while (pGroup)

{

/* ... */

pGroup = TpMainGrpMgr.GetMainGrpList().GetAt(ix1++);

}

But I found that I get memory corruption problems

if I declare and intiialize a group list as follows:

code:

tpGrpList TpList = TpMainGrpMgr.GetMainGrpList();

op_group *pGroup = TpList.RetrieveFirstOperationGroup();

 

ix1 = 1;

while (pGroup)

{

/* ... */

pGroup = TpList.GetAt(ix1++);

}

It is of only academic interest as I have it working but I wonder if you have any thoughts on why this is.

Link to comment
Share on other sites

Did this really "work"? ->

code:

op_group *pGroup = TpMainGrpMgr.GetMainGrpList().RetrieveFirstOperationGroup();

 

INT_PTR ix1 = 1;

while (pGroup)

{

pGroup = TpMainGrpMgr.GetMainGrpList().GetAt(ix1++);

}

I tried this and it crashed...

 

After looking at this code, I can't say that I'm suprised.

My test MCX contained; 1 Machine Group that has 1 Toolpath Group.

 

First time into the loop with 'ix1 = 1' and 'pGroup != NULL'

(Obviously, otherwise we'd never drop into the loop! wink.gif )

and on the first trip thru the loop we pick up the next 'pGroup' and it is also "valid".

Now since we are only checking on 'while (pGroup)', we drop into the content of the loop again, with 'ix1 = 2'

And now with 'TpList.GetAt(ix1++)' we attempt to 'GetAt(2)'.

Which is an invalid index! => *Crash*

 

I know this to be true by looking at the value of 'listSize', which = 2.

(Recall that my test MCX had 1 Machine Group and 1 Toolpath Group)

 

The moral of this story is...

 

Make absolutely sure that your 'index' doesn't step past the valid range of a 'group'!

 

Note my previous code samples...

1> I get the size (number) of items in the list.

2> I check that I never exceed that number.

Link to comment
Share on other sites

The code worked fine for me. When I called

 

pGroup = TpMainGrpMgr.GetMainGrpList().GetAt(ix1++);

 

after processing the last group, pGroup was set to NULL without any error. But I will change my loop to check for the number of groups. The reason I did it that way was that the code needs to work for X, X2, X3 and X4. For X and X2 I use the following code in the same loop within compile time variables

 

group_list *pGroup;

group_list pGroup = group_list_ptr;

 

while (pGroup)

{

/* ... */

pGroup2 = pGroup2->next_ptr;

}

 

I will need to change this code to get a count of the number of groups. Is there a way to get the number of groups in X and X2 without traversing the list and counting them?

 

What didn't work for me was creating a function which declared and assigned a tpGrpList even without any other code e.g.

 

void func()

{

tpGrpList TpList = TpMainGrpMgr.GetMainGrpList();

}

 

This fails with an error exiting func saying that the stack has been corrupted around TpList.

 

It is a nuisance for us when the code is changed for every release of MasterCAM without any warning or documentation that I know of. I hope that the nethook interface will be more stable for future releases.

 

Thanks again for the help.

Link to comment
Share on other sites

quote:

after processing the last group, pGroup was set to NULL without any error. But I will change my loop to check for the number of groups. The reason I did it that way was that the code needs to work for X, X2, X3 and X4.

Would you mind tell me how to integrate all the projects together.

 

I have to develop the C-Hooks for X2 and X3 in VS2005, and these for X4 in VS2008.

 

It is very good to keep them together especially in one solution.

 

Can I use VS2008 to develop C-Hooks for X/X2/X3.

 

Sorry for interupting your thread.

Link to comment
Share on other sites

quote:

The code worked fine for me.

All I can tell you is that it didn't work for me.

*I'm not here trying to tell you how you have to do anything, I'm just trying to assist.

 

quote:

It is a nuisance for us when the code is changed for every release of MasterCAM without any warning or documentation that I know of...

Yup, change is a pain. But, when something needs to change to enhance/improve the product it happens.

 

BTW, In my (X4) SDK folder I see this file ->

C:McamX4sdkMastercam X4 API - Whats New.doc

Page#3 sounds like an interesting read! smile.gif

 

6. Operation Management List Class

6.1 What's changed and Why

6.2 Converting your App

!-- sample code --!

 

quote:

Can I use VS2008 to develop C-Hooks for X/X2/X3

You're certainly free to try, but I highly doubt it.

Link to comment
Share on other sites

@Sigmawave

Here's how I now handle traversing operation groups for versions X through X4. I have a separate VS project for each and define the appropriate compile time variable VER_Xn in each project.

code:

#if defined(VER_X) || defined(VER_X2)

#define GROUP_LIST group_list

#endif

#if defined(VER_X3) || defined(VER_X4)

#define GROUP_LIST op_group

#endif

 

GROUP_LIST *getNextGroup(GROUP_LIST *pGroup, int ix)

{

#if defined(VER_X) || defined(VER_X2)

if (ix == 0)

{

return group_list_ptr;

}

if (pGroup != NULL)

{

return pGroup->next_ptr;

}

#endif

#ifdef VER_X3

if (ix < TpMainGrpMgr.m_MainGrpList.GetSize())

{

return TpMainGrpMgr.m_MainGrpList.GetAt(ix);

}

#endif

#ifdef VER_X4

if (ix < TpMainGrpMgr.GetMainGrpList().GetSize())

{

return TpMainGrpMgr.GetMainGrpList().GetAt(ix);

}

#endif

return NULL;

}

 

// Calling the function

GROUP_LIST *p1;

p1 = getNextGroup(NULL, 0); // First group

p1 = getNextGroup(p1, ix); // Subsequent groups

I also use the compile time variables for other changes for each release.

 

I use VS 2003 for X, VS 2005 for X2 and X3 and VS 2008 for X4. I agree with Roger that you will not be able to use VS 2008 for them all.

 

@Roger

Sorry, I somehow missed the Whats New doc and it does seem to tell me all I needed to know. That said, yes, change happens but we work with a number of CAD/CAM systems and the others all do a better job of isolating users of their API from internal changes.

 

But I greatly appreciate your assistance with this problem.

 

Do you have any thoughts on the memory corruption I mentioned in my previous post?

 

Thanks again.

Link to comment
Share on other sites

It does not work for me. All I need is a function with the one line declaring TpList. It gets the following error in a pop up window when it exits the function:

 

Run Time Check Failure #2 - Stack around the variable 'TpList' was corrupted.

 

I tried compiling with and without debug and running with and without a part loaded. I am running the latest SDK with X4.

 

If I don't declare and assign TpList but instead just use TpMainGrpMgr.GetMainGrpList() directly it work fine.

 

The code gremlins must be really chuckling over this. I don't get a failure when I do something that should fail and do get a failure when I do something that should work.

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