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:

C-Hook Chaining


Recommended Posts

I am trying to write a chook to automatically select and set a chain to an operation. I believe the function I should be using for this is mc_op_getChains(). I need to input an entity pointer, the op index, and the chain. The op index is straight forward, I believe I understand the how to set and pass the chain into the function, what I'm having trouble with is the entity pointer. What entity do I need to pass into the function? In the Mastercam SDK the variable name is "solid" (shown in attached screenshot) which leads me to believe the function needs a solid. I don't understand why this function needs a solid, or any additional information at all.

I feel as though I'm either trying to use the wrong function, or I'm completely misunderstanding how this function works. Any help is very much appreciated.

I'm running Mastercam 2022 and Visual Studio Community 2019. If any additional information is needed please let me know.

mc_op_getChains().png

Link to comment
Share on other sites

I finally found a better answer to my own question. I didn't know there was another whole forum (this eMastercam forum, as well as myMastercam forum). I am finding answers to many of my questions there. Here is a link to a post about chaining:

https://forum.mastercam.com/Topic45815.aspx

Link to comment
Share on other sites

I would like to chain wireframe. Currently I am attempting to chain for a 2D contour operation.

I believe once I have a chain set I will just need to use the chain_manager(...) function to apply it to an operation. What I'm stuck on is how to set wireframe as a chain.

In the link I posted the function used is chain_it(...) but, as far as I can tell, this function will prompt the user to select a chain. As I said before, I would like to automate this process.

Out of curiosity, what is the mc_op_getChains(...)function used for?

Link to comment
Share on other sites

Yes, chain_it(…) prompts the user to select the chains(s).

I believe the mc_op_getChains(...) gets the chains from a Solid operation.
You are passing in a DB ptr to a Solid and getting out the Chains (if any).
The return is the number of chains found and returned via the [out] CHAIN **chains variable.

See chain_all_selected(…) in Chain_CH.h

You need to select the entities to be chained.
Not difficult, but you want to have plan first.
Are the entities all by themselves on a separate level?
Or are they all a specific color?
Or both?  
You could select the entities by level and/or color, and/or by some other property that is unique to those entities.

I you would like working sample code of using this,
email us SDK[at]Mastercam[dot]com with your company contact info.
 

Link to comment
Share on other sites

I think I just about have it. There's just one last error I can't seem to figure out:

main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl chain_manager(struct chain_manager_info *,short,bool *,short)" (__imp_?chain_manager@@YAXPEAUchain_manager_info@@FPEA_NF@Z) referenced in function "bool __cdecl AutoChaining(void)" (?AutoChaining@@YA_NXZ)

After some research my only guess is one of the arguments I have in the chain_manager(...) function call is incorrectly defined. I have #include "Chain_CH.h" at the top of the file. Here is the code:

bool AutoChaining()
{
    //variables for selection
    auto level = 0;  // Set > 0 to restrict the search to this level.
    auto color = 0;  // Set > 0 to restrict the search to this color. (max: 255)
    long selectionMask = GEOM_MASK;
    bool excludeBlanked = true; //exclude blanked entities
    auto count = 0;
    bool succf = false;
    NoStackEnt(entity);
    DB_LIST_ENT_PTR pFound = nullptr;
    DB_LIST_ENT_PTR pDB = db_start;
    
    //do while loop (do while succf is true)
    do {
        // If the 1st parameter is 'true', it will restrict the search to "visible" entities.
        //get_raw_ent gets next "alive" entity from database
        get_raw_ent(
            false,            //don't check if entity is visible
            &pDB,            //data base pointer
            &pFound,        //pointer to the entity
            &entity,        //the entity
            ALIVE_BIT,        //selection mask (bit 0) (not sure what this does)
            selectionMask,    //entity mask = GEOM_MASK
            &succf);        //returns true or false

        if (succf)
        {
            //if exluded blanked true AND if entity.bit is on (true) / BLANK_BIT = bit 8 (bit 8 = wire_flag)
            if (excludeBlanked && sel_bit_is_on(&entity, BLANK_BIT))
            {
                continue;
            }
            //if level is 0 OR level of the entity is equal to level AND...
            //...color is 0 OR color of the entity is equal to color
            //else jump to next iteration of do while loop
            if ((level == 0 || entity.level == level) &&
                (color == 0 || entity.color == color))
            {
                //turn bit 2 in entity on (bit 2 = selected)
                sel_bit_turn_on(&entity, SELECT_BIT);
                //write .sel and .id to database (updates/saves entity in database as selected)
                write_ent_sel(&entity, entity.eptr);
                count++;
            }
        }
    } while (succf);


    //variables for chaining
    CHAIN* new_chains = nullptr;
    bool only_closed = true;
    bool no_pts = true;

    //chain selected entities
    chain_all_selected(&new_chains, only_closed, no_pts);

    long op_number = 1;
    short customChainType = 0;

    //apply chain to operation
    chain_manager_info chainManagerInfo;
    chainManagerInfo.op_idn = op_number;
    chainManagerInfo.chns = new_chains;//CHAIN *
    chainManagerInfo.mode = CHNMGR_ADD;
    chain_manager(&chainManagerInfo,
        TP_CHN_ALL,
        &succf,
        customChainType);

   free_chains(&new_chains);

    return succf;
}

Link to comment
Share on other sites

That library was what I was missing, thank you! How was I supposed to know I needed to include that library? I don't see any mention of it in the SDK?

Also, for my own future reference, The line of code that was "sel_bit_turn_on(&entity,SELECT_BIT);" ... the "SELECT_BIT" had to be changed to "TEMP2_BIT" because that's the bit that the chain_all_selected(...) function reads. So the new line is this: "sel_bit_turn_on(&entity,TEMP2_BIT);"

I managed to get this all working, as well as regenerating the operation after applying the chain. What I'm stuck on now is trying to change the chain direction from CCW to CW. I see the chain_direction(...) function but I can't figure out how to call it. This function is in the CHAIN_HASH struct in ChainLib_CH.h. But there is also a CHAIN_HASH struct in BaseChainingTypes_CH.h and when I call CHAIN_HASH it defaults to the one I don't need. Do I need to create a seperate .cpp file and not include BaseChainingTypes_CH.h at the top so I can call the correct struct?  Thanks again for all the help.

Link to comment
Share on other sites
  • 4 weeks later...
On 5/25/2022 at 9:26 AM, Jake L said:

I finally found a better answer to my own question. I didn't know there was another whole forum (this eMastercam forum, as well as myMastercam forum). I am finding answers to many of my questions there. Here is a link to a post about chaining:

https://forum.mastercam.com/Topic45815.aspx

haha, that's my post

On 5/31/2022 at 3:23 PM, Jake L said:

That library was what I was missing, thank you! How was I supposed to know I needed to include that library? I don't see any mention of it in the SDK?

 

Check out the documentation for dumplib in the Mastercam Sdk pdf's, that will let you easily locate which library contains the function that the linker is complaining about, they give you code for a .bat file that needs to be run from the command line..

  • Like 1
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...