LMVUICHARD

SearchManager.GetOperations ONLY for milling operations?

Recommended Posts

I meet some dificulties with the SearchManager.GetOperations Method.

It seems that Method run only with milling operations.

If i try to run it with a basic lathe machining file, with some turning operations and some drilling,

the code below returns only the drillings operations.

With a milling file, it's run properly, but impossible with a lathe file (i don't have try with a wire file, but it will be probably the same).

I have try with some modifiers, (you can see in comments),  but result is the same.

 

What is the way in NetHook to load an array with really all operations, not depending machining technology?

i need only access status (get)  in the Msbox, and get or set only posting, displayToolpath.

Its very easy to test, the code is only to paste in a standard Mastercam vb.net template, and i join the mastercam test lathe file too.

 

Thanks in advance

 

Mastercam version:2020

 

Code:

 Private Sub OnOkView(sender As Object, e As EventArgs) Handles buttonOK.Click
            Dim Tl As Tool = Nothing
            'Dim Optp As OperationType = Nothing
            'Dim Operationss = SearchManager.GetOperations(-1, -1, True, Tl)
            'Dim Operationss = SearchManager.GetOperations(True)
            Dim Operationss = SearchManager.GetOperations()
            For IndxBcl = 0 To Operationss.Count - 1
                If Operationss(IndxBcl).Selected = True Then
                    MsgBox("Opération ID:" & Operationss(IndxBcl).GetOperationID() & " Name:" & Operationss(IndxBcl).Name & " Tool:" & Operationss(IndxBcl).OperationTool.Number & " Posting:" & Operationss(IndxBcl).Posting & " Display:" & Operationss(IndxBcl).DisplayToolpath & " Dirty:" & Operationss(IndxBcl).Dirty)
                End If
            Next

        End Sub

 

 

Julien-LMV2.mcam

Share this post


Link to post
Share on other sites
5 minutes ago, LMVUICHARD said:

I meet some dificulties with the SearchManager.GetOperations Method.

It seems that Method run only with milling operations.

If i try to run it with a basic lathe machining file, with some turning operations and some drilling,

the code below returns only the drillings operations.

With a milling file, it's run properly, but impossible with a lathe file (i don't have try with a wire file, but it will be probably the same).

I have try with some modifiers, (you can see in comments),  but result is the same.

 

What is the way in NetHook to load an array with really all operations, not depending machining technology?

i need only access status (get)  in the Msbox, and get or set only posting, displayToolpath.

Its very easy to test, the code is only to paste in a standard Mastercam vb.net template, and i join the mastercam test lathe file too.

 

Thanks in advance

 

Mastercam version:2020

 

Code:

 Private Sub OnOkView(sender As Object, e As EventArgs) Handles buttonOK.Click
            Dim Tl As Tool = Nothing
            'Dim Optp As OperationType = Nothing
            'Dim Operationss = SearchManager.GetOperations(-1, -1, True, Tl)
            'Dim Operationss = SearchManager.GetOperations(True)
            Dim Operationss = SearchManager.GetOperations()
            For IndxBcl = 0 To Operationss.Count - 1
                If Operationss(IndxBcl).Selected = True Then
                    MsgBox("Opération ID:" & Operationss(IndxBcl).GetOperationID() & " Name:" & Operationss(IndxBcl).Name & " Tool:" & Operationss(IndxBcl).OperationTool.Number & " Posting:" & Operationss(IndxBcl).Posting & " Display:" & Operationss(IndxBcl).DisplayToolpath & " Dirty:" & Operationss(IndxBcl).Dirty)
                End If
            Next

        End Sub

 

 

Julien-LMV2.mcam

Unless NEThook has updated it does not support lathe or wire operations, 

like many things this would probably require c++

If you explain in great detail, what you are trying to do, I could write you a wrapper class for it, that you could use kn vb.net

You could import operations thats about it..

 

Share this post


Link to post
Share on other sites

SearchManager in the NET-Hook API currently only supports Mill type operations.
A simple C++/CLI project that creates an interop DLL that your NET-Hook add-in can use would be simple to create. You would add a reference to this DLL. just like you do for the NETHook3_0.DLL to get access to the functionality in the standard API. 
I have such a project. If you email -> SDK.mastercam.com and let us know you company contact information and what version of Mastercam this is for, I can probably set you up.

It appears you are looking for these data items in each operation -
Operation Name (comment)
Operation ID (number)
Operation Type ("type" code)
Operation Tool Number (and probably also the Tool Slot Number)
“Toolpath Visibility” status
“IsDirty” status
“Selected” status
“Posting” status (Is the operation ghosted?)
*Are there more?

  • Like 1

