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:

Custom Setup Sheet Data from NC FILE C# :


Recommended Posts

14 minutes ago, Zaffin said:

In my half hour of testing both functions return the same values, I've tried blanking and hiding entities, removing them, adding non solids; they return the same vector.

Are you testing the functions outside of your project?

No, the problem comes when I run one of the functions, then for example move the 3d model and run it again. Strange this is not the case for you.

Link to comment
Share on other sites
1 hour ago, c++ said:

No, the problem comes when I run one of the functions, then for example move the 3d model and run it again. Strange this is not the case for you.

Ahh I see the issue!  The alive bit gets manipulated when moving geometry and when removing a solids history.  Checking to make sure the solid is alive seems to solve the issue.

std::vector<DB_LIST_ENT_PTR> GetAllSolids()
{
	int numberOfSolidsSelected = 0;

	std::vector<DB_LIST_ENT_PTR> dblistptrvector;

	auto entityPointer = db_start;

	while (entityPointer != nullptr)
	{

		if (entityPointer->eptr->id == SOLID_ID  &&
			entityPointer->eptr->sel & ALIVE_BIT)
		{
			if (sel_bit_is_off(BLANK_BIT, entityPointer->eptr->sel))
			{
				numberOfSolidsSelected++;

				dblistptrvector.push_back(entityPointer);
			}
		}

		entityPointer = entityPointer->next;
	}

	if (numberOfSolidsSelected)
	{
		repaint_graphics();
	}

	return dblistptrvector;
}

 

Link to comment
Share on other sites

That explains a lot, they are MC_DEAD! The reason I thought this was a memory thing was because I had exactly the same behavior a long time ago with a .net list type I declared with new but did not cleat.

Link to comment
Share on other sites

Instead of you stepping though all of the entities, let Mastercam do that work for you.

get_raw_ent is just like get_ent, except you can control whether of not the entities must be visible to be "seen" by the get functionality.

Both only retrieve ALIVE entities of the requested type.

std::vector<DB_LIST_ENT_PTR> GetAllSolids ()
	{
	std::vector<DB_LIST_ENT_PTR> dblistptrvector;

	auto onlyVisible = false;
	auto succf = false;
	ent entity;
	DB_LIST_ENT_PTR foundPtr;
	DB_LIST_ENT_PTR eptr = db_start;
	do
		{
		get_raw_ent (onlyVisible, &eptr, &foundPtr, &entity, 0, SOLID_ID, &succf);
		if (succf)
			{
			if (sel_bit_is_off (&entity, BLANK_BIT))
				{
				dblistptrvector.push_back (foundPtr);
				}
			}
		} while (succf);

		if (!dblistptrvector.empty ())
			{
			repaint_graphics ();
			}

	return dblistptrvector;
	}

 

  • Like 1
Link to comment
Share on other sites
7 minutes ago, Roger Martin from CNC Software said:

Instead of you stepping though all of the entities, let Mastercam do that work for you.

get_raw_ent is just like get_ent, except you can control whether of not the entities must be visible to be "seen" by the get functionality.

Both only retrieve ALIVE entities of the requested type.


std::vector<DB_LIST_ENT_PTR> GetAllSolids ()
	{
	std::vector<DB_LIST_ENT_PTR> dblistptrvector;

	auto onlyVisible = false;
	auto succf = false;
	ent entity;
	DB_LIST_ENT_PTR foundPtr;
	DB_LIST_ENT_PTR eptr = db_start;
	do
		{
		get_raw_ent (onlyVisible, &eptr, &foundPtr, &entity, 0, SOLID_ID, &succf);
		if (succf)
			{
			if (sel_bit_is_off (&entity, BLANK_BIT))
				{
				dblistptrvector.push_back (foundPtr);
				}
			}
		} while (succf);

		if (!dblistptrvector.empty ())
			{
			repaint_graphics ();
			}

	return dblistptrvector;
	}

 

Cool, I will update my functions accordingly, thanks for the lesson Roger! I will follow your examples closely. 

Link to comment
Share on other sites

This add on is working great now, it is saving me loads of time, although I have a few enhancement requests,I will be switching my focus to my nethook nesting in c++/cli, hopefully that can get me and my colleagues out of these 60+ hours a week of programming!

Link to comment
Share on other sites

I need to iterate through the string names of parts to deduce the type of material then select the appropriate sheet size and add the appropriate trim and pin holes (for the flip) and drafting notes. I am also hoping to shuffle the part priority and angle to best optomize the nesting

Link to comment
Share on other sites
On 1/27/2020 at 11:09 AM, Zaffin said:

