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:

Reading operation groups from a library


Recommended Posts

I have an operation library file with several groups, each group containig several operations. I want to import all operations from a group specified by a user. There is a function grplib_list that I thought would help do just that, so I have tried the following:

code:

char *operation_library = "C:McamxMillOpsRDEFAULT.OPERATIONS";

group_list *l = grplib_list(

operation_library, // I: source file name

GROUP_OPERATIONS, // I: GROUP_ALL, GROUP_GEOMETRY, GROUP_OPERATIONS, etc

&succf); // O: TRUE = group info read ok

It does return the groups list, but my problem is that long n_ents and emap *e members of the group_list structure are empty, and I would expect them to hold all operations in the group.

 

Then I tried the same code on Mastercam 9, and the function did populate those members. But, I am not sure the values were correct, or maybe I just do not know how to use them, because I tried the following:

 

code:

operation op;

long fpos;

memset(&op, 0, sizeof op);

op.op_idn = l->e[0].ent_idn;

library_manager (OP_ID, operation_library, &op, &op.op_idn, LIBMGR_GET, &fpos, &succf);

and got "Access violation exception".

 

Failing that I tried getting just the list of operations from the library:

 

code:

op_list *op_head = 0;

list_manager (OP_ID, operation_library, LSTMGR_GET, (void**)&op_head);

It again returned nothing on Mastercam X, and caused "Access violation exception" on Mastercam 9.

 

So what am I doing wong here?

 

Thanks

Link to comment
Share on other sites

I found how to eliminate exception in Mastercam v9. I just need to replace

code:

char *operation_library = "C:Mcam9MillOpsRDEFAULT.OP9";

with

code:

char operation_library[] = "C:Mcam9MillOpsRDEFAULT.OP9";

This means that the function tries to write into my array which in the first case is in the read-only memory. Very bizarre...

 

The explanation for X returning empty list from list_manager is more logical, I simply need to create a machine group first.

 

I also found import_operations funstion, but it fails miserably on v9 with "Access violation" (this time it actually jumps to address 0!). On X it works somewhat, but does not properly imports groups.

 

That leaves me with my original problem, namely how to properly import a group of operations from a library? A sample code (preferably for v9) would be much appreciated.

 

Thanks

Link to comment
Share on other sites

OK, let me correct myself once again. import_operations function also somewhat works in v9 (I was using a wrong SDK version), but it does not import groups. So to summarize my problem, how can I associate operations from a library to their groups and import them as such?

Link to comment
Share on other sites

Hi, markov

this is my sample code of import_all_operations() function.

 

however I dont checked if I can import groups....

 

code:

 

 

 

CString file;

MC_BOOL succf;

 

DB_LIST_ENT_PTR e_ptr;

 

p_3d origin_pt={0,0,0};

ulong *op_ids;

ushort n_op_ids;

DUPTOOL_CHK dup;

// Purpose: import operations with all their assoc geometry from an external file

import_all_operations (file.GetBuffer(0), // I: source file to open and search

origin_pt, // I: predefined origin pt, NULL to call point_proc()

&op_ids, // O: op numbers to import, list will be update to new id's

&n_op_ids, // O: # of operations in list

true, // I: TRUE = import just the operation - no geometry

0, // I: 0=don't import op groups, 1=import op groups, -1=ask

false, // I: TRUE = recalc speed and feed to current material

true, // I: TRUE=use system views, FALSE=use views stored with op

dup, // I: TRUE do not check for similar tools in current tool list

true,

true,

&succf); // O: TRUE = operation found and added to current db

 

if(!succf||n_op_ids<=0)

{

 

 

return 0;

}

 

operation op;

for(int i=0;i<n_op_ids;i++)

{

op.op_idn=op_ids
;

operation_manager (&op, OPMGR_GET, &e_ptr, &succf);

if(succf)

{

/////

//op.cmn.grp_idn

}

 

}

 

 

 

 

 

 

 

 


Link to comment
Share on other sites

Thank you MasterShake,

 

I was hoping you would come and rescue me.

 

I had actually tried import_all_operations, and it even imports groups, but... The operation library I am working with has surface and contour toolpaths. I think my problem is that I only have level 1 licence which does not let me work with surfaces. When I try to import operations manually, the surface operations are grayed, and I can not import them. And here is a kicker: I can actually import the single "Surface Rough Parallel" operation from that library, but none of the "Surface Finish Parallel" operations! I still can not create any surface operations myself. Anyway. going back to my problem, as soon as it hits one of those "forbidden" operations, the import stops.

 

