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:

Recommended Posts

I'm certainly not an expert (or even very knowledgeable biggrin.gif ) on this older (v1.0) NETHook API.

 

This seems to work ->

 

code:

/// <summary>

/// ChangeLevels

/// Moves the currently 'selected' (Point, Line, Arc) entities to the specified level.

/// </summary>

/// <param name="level"></param>

public void ChangeLevels(int level)

{

bool ok = true;

int found_id = -1;

 

// Only look at 'selected' items

MC_SELBIT selMask = MC_SELBIT.Select;

 

// The 'type(s)' of entities to search for in the database

MC_ENTMASK entMask = MC_ENTMASK.Point_ID | MC_ENTMASK.Line_ID | MC_ENTMASK.Arc_ID;

 

// Start at the beginning

int start_id = Mastercam.DataBase.GetDBStart();

do

{

ok = Mastercam.DataBase.DBSearch(ref start_id, ref found_id, selMask, entMask);

if (ok)

{

CEntRef eRef = new CEntRef(found_id); // Reference to the Entity

eRef.level = level; // Set the level to...

}

} while (ok);

}

Link to comment
Share on other sites

Roger, thank you very much.

 

Today I remembered that some time ago I was able to program code like this, but then I forgot a little...

 

Your code works well. But the way you get the references to all entities seems a little odd to me. I've done it in an other (also odd wink.gif way:

code:

public static int[] AllEntities()

{

CEntRef[] entList;

int eptr;

int[] allEnts = new int[10000];

int i = 0;

int[] levels = Levels.GetVisibleLevels();

foreach (int level in levels)

{

entList = Levels.GetLevelEnts(level);

foreach (CEntRef ent in entList)

{

eptr = ent.eptr;

allEnts
= eptr;

i++;

}

}

return allEnts;

}

I'll appreciate any comments to my code.

Link to comment
Share on other sites

Jure,

The difference in the methods is probably because of the way the problem is approached.

You stated you want to change the levels of the selected entities.

So, how to do that? I (not knowing how!) thought...

“I want to go thru the database, retrieving just the selected entities and change the level of each of those entities.”

If there was a method to load up the CEntRef[] entList array with all the currently selected entities, your use the foreach would be an elegant solution. But, a built-in method that does that does not exist. ;(

(At least I don't think one exists. I did state that I'm not very experienced in using the NETHook v1.0 API)

Therefore you see my solution to "walk" thru the database.

 

As for using a modified version of your method, to solve the “change levels” problem.

If you wanted to “move” all of the entities on the Visible Levels to a new level, you could do something like shown below.

*Note how the the "problem" has been restated!

code:

       /// Change the level of all the entities on all the currently visible levels

public void ChangeLevels(int newLevel)

{

int[] levels = Levels.GetVisibleLevels();

foreach (int level in levels)

{

CEntRef[] entList = Levels.GetLevelEnts(level);

foreach (CEntRef ent in entList)

{

ent.level = newLevel;

}

}

}

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