Share this post


Link to post
Share on other sites

Wow… thanks for the informations.

Roger as asked, i've send you an email.

 

Thanks for all!

Share this post


Link to post
Share on other sites
On 5/27/2020 at 4:00 PM, Roger Martin from CNC Software said:

A simple C++/CLI project that creates an interop DLL that your NET-Hook add-in can use would be simple to create.
I have such a project.

It appears you are looking for these data items in each operation -
Operation Name (comment)
Operation ID (number)
Operation Type ("type" code)
Operation Tool Number (and probably also the Tool Slot Number)
“Toolpath Visibility” status
“IsDirty” status
“Selected” status
“Posting” status (Is the operation ghosted?)
*Are there more?

Hi Roger,

are you passing all the data as an array from C++/CLI to managed NET-Hook? I use similar approach to expose some Chook functions which are not available in NET-Hook, but I only pass some values, strings. I use Text.StringBuilder in one case to receive a list of Stock Model (operations) names.

Is there a better approach and/or better for multiple data like this example above?

TIA, Peter

Share this post


Link to post
Share on other sites
1 hour ago, Peter - NCS Ltd. said:

Hi Roger,

are you passing all the data as an array from C++/CLI to managed NET-Hook? I use similar approach to expose some Chook functions which are not available in NET-Hook, but I only pass some values, strings. I use Text.StringBuilder in one case to receive a list of Stock Model (operations) names.

Is there a better approach and/or better for multiple data like this example above?

TIA, Peter

You can export arrays like this from cli :

//we need a class to export
#pragma once
namespace ApiTools
{
	namespace Database
	{
		public ref class PointerArrays abstract sealed
		{
		public:
			static array<System::Int32>^ GetWireframeOnLevel(const int level1);

		};
	}
}
//get an array of database pointers cast as int32 representing wireframe found on the specified level

array<System::Int32>^ ApiTools::Database::GetWireframeOnLevel(const int level1)

{
	auto EntityPointerList = gcnew System::Collections::Generic::List<System::Int32>;
	long count = 0;
	bool bSuccf;
	ent entity;
	DB_LIST_ENT_PTR foundPtr;
	DB_LIST_ENT_PTR eptr = db_start;

	bool found;

	found = false;

	long selectionMask = ALL_ENTITIES_MASK;

	for (; ; ) // loop until "break;" command

	{

		get_ent(&eptr, &foundPtr, &entity, ALIVE_BIT,//get entity//found entity pointer//found entity new pointer//entity class object//sel bit//entity type

			selectionMask, // entity types

			&bSuccf); // entity successfully read
		{
			if (!bSuccf) // No more entities
			{
				break;
			}

			if (bSuccf) // entity found loop once
			{
				if (entity.level == level1)
				{
					if (entity.id == S_ID || entity.id == NB_ID || entity.id == A_ID || entity.id == L_ID)
					{

						EntityPointerList->Add(static_cast<System::Int32>(PtrToInt(entity.eptr)));
						count++;
					}
				}

			}
		}
	}

	if (EntityPointerList->Count > 0)
	{
		return EntityPointerList->ToArray();
	}
	return nullptr;
}

 

  • Like 1

Share this post


Link to post
Share on other sites

If you are passing a known number of string you could create a struct in cli and pass that to your function :

namespace mynamespace
{
public ref struct OperationValues
{
System::String ^ param1;
System::String ^ param2;
};
public ref class GetOperationValuesClass{
public : 
void GetOperationValues(OperationValues^ values)
{
values->param1 = "firststring";
values->param2 = "secondstring";
}
private:
};
}

 

  • Like 1

Share this post


Link to post
Share on other sites
37 minutes ago, baby byte said:

If you are passing a known number of string you could create a struct in cli and pass that to your function :


 

Thank you Peter, that makes sense! I'll play with it.

Share this post


Link to post
Share on other sites
1 hour ago, baby byte said:

Sorry, while this will work for importing to c++ there appear to be issues with c# and structs

 https://stackoverflow.com/questions/35912787/using-c-cli-structs-from-c-sharp

I would go ahead with the array  instead

I think you are misunderstanding that thread.  The example below works for me. 

OperationService.h

#pragma once

namespace OperationServiceNative
{

	public ref struct OperationData
	{
		System::String^ Comment;
		int ID;
		int Type;
		int ToolNumber;
	};

	public ref class OperationService
	{
	public:
		OperationService();

		OperationData^ GetOperationData(int opID);

		~OperationService();

	};
}