Ahh I see the issue!  The alive bit gets manipulated when moving geometry and when removing a solids history.  Checking to make sure the solid is alive seems to solve the issue.


std::vector<DB_LIST_ENT_PTR> GetAllSolids()
{
	int numberOfSolidsSelected = 0;

	std::vector<DB_LIST_ENT_PTR> dblistptrvector;

	auto entityPointer = db_start;

	while (entityPointer != nullptr)
	{

		if (entityPointer->eptr->id == SOLID_ID  &&
			entityPointer->eptr->sel & ALIVE_BIT)
		{
			if (sel_bit_is_off(BLANK_BIT, entityPointer->eptr->sel))
			{
				numberOfSolidsSelected++;

				dblistptrvector.push_back(entityPointer);
			}
		}

		entityPointer = entityPointer->next;
	}

	if (numberOfSolidsSelected)
	{
		repaint_graphics();
	}

	return dblistptrvector;
}

 

Zaffin,

If you want to view the project to see the latest improvements by myself & Roger, I changed the address of my GitHub : https://github.com/PeterRussellEvans/Api_Tools_Upgrade

Link to comment
Share on other sites
  • 1 month later...
  • 2 months later...

Here is an example I found online of wrapping the native open file dialog in c#

/*
typedef struct tagOFN { 
  DWORD         lStructSize; 
  HWND          hwndOwner; 
  HINSTANCE     hInstance; 
  LPCTSTR       lpstrFilter; 
  LPTSTR        lpstrCustomFilter; 
  DWORD         nMaxCustFilter; 
  DWORD         nFilterIndex; 
  LPTSTR        lpstrFile; 
  DWORD         nMaxFile; 
  LPTSTR        lpstrFileTitle; 
  DWORD         nMaxFileTitle; 
  LPCTSTR       lpstrInitialDir; 
  LPCTSTR       lpstrTitle; 
  DWORD         Flags; 
  WORD          nFileOffset; 
  WORD          nFileExtension; 
  LPCTSTR       lpstrDefExt; 
  LPARAM        lCustData; 
  LPOFNHOOKPROC lpfnHook; 
  LPCTSTR       lpTemplateName; 
#if (_WIN32_WINNT >= 0x0500)
  void *        pvReserved;
  DWORD         dwReserved;
  DWORD         FlagsEx;
#endif // (_WIN32_WINNT >= 0x0500)
} OPENFILENAME, *LPOPENFILENAME; 
*/

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class OpenFileName
{
    public int structSize = 0;
    public IntPtr dlgOwner = IntPtr.Zero;
    public IntPtr instance = IntPtr.Zero;

    public String filter = null;
    public String customFilter = null;
    public int maxCustFilter = 0;
    public int filterIndex = 0;

    public String file = null;
    public int maxFile = 0;

    public String fileTitle = null;
    public int maxFileTitle = 0;

    public String initialDir = null;

    public String title = null;

    public int flags = 0;
    public short fileOffset = 0;
    public short fileExtension = 0;

    public String defExt = null;

    public IntPtr custData = IntPtr.Zero;
    public IntPtr hook = IntPtr.Zero;

    public String templateName = null;

    public IntPtr reservedPtr = IntPtr.Zero;
    public int reservedInt = 0;
    public int flagsEx = 0;
}

public class LibWrap
{
    //BOOL GetOpenFileName(LPOPENFILENAME lpofn);

    [DllImport("Comdlg32.dll", CharSet = CharSet.Auto)]
    public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
}
//usage :
 OpenFileName ofn = new OpenFileName();

                ofn.structSize = Marshal.SizeOf(ofn);

                ofn.filter = "Nc files\0*.nc";

                ofn.file = new String(new char[256]);
                ofn.maxFile = ofn.file.Length;

                ofn.fileTitle = new String(new char[64]);
                ofn.maxFileTitle = ofn.fileTitle.Length;

                ofn.initialDir = "K:\\Departments\\Operations\\Shared\\NC_Data\\Router_3 axis\\DMS-NC FILES\\6.JUN 2020";
                ofn.title = "Safran";
                ofn.defExt = "nc";

                if (LibWrap.GetOpenFileName(ofn))
                {
                    //Console.WriteLine("Selected file with full path: {0}", ofn.file);
                    //Console.WriteLine("Selected file name: {0}", ofn.fileTitle);
                    // Console.WriteLine("Offset from file name: {0}", ofn.fileOffset);
                    //Console.WriteLine("Offset from file extension: {0}", ofn.fileExtension);
                    filename = ofn.file;
                }

 

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