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:

SDK question - getting entities from database


Recommended Posts

I am having trouble using the SDK to get entities from the database and I can't find any sample code. This is what I am trying.

 

boolean succf;

DB_LIST_ENT_PTR ptr, found_ptr;

ent entity;

ushort sel_mask;

ulong ent_mask;

 

sel_mask = 0x2ff;

ent_mask = 0xffff;

ptr = db_start;

get_ent (&ptr, &found_ptr, &entity, sel_mask, ent_mask, &succf);

 

I have tried setting the selection mask and entity mask to different values but without any success. What I want to do eventually is go through the database and retrieve all invisible notes on a particular layer. I also want to be able to store notes in the database. Can anyone help me with thus or point me to some sample code?

 

Any help would be greatly appreciated.

 

CaKiwi

Link to comment
Share on other sites

quote:

What I want to do eventually is go through the database and retrieve all invisible notes on a particular layer.


code:

boolean succf;

DB_LIST_ENT_PTR ptr, found_ptr;

ent entity;

ushort sel_mask;

ulong ent_mask;

int iLevelYouWant = 22; // for instance

 

 

for ( ; ; )

{

get_ent(&ptr, &found_ptr, &entity, BLANK_BIT, N_ID, &succf);

 

if (!succf) break;

 

if (entity.level == iLevelYouWant)

{

// Here's a blanked note on level 22

// Now the fun begins
;)

}

}

HTH

Link to comment
Share on other sites

Bullines: Thanks for the rapid response, but I can't get your code to work. If I don't initialize the variable ptr to something, I get a fatal error. I was initializing it to db_start, which did not give me a fatal error but always returned a null ptr and the succf argument was always false.

Link to comment
Share on other sites

quote:

If I don't initialize the variable ptr to something, I get a fatal error.


Is it better if you init both the db pointer and found pointer to the beginning of the db?

 

code:

// init

ptr = db_start;

found_ptr = db_start;

 

for ( ; ; )

{

get_ent(&ptr, &found_ptr, &entity, BLANK_BIT, N_ID, &succf);

 

if (!succf) break;

 

if (entity.level == iLevelYouWant)

{

// Here's a blanked note on level 22

// Now the fun begins
;)

}

}

quote:

succf argument was always false


Just to be sure, there are entities in the currently opened file?

Link to comment
Share on other sites

Initializing just ptr to db_start ( and setting the masks so there was something to find) fixed the problem. Thanks a lot for your help. Have a virtual beer on me.

 

I still need to save a note in the database and I would greatly appreciate any help you could give me on that.

 

Thanks again.

 

CaKiwi

Link to comment
Share on other sites

quote:

One more thing, now that I have the note in the entity structure, where do I find its text?


code:

ulong mtid;

char *szText;

char *szNoteText;

int iTextLen;

 

 

strcpy(szText, "Mastercam Notes are fun!!!");

iTextLen = strlen(szText) + 1;

szNoteText = (char *) mTableAlloc(iTextLen, &mtid); // allocate table item

your_label_ent.u.n.mtid = mtid; // assign memory table

strcpy(szNoteText, szTExt); // copy string

Then when you call store_ent(), your text will be stored with the note.

 

HTH

Link to comment
Share on other sites

Thanks, that worked great!

 

I do also want to create a new note, which your previous post helps with. Is there some way to initialize the fields in the entity structure to sensible default values without having to set each field individually? Does store_ent() create a new entity or just update an old one?

 

CaKiwi

Link to comment
Share on other sites

quote:

Is there some way to initialize the fields in the entity structure to sensible default values without having to set each field individually?


InitNOTE() should help.

 

quote:

Does store_ent() create a new entity or just update an old one?


store_ent() creates a new entitiy. You'd use rewrite_ent() to modify an existing one.

Link to comment
Share on other sites

I'm getting REALLY close. I am able to create a note and read it back, but if I blank it either by using delete_ent() as in the code below (is this the correct way to do it?) or manually in MC my call to get_ent() doesn't find anything. Any thoughts?

 

code:

 

...

store_ent (&entity, &ptr, 0, 0, 3987, new_attrib, &succf);

 

if (succf)

{

delete_ent(ptr, 1, 1, 0, &succf, 0);

}

 

sel_mask = BLANK_BIT;

ent_mask = N_ID;

ptr = db_start;

get_ent (&ptr, &found_ptr, &entity, sel_mask, ent_mask, &succf);

while (succf)

{

// handle note

cptr = (char *) mTableFindData (entity.u.n.mtid);

get_ent (&ptr, &found_ptr, &entity, sel_mask, ent_mask, &succf);

}

Thanks a lot for your help.

 

CaKiwi

Link to comment
Share on other sites

I haven't been able make get_ent() retrieve blanked entities. I tried get_raw_ent() with the chkvis argument set to false and this is working fine, retrieving both blanked and visible entities. So my next question is, how do I find out if an entity that I have retrieved is visible or blanked.

 

Thanks

 

CaKiwi

Link to comment
Share on other sites

I've found that passing a sel_mask set to BLANKED_BIT to get_raw_ent() retrieves only blanked entities. Also, I noticed that the documentation says the get_ent() only retrieves visible entities, which I suppose explains why it returns no entities if the sel_mask is set to BLANKED_BIT.

 

I seem to have run out of questions, at least temporarily. Thanks again for all the help.

 

CaKiwi

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