OperationService.cpp

#include "pch.h"

#include "OperationService.h"

OperationServiceNative::OperationService::OperationService()
{
}

OperationServiceNative::OperationData^ OperationServiceNative::OperationService::GetOperationData(int opID)
{
	OperationData^ opData = nullptr;

	auto operation = TpMainOpMgr.GetMainOpList().OpByID(opID);

	if (operation != nullptr)
	{
		opData = gcnew OperationData();

		System::String^ commentString = gcnew System::String(operation->comment);

		opData->Comment = commentString;
		opData->ID = operation->op_idn;
		opData->Type = operation->opcode;
		opData->ToolNumber = operation->tl.tlno;
	}

	return opData;
}

OperationServiceNative::OperationService::~OperationService()
{
}

Main.cs

namespace MyNetHook
{
    using Mastercam.App;
    using Mastercam.App.Types;

    using OperationServiceNative;

 
    public class Main : NetHook3App
    {

        public override MCamReturn Run(int param)
        {
            var opService = new OperationServiceNative.OperationService();

            var opData = opService.GetOperationData(1);
       
            return MCamReturn.NoErrors;
        }

    }
}

 

  • Thanks 1

Share this post


Link to post
Share on other sites
28 minutes ago, Zaffin_D said:

void OperationServiceNative::OperationService::GetOperationData(int opID,OperationServiceNative::OperationData^ data);//can this be done?

I was trying to take the struct as a parameter,

not sure if that is the reason i was having

trouble. Nice example.. :thumbsup::turned:

Share this post


Link to post
Share on other sites
19 minutes ago, baby byte said:

I was trying to take the struct as a parameter,

not sure if that is the reason i was having

trouble. Nice example.. :thumbsup::turned:

Yes, you can pass a struct, see below

File: OperationService.h

#pragma once

namespace OperationServiceNative
{
	public value struct OperationData
	{
		System::String^ Comment;
		int ID;
		int Type;
		int ToolNumber;
	};

	public ref class OperationService
	{
	public:
		OperationService();

		OperationData^ GetOperationData(int opID);

		bool CreateOperation(OperationData% opData);

		~OperationService();

	};
}

File: OperationService.cpp

#include "pch.h"

#include "OperationService.h"

OperationServiceNative::OperationService::OperationService()
{
}

OperationServiceNative::OperationData^ OperationServiceNative::OperationService::GetOperationData(int opID)
{
	OperationData^ opData = nullptr;

	auto operation = TpMainOpMgr.GetMainOpList().OpByID(opID);

	if (operation != nullptr)
	{
		opData = gcnew OperationData();

		System::String^ commentString = gcnew System::String(operation->comment);

		opData->Comment = commentString;
		opData->ID = operation->op_idn;
		opData->Type = operation->opcode;
		opData->ToolNumber = operation->tl.tlno;
	}

	return opData;
}

bool OperationServiceNative::OperationService::CreateOperation(OperationData% opData)
{
	//Code to create an operation with the OperationData struct

	return false;
}

OperationServiceNative::OperationService::~OperationService()
{
}

File: Main.cs

namespace MyNetHook
{
    using Mastercam.App;
    using Mastercam.App.Types;

    using OperationServiceNative;

 
    public class Main : NetHook3App
    {

        public override MCamReturn Run(int param)
        {
            var opService = new OperationService();

            var opData = (OperationData)opService.GetOperationData(1);

            var newOpData = new OperationData()
            {
                Comment = "A new op",
                ID = 2,
                Type = 1,
                ToolNumber = 1
            };

            var isSuccess = opService.CreateOperation(ref opData);
       
            return MCamReturn.NoErrors;
        }

    }
}

 

  • Thanks 1
  • Like 1

Share this post


Link to post
Share on other sites

This is a way better way (imo) to import/export data.

Functions that take structs that take functions as parameters have no requirement to modify the function name and header file when adding/removing parameters..

Share this post


Link to post
Share on other sites
14 hours ago, Zaffin_D said:

Yes, you can pass a struct, see below

Hi Zaffin,

are you willing to share this both VC projects on GitHub?

TIA,

Peter

Share this post


Link to post
Share on other sites
2 hours ago, Peter - NCS Ltd. said:

Hi Zaffin,

are you willing to share this both VC projects on GitHub?

TIA,

Peter

Yes.  Here you are.

  • Thanks 2

Share this post


Link to post
Share on other sites

Great topic and good to see 3 very brilliant people working and sharing information. :thumbsup:

  • Like 2

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

  • 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