Sign in to follow this  
c++

How to ublank entities in a Chook ?

Recommended Posts

Good day,

I am blanking the entities in my mcx files with this function


int doentblnk(long selectionMask = ALL_ENTITIES_MASK, int level = 0, MC_BYTE color = 0)
{
	long count = 0; bool succf, suc = false; ent entity; DB_LIST_ENT_PTR foundPtr; DB_LIST_ENT_PTR eptr = db_start;
	do
	{
		get_raw_ent(false, &eptr, &foundPtr, &entity, 0, ALL_ENTITIES_MASK, &succf);

		if (succf)
		{
			if (entity.id != selectionMask)
			{
				suc = true;

				sel_bit_turn_on(&entity, BLANK_BIT);

				write_ent_sel(&entity, entity.eptr);
			}

		}
	
	} while (succf); 

	return suc ? 1 : 0;
}

However, when I try to reverse the process by setting BLANK_BIT off it does not work.

Share this post


Link to post
Share on other sites

Not sure what you mean about "does not work".

This worked for me (tested in 2018 and 2020) ->

extern "C" __declspec (dllexport) int m_main (int not_used)
	{
	// Must call this prior to accessing any Resources in the C-Hook DLL !
	ChangeResCl res (GetChookResourceHandle ());

	ent entity;
	if (AskForGeometry (_T ("Select an Arc..."), A_ID, entity))
		{
		sel_bit_turn_on (&entity, BLANK_BIT);
		write_ent_sel (&entity, entity.eptr);
		AfxMessageBox (_T ("Entity was Blanked"));

		sel_bit_turn_off (&entity, BLANK_BIT);
		write_ent_sel (&entity, entity.eptr);
		AfxMessageBox (_T ("Entity was UnBlanked"));
		}

	return MC_NOERROR | MC_UNLOADAPP;
	}

 

 

Share this post


Link to post
Share on other sites
45 minutes ago, Roger Martin from CNC Software said:

Not sure what you mean about "does not work".

This worked for me (tested in 2018 and 2020) ->

extern "C" __declspec (dllexport) int m_main (int not_used)
	{
	// Must call this prior to accessing any Resources in the C-Hook DLL !
	ChangeResCl res (GetChookResourceHandle ());

	ent entity;
	if (AskForGeometry (_T ("Select an Arc..."), A_ID, entity))
		{
		sel_bit_turn_on (&entity, BLANK_BIT);
		write_ent_sel (&entity, entity.eptr);
		AfxMessageBox (_T ("Entity was Blanked"));

		sel_bit_turn_off (&entity, BLANK_BIT);
		write_ent_sel (&entity, entity.eptr);
		AfxMessageBox (_T ("Entity was UnBlanked"));
		}

	return MC_NOERROR | MC_UNLOADAPP;
	}

 

 

Hi Roger,

some of the entities are not returning from their blanked state even manually after processing, but they are registered in the level manager.

I used this function

int doentunblnk(long selectionMask = ALL_ENTITIES_MASK, int level = 0, MC_BYTE color = 0)
{
	std::vector<ent> ents; std::vector<ent> ents2;
	long count = 0; bool succf, suc = false; ent entity; DB_LIST_ENT_PTR foundPtr; DB_LIST_ENT_PTR eptr = db_start;
	do
	{
		get_raw_ent(false, &eptr, &foundPtr, &entity, 0, ALL_ENTITIES_MASK, &succf);

		if (succf)
		{
				sel_bit_turn_off(&entity, BLANK_BIT);

				write_ent_sel(&entity, entity.eptr);
				
			

		}

	} while (succf);
	return suc ? 1 : 0;
}

 

Share this post


Link to post
Share on other sites

The now un-blanked entities are not appearing visually on-screen?

ref: interfaces\GUI\CGui_ch.h

// Try this first after the un-blanking.
repaint_graphics ();  

// This 'repaint_graphics' does do it for you, replace it with this ->
rebuild_graphics();  //  Only use if really needed, as this can take time.

} while (succf);

if (suc) //  Was anything changed?
  repaint_graphics ();  

return suc ? 1 : 0;

 

  • Thanks 1

Share this post


Link to post
Share on other sites
49 minutes ago, Roger Martin from CNC Software said:

The now un-blanked entities are not appearing visually on-screen?

ref: interfaces\GUI\CGui_ch.h

// Try this first after the un-blanking.
repaint_graphics ();  

// This 'repaint_graphics' does do it for you, replace it with this ->
rebuild_graphics();  //  Only use if really needed, as this can take time.

} while (succf);

if (suc) //  Was anything changed?
  repaint_graphics ();  

return suc ? 1 : 0;

 

Thanks Roger, that fixed the problem, although jeeez I don't think I can afford the performance loss on that one.

Share this post


Link to post
Share on other sites

