JKLINE
-
Posts
166 -
Joined
-
Last visited
Content Type
Profiles
Forums
Downloads
Store
eMastercam Wiki
Blogs
Gallery
Events
Posts posted by JKLINE
-
-
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 ; }
-
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; }
-
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?
-
Of course! It's an array after all
-
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()'
-
You would post this as a DLL, load it into the resources, and then call on it with opCode?
-
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
-
This'll be my first CHook project? How exciting.
-
//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.
-
The intent is to compete with other software. Instead of importing customer geometry into other software, we'd like to import it directly into Mastercam.
Two rotary dies that never touch.
https://www.ardensoftware.com/products/impact-die-making-cad-cam-software/
Sheer cut instead of crush cut, making the metal last significantly longer.
-
I greatly appreciate the assist. Only a form left to create and it'll be ready to demo and debug
-
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?
-
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;
Altered:
GraphicsManager.Repaint(false); // or remove this call
int createdUpperLevel = 500;
int createdLowerLevel = 501;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-CUTThey work fine SOLO, but when ran together during one Mastercam session, they mix up geometry.
-
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; }
-
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
-
That looks like the exact thing I'm looking for
Thank you.
-- It doesn't work while waiting on user Input though.
"oh no, I've clicked the wrong geometry, I'd like to exit instead of having to go through the rest of the motions."
Thinking "if response == null, return"?
-
2 minutes ago, techbytesoftware.com said:
while(true) { //if u want t exit break; };
While (escape key is not pressed){
--commit CHook--
}
return
This was my initial thought, but I can't get it to recognize when the escape key is pressed.
I don't want it to exit at a specific time, I want it to exit when the user presses escape.
-
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);
} -
if (Geometry.RetrieveEntity(surface10) is Geometry roughDraftSurface10) { roughDraftSurface10.Level = roughSurf; roughDraftSurface10.Commit(); }
Changing from 'DraftSurface' to 'Geometry' fixed the level issue.
It works great! Thank you Roger
-
angle = Mastercam.Math.VectorManager.RadiansToDegrees(15)
Fixed the angle issue
This also fixed the 'not following arcs' issue.
-
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);
-
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:White line is customer supplied geometry.
Green is the offsetContour in both directions.
Surface is a draft surface at a negative value.
-
2 minutes ago, x4g said:
or you can pickup up the definition using the dumplib utility, (see pdf on dumplib in the sdk installer folder)
This is literal gold. Thank you.
-
Mastercam::CHookAPI::Database::
This was the key to finding the options/tools/methods ect ect.
I'm still not seeing any 'surface' commands though. Enlighten me?
Operation Linking
in Mastercam C-Hook, NET-Hook and VBScript Development
Posted
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?
https://github.com/UberGamz/SurfaceInterop (CLI)
https://github.com/UberGamz/Rotary-PD---Copy (Nethook)