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:

JKLINE

Verified Members
  • Posts

    166
  • Joined

  • Last visited

Posts posted by JKLINE

  1. And I'm officially stuck 😅 The first portion works in Mastercam, but the second portion throws an alarm. 

    "Method not found: 'Boolean Mastercam.IO.Interop.SelectionManager.AlterContourFinish(Int32, Double, Double, Double)'."

     

    Maybe I put something in the wrong place? Or am calling it incorrectly?

     

    	static System::Collections::Generic::List<int>^ GetOperations(int opCode)
    	{
    
    		auto list = gcnew System::Collections::Generic::List<int>();
    		for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index)
    		{
    			auto op = TpMainOpMgr.GetMainOpList()[index];
    			if (op && (opCode == TP_NULL || op->opcode == opCode))
    			{
    				list->Add(op->op_idn);
    			}
    		}
    
    		return list;
    	};
    	static bool SelectionManager::AlterContourFinish(long opID, double maxStepdown, double minDepth, double maxDepth)
    	{
    		//Get
    		prm_srf_common opCommon;
    		prm_srf_depths opDepth;
    		tp_entity thisToolPath;
    		thisToolPath.op_idn = opID;
    
    		//Set
    		opCommon.prm_srf_common::max_stepdown = maxStepdown;
    		opDepth.prm_srf_depths::min_depth = minDepth;
    		opDepth.prm_srf_depths::max_depth = maxDepth;
    
    		return true;
    	};
    	static bool SelectionManager::AlterPencilFinish(long opID, bool status, double limitOne, double limitTwo)
    	{
    		//Get
    		prm_srf_limits opData;
    		tp_entity thisToolPath;
    		thisToolPath.op_idn = opID;
    
    		//Set
    		opData.prm_srf_limits::on = status;
    		opData.prm_srf_limits::z1 = limitOne;
    		opData.prm_srf_limits::z2 = limitTwo;
    
    		return true;
    	};

     

                OperationsManager.UnSelectAllOperations();
                var surfaceFinishContourOpID = Mastercam.IO.Interop.SelectionManager.GetOperations(15);
                var surfaceFinishPencilOpID = Mastercam.IO.Interop.SelectionManager.GetOperations(39);
                foreach (var op in surfaceFinishContourOpID)
                {
                    var thisOp = SearchManager.GetOperation(op);
                    thisOp.SetSelectedState(true);
                    Mastercam.IO.Interop.SelectionManager.AlterContourFinish(op, 0.2, -0.2, -0.2);
                }
                OperationsManager.RefreshOperationsManager(true);
                foreach (var op in surfaceFinishPencilOpID)
                {
                    var thisOp = SearchManager.GetOperation(op);
                    thisOp.SetSelectedState(true);
                }
                OperationsManager.RefreshOperationsManager(true);
    
                return MCamReturn.NoErrors;

    https://github.com/UberGamz/SurfaceInterop (CLI)

    https://github.com/UberGamz/Rotary-PD---Copy (Nethook)

  2. Even closer! One problem though 😕 C++ has 'rules' 🤣

    "C++ a nonstatic member reference must be relative to a specific object"

     

    	static bool AlterContourFinish(long opID, double maxStepdown, double minDepth, double maxDepth)
    	{
    		//Get
    		auto thisOp = TpOpList::OpByID(opID);
    
    		//Set
    		thisOp.prm_srf_common::max_stepdown = maxStepdown;
    		thisOp.prm_srf_depths::min_depth = minDepth;
    		thisOp.prm_srf_depths::max_depth = maxDepth;
    
    		return ;
    	}
    	static bool AlterPencilFinish(long opID, bool status, double limitOne, double limitTwo)
    	{
    		//Get
    		auto thisOp = TpOpList::OpByID(opID);
    		
    		//Set
    		thisOp.prm_srf_limits::on = status;
    		thisOp.prm_srf_limits::z1 = limitOne;
    		thisOp.prm_srf_limits::z2 = limitTwo;
    
    		return ;
    	}

     

  3. It's a Christmas Miracle! Got it to select the pencil and finish contour toolpaths. Thank you so much!

    Put this into my NetHook portion ::

                OperationsManager.UnSelectAllOperations();
                var surfaceFinishContourOpID = Mastercam.IO.Interop.SelectionManager.GetOperations(15);
                var surfaceFinishPencilOpID = Mastercam.IO.Interop.SelectionManager.GetOperations(39);
                foreach (var op in surfaceFinishContourOpID)
                {
                    var thisOp = SearchManager.GetOperation(op);
                    thisOp.SetSelectedState(true);
                }
                OperationsManager.RefreshOperationsManager(true);
                foreach (var op in surfaceFinishPencilOpID)
                {
                    var thisOp = SearchManager.GetOperation(op);
                    thisOp.SetSelectedState(true);
                }
                OperationsManager.RefreshOperationsManager(true);
    
                return MCamReturn.NoErrors;

    I pasted this into the SelectionMangerExample.h

    	static System::Collections::Generic::List<int>^ GetOperations(int opCode)
    	{
    
    		auto list = gcnew System::Collections::Generic::List<int>();
    		for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index)
    		{
    			auto op = TpMainOpMgr.GetMainOpList()[index];
    			if (op && (opCode == TP_NULL || op->opcode == opCode))
    			{
    				list->Add(op->op_idn);
    			}
    		}
    
    		return list;
    	}

    Taking this to the finish line, I've found all the codes I'll need I believe. Just need practice calling them in C++. I feel like i'm sooooo close but soooo far away 🤣😅

    	static bool AlterContourFinish(int opCode)
    	{
    		bool succ = false;
    
    		 /// <summary> operation parameters - surface finish contour. </summary>
    		struct prm_srf_fin_contour
    		{
    			prm_srf_common common;		//!< common parameters for all surface operations
    			prm_srf_depths depth;		//!< surface operation's depth settings
    		}
    		/// <summary> operation parameters - surface operation's depth settings. </summary>
    		struct prm_srf_depths
    		{
    			double min_depth;			 //!< abs: highest cut
    			double max_depth;			 //!< abs: lowest cut
    		};
    		/// <summary> operation parameters - common parameters for all surface operations. </summary>
            struct prm_srf_common
    		{
    		double max_stepdown;		  //!< maximum stepdown
    		};
    
    		if (succ)
    
    		return succ;
    	}
    	static bool AlterPencilFinish(int opCode)
    	{
    		bool succ = false;
    
    		/// <summary> operation parameters - surface finish pencil. </summary>
    		struct prm_srf_fin_pencil
    		{
    			prm_srf_limits limit;		//!< surface operation's limit settings
    		};
    		/// <summary> operation parameters - surface operation's limit settings. </summary>
    		struct prm_srf_limits
    		{
    			bool on;				 //!< T-use cut depth limits
    			double z1;				 //!< depth limit 1
    			double z2;				 //!< depth limit 2
    		};
    
    		if (succ)
    
    			return succ;
    	}

     

  4. On 12/20/2022 at 12:24 PM, ___ said:

    Here is an example of getting the operations..

    /// <summary> Retrieves the operations found in the Toolpath Manager of the specified type. </summary>
    ///
    /// <param name="opCode"> (Optional) The operation code to filter on. (TP_NULL for NO Filtering). </param>
    ///
    /// <returns> The list of matching operations found. </returns>
    std::vector<operation*> GetOperations(TP_OPCODE opCode = TP_OPCODE::TP_NULL)
    {
    	std::vector<operation *> ops;
    	for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index)
    	{
    		auto op = TpMainOpMgr.GetMainOpList()[index];
    		if (op && (opCode == TP_NULL || op->opcode == opCode))
    		{
    			ops.push_back(op);
    		}
    	}
    
    	return ops;
    }

     

    Referencing the ChainDataInterOP source,

    this would go into the Main.CPP ?

    On 12/20/2022 at 5:03 PM, ___ said:
    ref class OperationsManagerInterop abstract sealed
    {
    public:
    /// <summary> Retrieves the operations found in the Toolpath Manager of the specified type. </summary>
    ///
    /// <param name="opCode"> (Optional) The operation code to filter on. (TP_NULL for NO Filtering). </param>
    ///
    /// <returns> The list of matching operations found. </returns>
    static System::Collections::Generic::List<int>^ GetOperations(int opCode)
    {
         
    	auto list = gcnew System::Collections::Generic::List<int>();
    	for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index)
    	{
    		auto op = TpMainOpMgr.GetMainOpList()[index];
    		if (op && (opCode == TP_NULL || op->opcode == opCode))
    		{
    			list->Add(op->op_idn);
    		}
    	}
    
    	return list;
    }
    };

    This would be a header file?

    On 12/20/2022 at 5:03 PM, ___ said:
    var opIDs = OperationsManagerInterop.GetOperations(15);//get only surface finish contour operations

     

    And this would go into my NetHook file?

    I'm not sure why this is so difficult for me? 😅

     

    https://github.com/UberGamz/SurfaceToolpathInterop

  5. I'm struggling to change the start entity of a chain. (closed chain).

    Wanting it to be the farthest entity that is to the left (most negative X), I use the logic as follows

                    foreach (var chain in selectedChains){
                        var chainData = chainDetails.GetData(chain);
                        var chainStartGeo = Geometry.RetrieveEntity(chain.FirstEntityId);
                        if (chainStartGeo is ArcGeometry arcGeo){
                            var chainStartGeoEP1 = arcGeo.EndPoint1;
                            var chainStartGeoEP2 = arcGeo.EndPoint2;
                            var chainStartGeoMidpoint = new Point3D(((chainStartGeoEP1.x + chainStartGeoEP2.x) / 2),((chainStartGeoEP1.y + chainStartGeoEP2.y) / 2),0.0);
                            var chainEntity = ChainManager.GetGeometryInChain(chain);
                            foreach (var entity in chainEntity){
                                if (entity is ArcGeometry tempArc){
                                    var entityGeoEP1 = tempArc.EndPoint1;
                                    var entityGeoEP2 = tempArc.EndPoint2;
                                    var entityGeoMidpoint = new Point3D(((entityGeoEP1.x + entityGeoEP2.x) / 2), ((entityGeoEP1.y + entityGeoEP2.y) / 2), 0.0);
                                    if (chainStartGeoMidpoint.x > entityGeoMidpoint.x){
                                        chainData.FirstEntity = entity;
                                   }
                                }

    I am using "ChainManager.RelinkChains(ref selectedChains);" after it goes through the checks, but it's not changing.

    Link :: https://github.com/UberGamz/CustomNethook

    Why am I trying to do this? When I select rightToLeft, it selects the colors of the chains correctly but when I select leftToRight, it colors 3 of the 4 chains correctly.

    I've narrowed it down to it being the start point of the chains inside the 'ColorCrossovers()'

  6. You make that sound super easy 😅 I think I'm missing a large piece. I just find the parts in the C++ files that I need and copy them to where they go? Do you have a VS Project I can reference?

    Solution : ChainDataInterop
      	Namespace : Mastercam
      		Class : NETHookApiReflection
              Public Methods
              		Class : Object
          
      	Namespace : Mastercam.Database.Interop
          	Class : ChainData
            Class : ChainDetails
              	Public Methods
              		 Class : Object

     

     

    Untitled.png

  7.             //Surface Finish Contour
                var maximumStepdown = 0.01;
                var contourMinimumDepth = 0;
                var contourMaximumDepth = 0;
    
                //Surface Finish Pencil
                var depthLimits = true;
                var pencilMinimumDepth = 0;
                var pencilMaximumDepth = 0;
    
                var selectedOps = SearchManager.GetOperations(true);
                foreach (var op in selectedOps)
                {
                    op.Retrieve();
                    op.Linking.
                    op.Commit();
                }
    
    
                GraphicsManager.Repaint(true);
                return MCamReturn.NoErrors;

    I've started this code, but I'm not finding a LinkingParams to suit my needs.

    Looking to alter the circled boxes

    DepthCutsParams also didn't work.

    ContourPage.png

    PencilPage.png

  8. 23 minutes ago, techbytesoftware.com said:

    You could avoid this issue entirely by simply not using selection

     

                        foreach (var entity in creaseResultGeometryNew)
                        {
                            upperCreaseID.Add(entity.GetEntityID());
                            entity.Color = 10;
                            entity.Level = createdUpperCrease;
                            entity.Commit();
                        }
                        //Moves result geometry

     

    instead of 

                        foreach (var entity in creaseResultGeometryNew)
                        {
                            upperCreaseID.Add(entity.GetEntityID());
                            entity.Color = 10;
                            entity.Selected = true;
                            entity.Commit();
                        }
                        //Moves result geometry
                        GeometryManipulationManager.MoveSelectedGeometryToLevel(createdUpperCrease, true);

     

    I'm so glad when I write new code, I don't do this anymore 🤣

    Works like a champ now.

    14 minutes ago, techbytesoftware.com said:
            var creaseResultGeometryNew = SearchManager.GetSelectedGeometry();
                            foreach (var entity in creaseResultGeometryNew)
                            {
                                entity.Color = 11;
                                entity.Selected = true;
                                entity.Commit();
                            }

    Here you are getting selected geometry, trying to select it again and calling commit()

     

    That looks like a mistake, no need to select it again, you selected it already

     

     

    How did you find that so fast?

  9. On 12/13/2022 at 10:39 AM, Roger Martin from CNC Software said:

     

    Don’t know “why” at this point, but it makes a difference.

    In -> offsetCutChain80() 

    Original:

    GraphicsManager.Repaint(true);
    int createdUpperLevel = 500;
    int createdLowerLevel = 501;
     

    image.png.212f3fdd41f564ee7e7b7239b8cc9fd8.png

    Altered:
    GraphicsManager.Repaint(false); // or remove this call 
    int createdUpperLevel = 500;
    int createdLowerLevel = 501;

    Result ->
    image.png.c37defcc75199656b4d42316702bbf0d.png

    Yes, you can share the ChainDataInterop project.

    This has become a large issue for me. 😕

    I've taken all the 'repaint(true)' out of the program that I can. Some of the areas require it to be there, or they do not work.

    That being said, if I run two of my NetHooks, no matter the order, geometry gets moved 😕

    I've tried added this code before and after each VOID but it's not helping.

                void deSelect()
                {
                    var selectedGeo = SearchManager.GetGeometry();
                    foreach (var entity in selectedGeo)
                    {
                        entity.Retrieve();
                        entity.Selected = false;
                        entity.Commit();
                    }
                }

    https://github.com/UberGamz/RP-GEN-CREASES
    https://github.com/UberGamz/RP-GEN-CUT

    They work fine SOLO, but when ran together during one Mastercam session, they mix up geometry.

  10. Solution ::

                    var depth = -0.100;
                    var roughAngle = 15.0;
                    var finishAngle = 20.0;
                    var selectedCutChain = ChainManager.GetMultipleChains("Select Geometry");
                    if (selectedCutChain == null)
                    {
                        return;
                    }
                    var depthDialog = DialogManager.AskForNumber("Enter Depth", ref depth);
                    if (depthDialog == 0)
                    {
                        return;
                    }
                        var roughAngleDialog = DialogManager.AskForAngle("Enter Rough Angle", ref roughAngle);
                    if (roughAngleDialog == 0)
                    {
                        return;
                    }
                    var finishAngleDialog = DialogManager.AskForAngle("Enter Finish Angle", ref finishAngle);
                    if (finishAngleDialog == 0)
                    {
                        return;
                    }

     

  11. 					var depth = -0.100;
                        var roughAngle = 15.0;
                        var finishAngle = 20.0;
    					var selectedCutChain = ChainManager.GetMultipleChains("Select Geometry");
                        if (selectedCutChain == null)
                        {
                            return;
                        }
                        DialogManager.AskForNumber("Enter Depth", ref depth);
                        if (depth == null)
                        {
                            return;
                        }
                        DialogManager.AskForAngle("Enter Rough Angle", ref roughAngle);
                        if (roughAngle == null)
                        {
                            return;
                        }
                        DialogManager.AskForAngle("Enter Finish Angle", ref finishAngle);
                        if (finishAngle == null)
                        {
                            return;
                        }

    Agreed. Except depth, roughAngle, and finishAngle will never be null

  12. I've looked around for a way to exit the script when the user hits the 'escape' key but failed to find a solution.

    Can't use 'console.readKey' because Mastercam doesn't have a console.

    I also found Mcamreturn (escape pressed) and looked into the UIevents

    I found this but it looks like it's pressing the keys, not waiting for keys to be pressed.

    //so, I press escape key 3 times or more....
    for(int i=0;i<3;i++)
    {
    keybd_event(VK_ESCAPE, 0, 0, 0);
    keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);
    }

  13. 4 hours ago, Roger Martin from CNC Software said:

    JKLINE,

    You are looking to create a Draft surface with a NET-Hook add-in?

     

    Using the code below, I'm getting a result, but some things seem strange.

    1. It doesn't send the surface to a different level.

    2. The angle I type in doesn't seem to matter. 15.0 results in -0.2618 degrees.

    3. It follows the chains, but not the arcs.

    Did I code it wrong? 😕

                void offsetCutchain(){
                    SelectionManager.UnselectAllGeometry();
                    LevelsManager.RefreshLevelsManager();
                    GraphicsManager.Repaint(true);
                    var selectedCutChain = ChainManager.GetMultipleChains("Select Geometry");
                    int mainGeo = 10;
                      int roughSurf = 138;
                       SurfaceDraftParams roughSurfaceDraftParams = new SurfaceDraftParams {
                        draftMethod=SurfaceDraftParams.DraftMethod.Length,
                        geometryType=SurfaceDraftParams.GeometryType.Surface,   
                        length=-0.100,
                        angle=15.0,
                        draftDirection=SurfaceDraftParams.DraftDirection.Defined
                        } ;
                    foreach (var chain in selectedCutChain){
                        var mainGeoSide1 = chain.OffsetChain2D(OffsetSideType.Right, .002, OffsetRollCornerType.All, .5, false, .005, false);
                        var mainGeoResult = SearchManager.GetResultGeometry();
                        foreach (var entity in mainGeoResult){
                            entity.Color = mainGeo;
                            entity.Level = mainGeo;  
                            entity.Selected = true;
                            entity.Commit();
                        }
                        var thisChain10 = ChainManager.ChainAllSelected();
                        foreach (var draftChain10 in thisChain10) {
                            var draftSurface10 = SurfaceDraftInterop.CreateDrafts(draftChain10, roughSurfaceDraftParams, false, 1);
                            foreach (var surface10 in draftSurface10){
                                if (Geometry.RetrieveEntity(surface10) is DraftSurface roughDraftSurface10) {
                                    roughDraftSurface10.Level = roughSurf;
                                    roughDraftSurface10.Commit();
                                }
                            }
                        }
                        GraphicsManager.ClearColors(new GroupSelectionMask(true));
                    }
                }
                offsetCutchain();
                GraphicsManager.Repaint(true);

     

     

    Untitled.png

  14. 11 minutes ago, Roger Martin from CNC Software said:

    JKLINE,

    You are looking to create a Draft surface with a NET-Hook add-in?

     

    Yes.

    Take customer geometry
    ChainOffsetContour(you've already helped me with this)
    DraftSurface(from the Result of ChainOffsetContour) at a negative depth (user specified) and angle (user specified).
    All ChainOffsetContour results are closed chains, and climb (Clockwise I think) direction is a positive angle.

    On 12/14/2022 at 8:06 AM, JKLINE said:

    That's a negative. It's angled at either 10, 15, 20, or 30 degrees at a negative depth.

    This here is an example of an end result. White line is the supplied geometry. We offset the green geometry. And then draft a surface down.

    Untitled.png

     

    White line is customer supplied geometry.

    Green is the offsetContour in both directions.

    Surface is a draft surface at a negative value.

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