I used both, there is however a lot going on in between, could the call set_clr_sel_bits() be interfering, I also did not call freechains while doing chain_intersect.. 

Share this post


Link to post
Share on other sites

My problem is the management of existing geometry, in my project I host a collection of c++/cli nethook entry points each designed to :

->get a solid if there is 1 solid in the file

->blank the existing non solid entities ,lines,arcs, notes,splines etc.

->create geometry on the min/max z extends of the part using the psbodyaskfaces and psbodyaskedges on a unique level for each top and bottom group

->creates a silhouette boundary using mastercams silhouette boundary function onto a unique level

->separating the outer "external" profile of the silhouette boundary ,top geometry and bottom geometry levels using nethook chainmanger and sort chains by area functions

->separating the "full" 360 degree arcs onto a unique level for top and bottom

->comparing the xy CenterPoint and diameter values to find the "through" holes then storing them on a unique level

->converting all non full circle wireframe geometry to splines via nethooks createparametricsplinefromchains to avoid parts of the chain being dropped by nesting undetected

->using c++ chains_intersect and comparing the spline length on the remaining "internal" top and "internal" bottom group against the remaining silhouette boundary "internal" group and deleting the "through" pockets

->repeating the above process to filter out the full circles entities from the silhouette boundary "internal" group

-> assign specific toolpaths to each group of geometry on each level : top plane pockets, bottom plane pockets, top blind holes, bottom blind holes,bottom through holes,and the outer profile final contour 

In order to avoid inadvertently chaining existing geometry on the target levels I blank them with the first function, however it would be nice to return any notes or geometry for the

user, although this is not critical since we will be nesting after some parts may contain engineering notes pertaining to customer requirments for a specific part.

We make private jet interiors so there are a lot of "special cases" that need documentation and because of the fast pace production line style of programming notes in mastercam save a lot of time and ensure important information for the programmer is delivered.

 

 

 

Share this post


Link to post
Share on other sites
Quote

could the call set_clr_sel_bits() be interfering

Depends if you're messing with the BLANK_BIT when using this.

So you are "blanking" the items you don't want included in the chain(s) and then chaining all on that level?

Quote

In order to avoid inadvertently chaining existing geometry on the target levels

Is that the only way you have to separate the items to be chained?
Can you separate the desired items - by type, by color, or...
 

Edited by Roger Martin from CNC Software

Share this post


Link to post
Share on other sites
22 minutes ago, Roger Martin from CNC Software said:

Depends if you're messing with the BLANK_BIT when using this.

It is only clearing SELECT_BIT

23 minutes ago, Roger Martin from CNC Software said:

So you are "blanking" the items you don't want included in the chain(s) and then chaining all on that level?

Yes.

 

23 minutes ago, Roger Martin from CNC Software said:

Is that the only way you have to separate the items to be chained?
Can you separate the desired items - by type, by color, or...

Same problem since I am concerned with what would happen were the chook would to be ran twice.

Share this post


Link to post
Share on other sites

I have an Idea but I do not know how, could I recolor all the existing entities in the database then use color schemes to define which geometry to chain? I am chaining with the .net api chainmanager. (my efforts to do chaining in c++ have not been very successful)

Share this post


Link to post
Share on other sites

Can you email me a sample part file? SDK [at] mastercam [dot] com

 Just a sample of the geometry you're dealing with and let me know which items should be chained and which should be ignored.

Since you doing C++/CLI you have all of the tools available to you.

  • Thanks 1

Share this post


Link to post
Share on other sites

OK...

 You're trying to chain what, on which level, while having the chaining ignore what type(s) of geometry?

You're said you're doing this by blanking the unwanted entities, which while this will work...

You don't like the need to have to call rebuild_graphics after. Fair enough, as that can take some time to complete.

There may be other ways to segregate the wanted from the unwanted geometry when chaining.

If I have details, I may be able to offset suggestions,

Share this post


Link to post
Share on other sites
11 minutes ago, Roger Martin from CNC Software said:

You're trying to chain what, on which level, while having the chaining ignore what type(s) of geometry?

CHAIN Level : 10000000  + Level 500000000 as top pocket operation

CHAIN Level : 5000000  + Level 500000000 as bottom pocket operation

CHAIN Level : 50 as bottom pocket operation

CHAIN Level : 100 as top pocket operation

CHAIN Level : 5000 as contour osciliation bottom plane

CHAIN Level : 5000 as 2d contour bottom plane

CHAIN Level : 50000000 as contour osciliation top plane

CHAIN Level : 50000000 as 2d contour top plane
 

Our programmers are currently using an older chook I wrote to program full  360 degree arcs so I will deal with those at a later date.

We are currently using the new chooks also as of yesterday, It is working well, the issue is really just the blank entities requiring refresh.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • 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