That is why I tried importing operations one by one using import_operations, but that is when it gets confused with groups. You do not have an example for that function, do you?

 

But you have still helped me. op.cmn.grp_idn was what I was looking for whole day yesterday - how to establish the relationship between an operation and its group. If no one comes to the rescue with some neat solution, I shall read the groups and operations separately from the library, create groups myself, and add operations one by one setting the same group it had in the library.

 

BTW, you probably want initialize the DUPTOOL_CHK structure in your example before calling the import function. And n_op_ids ca not possible be less than zero (in the if condition), it is declared as unsigned.

Link to comment
Share on other sites

You're welcome,

I'm glad I could help you smile.gif

 

My experience with chook coding is less than one year,and my career as software developer is only few months..

yep,I'm a newb coder. bonk.gif

 

I remember my first problem encountered in chook development is how to change/get operation's groups...

 

 

and I have not tried import_operations,

and dont know how to load only ops I need by import_operations.

 

/// * @param[in,out] op_ids op numbers to import, list will be update to new id's ??? confused.gif

 

so I do..

1. import all ops by import_all_operations..

2. delete ops which is not nessesally

Link to comment
Share on other sites

MasterShake,

 

With that little expirience, you are very good. I can only imagine what you will be able to do next year!

 

So let me help you with import_operations function. You just create array with the list of operation IDs that you want to import, as they appear in the library (you will need to analyze library file first by calling library_manager). Another argument defines the number of elements in the array. After the call, the same array will have newly assigned operation IDs.

 

I have implemented my idea (creating groups explicitly and adding operations appropriately) from my previous post, and it works without a problem.

 

Not many people working on Sunday... I am glad you are here.

Link to comment
Share on other sites

hi,

 

sorry,I dont have english books.. biggrin.gif

 

but there are a lot of online tutorials and samples..

and MS Visual Studio comes with large document of MSDN.

 

You need the basic knowledge of C/C++ and MFC to start.

MFC is necessary for making dialogs.

 

first,you have to decide what you want to make/do with chook.

 

 

http://www.google.com/search?q=C%2B%2B+tutorial

http://www.google.com/search?q=MFC+tutorial

http://www.google.com/search?q=STL+Standard+Template+Library

 

for code samples

http://www.codeproject.com/

http://www.google.com/search?q=code+samples+c%2B%2B

 

http://forums.microsoft.com/msdn/default.aspx?siteid=1

Link to comment
Share on other sites

Subject: Dialogs in Mastercam add-ons

 

“MFC is necessary for making dialogs.”

MasterShake is absolutely correct –

If you have (or want) to creates a “pure” (C++/MFC) C-Hook solution.

 

I know C++ and understand the basics of MFC, but I find it painful to create dialogs using MFC. Especially when it is so much easier to create beautiful dialogs using WinForms functionality available in .NET.

And you can pick you choice of .NET language: VB or C# or...

 

I hear you saying...

"But this or that functionality I need is not available in the Mastercam .NET API !"

 

If you’re willing to distribute 2 DLLs for your add-on, the solution is easier than you might think.

Do the user interface using WinForms in .NET -> your UI DLL

Do the functional (Mastercam stuff) in C++ -> the other DLL

 

If you’ve done any C-Hook (C++) you’ve seen this type of function declaration ->

 

extern "C" __declspec(dllexport) int m_main (int param)

 

If you do the same extern "C" __declspec(dllexport) with your (C++ C-Hook) functions, they are now visible to your .NET code using PInvoke/Interop.

 

The only part of using Interop that takes a bit of additional time/work to figure out is creating the DLLImport declarations in the .NET project for each exported (C++) function you are going to call. Yes, the first time you get into this it will seem like pain, but once you get a handle on it - it's no big deal to do.

Plus, it gets you into .NET programming where you'll have all the great NET functionality to do everything other than the Mastercam specific functions that you need to in C++.

 

Note!

This knowledge of PInvoke/Interop in .NET will be useful for you in the future, whether programming Mastercam add-ons or other non-Mastercam projects.

 

.NET (just like MFC) is really a “wrapper” around the Windows Win32 API. It all ends there at the Win32 API! NET 2.0 has more than v1.1 and NET 3.0 will undoubtedly have more. Even so, programming with .NET, sooner of later you’ll run into a situation where what you need do to cannot be done (directly) in .NET and what you need to do requires calling an Win 32 API function – you’ll be doing PInvoke.

 

http://www.pinvoke.net/

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