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

Everything posted by JKLINE

  1. You are getting the same result? Or would you like me to send you another set of files? Using the same logic as the templist10.add(t.key) I also tried var chainEntity = Mastercam.Database.Geometry.RetrieveEntity(t.key); It gives a 'protection level' access error though.
  2. I'm seeing 24, 24, 25, and 25 in both chainEntityList AND it read the .Commit() line that same amount of times.
  3. There's a "modify length" button in Mastercam but I'm not seeing anything related in the NET-Hook API Reference. I found the ExtendShortenContourParams but that's related to operations. Am I missing it? Or will I need to create new geometry and delete the old geometry? (Or alter the endpoint location of the geometry)
  4. Almost a complete understanding. Shouldn't it be coloring ALL the entities in the chain? It's only changing the color for the FirstEntity. (there are 4 chains on level 75). var chainDetails = new Mastercam.Database.Interop.ChainDetails();// Preps the ChainDetails plugin var selectedChains = ChainManager.ChainAll(75);// Chains all geometry on level 75 var chainDirection = ChainDirectionType.CounterClockwise;// Going to be used to make sure all chains go the same direction foreach (var chain in selectedChains)// For each of the chains selected { templist10.Clear(); chain.Direction = chainDirection;//Makes all chains go same direction var chainData = chainDetails.GetData(chain);//Gets the data of the chain var chainEntityList = chainData.ChainEntities;//Creates a list of entities in (geometry format) the selected chain foreach (var t in chainEntityList)// For each entity in that chain { (t.Key).Color = 9; (t.Key).Commit(); }
  5. And that value isn't a {get:set} correct? So I can't just set it to 'false' instead of getting the value and if A then .... and if B then ....
  6. Update :: It only finds ONE match. Even though it checks all four chains. I've tried changing chainDirection and also looking for endpoints instead of startpoints. //If any entity in chain is color 12, loop through step 0, step 1, and step 2 //step 0 -- get entity //step 0 -- see if entity start point is crossover point (point from templist9) //step 0 -- if match, send to step 1 //step 0 -- if not match, get next entity and repeat step 0 //step 1 -- get entity //step 1 -- color 10 //step 1 -- get next entity //step 1 -- see if next entity start point is a crossover point (point from templist9) //step 1 -- if match, send next entity to step 2 //step 1 -- if not match, color 10 and send next entity to step 1 //step 2 -- get entity //step 2 -- color 11 //step 2 -- get next entity //step 2 -- see if next entity start point is a crossover point (point from templist9) //step 2 -- if match, send next entity to step 1 //step 2 -- if not match, color 11 and send next entity to step 2 var chainDetails = new Mastercam.Database.Interop.ChainDetails();// Preps the ChainDetails plugin var selectedChains = ChainManager.ChainAll(75);// Chains all geometry on level 75 var chainDirection = ChainDirectionType.CounterClockwise;// Going to be used to make sure all chains go the same direction foreach (var chain in selectedChains)// For each of the chains selected { templist10.Clear(); chain.Direction = chainDirection;//Makes all chains go same direction var chainData = chainDetails.GetData(chain);//Gets the data of the chain var chainEntityList = chainData.ChainEntities;//Creates a list of entities in (geometry format) the selected chain var step = 0;//Sets to step 0 (should be 0 until an entity on chain is found with start point matching crossover point) foreach (var t in chainEntityList)// For each entity in that chain { templist10.Add(t.Key.GetEntityID());// Changes to INT format foreach (var chainEntity in templist10)//For each chain entity in the selected chain { if (step == 1) { break;};//If step is 1 (match is found in chain for start point and point location) exit the loop through entities var entity = Geometry.RetrieveEntity(chainEntity);//Gets entity based on GeoID if (entity is ArcGeometry arc && step == 0)//If first entity is arc and at step 0 { arcX1 = arc.EndPoint1.x; // Arc 1 x 1 arcX2 = arc.EndPoint2.x; // Arc 1 x 2 arcY1 = arc.EndPoint1.y; // Arc 1 y 1 arcY2 = arc.EndPoint2.y; // Arc 1 y 2 arcStartPoint = new Point3D(arcX1, arcY1, 0.0); // Arc 1 start point arcEndPoint = new Point3D(arcX2, arcY2, 0.0); // Arc 1 end point firstEntity = 1; // Saves that first entity is Arc foreach (var v in tempList9)// For each point marked as crossover location { var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID if (w is PointGeometry point && step == 0)//Confirms GeoID is a point and checks we are on step 0 { var ux = point.Data.x;// X location of point var uy = point.Data.y;// Y location of point Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location var arcStartDistance = Math.Abs(VectorManager.Distance(uPoint, arcEndPoint));// Distance between entity start point and crossover point if (arcStartDistance <= tolerance)// If distance is less than tolerance, complete task { entity.Color = 10;// Changes color of entity to 10 entity.Commit();// Saves entity into Mastercam Database step = 1;// Sets step to 1 break;//Exits the check to see if entity start point matches point location } } } } if (entity is LineGeometry line && step == 0)//If first entity is line and at step 0 { lineX1 = line.EndPoint1.x; // line 1 x 1 lineX2 = line.EndPoint2.x; // line 1 x 2 lineY1 = line.EndPoint1.y; // line 1 y 1 lineY2 = line.EndPoint2.y; // line 1 y 2 lineStartPoint = new Point3D(lineX1, lineY1, 0.0); // Line 1 start point lineEndPoint = new Point3D(lineX2, lineY2, 0.0); // Line 1 end point firstEntity = 2; // Saves that first entity is Line foreach (var v in tempList9)// For each point marked as crossover location { var w = PointGeometry.RetrieveEntity(v);// Gets point based on GeoID if (w is PointGeometry point && step == 0)//Confirms GeoID is a point and checks we are on step 0 { var ux = point.Data.x;// X location of point var uy = point.Data.y;// Y location of point Point3D uPoint = new Point3D(ux, uy, 0.0);// Saves point location var lineStartDistance = Math.Abs(VectorManager.Distance(uPoint, lineEndPoint));// Distance between entity start point and crossover point if (lineStartDistance <= tolerance)// If distance is less than tolerance, complete task { entity.Color = 10;// Changes color of entity to 10 entity.Commit();// Saves entity into Mastercam Database step = 1;// Sets step to 1 break;//Exits the check to see if entity start point matches point location } } } } } } }
  7. Roger, I appreciate your patience. My studies have been in Javascript and Kotlin so it's a little bit of a culture shock. I'd just like to confirm that it's possible for entities to be flipped in the middle of a chain. For example, for lack of better explanation, entity1 = false, entity2 = true, entity3 = false.
  8. Ah yes, the part I was missing was that the Key is not the GeometryID and I also forgot that a list can be geometry, not just INT . Is the list in order? Meaning, I could call t.key[0] for example and t.key[1] would be the connecting entity?
  9. Roger, As I understand this, 'var chainEntityList = chainData.ChainEntities' is a geometry entity and also a bool for the "flip". It is however a list. I'm not sure how to go about using the list, or extracting those entityIDs into another list. Is this a key/map/array situation? Thanks foreach (var t in chainEntityList){ templist10.Add(Geometry.RetrieveEntity(t));
  10. I'm having a weird result when I offset my chains ( I made sure everything is in the same CW direction) and it only happens in 2 places even though 2 of the same exact shapes turned out to be correct. The top left shape and the bottom right shape are correct but the top right shape and bottom left shape are wrong, and only in that one radius. Is this an example of a 'flipped' chain?
  11. The offsetchain is ending up on the level I want it to. One of the current issues is that the initially selected geometry also goes with it. Even though it's in its' own 'void' and the second 'void' unselects all geometry and refreshes everything ect ect. So it'll offset the geo i have on level 75 to level 501 and level 502, but then when I run the same exact code for level 76, the offset result ends up on level 501 and 502 but the starting geometry from level 75 also goes to level 502. Vice Versa if I put 76 before the 75 code.
  12. Why does my list appear to be empty? I can tell the error is before line "foreach (var t in chainEntityList){" and after "foreach (var chain in selectedChains)[" var selectedChains = ChainManager.ChainAll(75); foreach (var chain in selectedChains){ ChainData data = new ChainData(); var chainEntityList = data.ChainEntities; foreach (var t in chainEntityList){ var chainKey = t.Key; var chainValue = t.Value; templist10.Add(chainKey.GetEntityID()); System.Windows.Forms.MessageBox.Show("ChainGeometry"); foreach (var chainEntity in templist10){ var entity = Geometry.RetrieveEntity(chainEntity);
  13. Your changes did fix the 'crease bug' but it does move the initial entities to the final destination. In this case, it took from level 101 and moved it to 502. All the colors were rendered at color 1 (I think it's the default when color is not specified) but I'm seeing that you clearly are passing the data and I'm not finding any linking issues. How very odd.
  14. It does however remove any "containment" in the geometry selection. Is this because I need to use more specific operation selections? Such as, chainBasedOperation? I do not see a surfaceBasedOperation (which is where the containment was lost.
  15. Awesome, thank you. Works like a charm void ChangeOperations(){ var rotaryPD = 0.0; DialogManager.AskForNumber("Enter New Rotary PD", ref rotaryPD); OperationsManager.RefreshOperationsManager(true); var operationIDs = SearchManager.GetOperationIDs(true); var axisParams = new RotaryAxisParams { Enabled = true, Diameter = rotaryPD, Type = RotaryAxisPositionType.AxisSubstitution, Direction = RotaryAxisDirection.CW, AxisSubstitution = RotaryAxisSubstitution.SubsituteX }; foreach (var opID in operationIDs){ var op = SearchManager.GetOperation(opID); op.RotaryAxis = axisParams; op.MarkDirty(); op.Commit(); } OperationsManager.RefreshOperationsManager(true); } ChangeOperations(); return MCamReturn.NoErrors;
  16. I also had to change "var axisSub = new RotaryAxisSubstitution". But everything works other than that, thank you. Additionally, it does not make ALL the operations dirty, only some of them. Should I have it regen the toolpaths just in case? void ChangeOperations(){ var rotaryPD = 0.0; DialogManager.AskForNumber("Enter New Rotary PD", ref rotaryPD); OperationsManager.RefreshOperationsManager(true); var operationIDs = SearchManager.GetOperationIDs(true); var axisParams = new RotaryAxisParams { Enabled = true, Diameter = rotaryPD, Type = RotaryAxisPositionType.AxisSubstitution }; foreach (var opID in operationIDs) { var op = SearchManager.GetOperation(opID); op.RotaryAxis = axisParams; op.Commit(); } OperationsManager.RefreshOperationsManager(true); } ChangeOperations();
  17. I'm looking at a mass edit to change all of the rotary diameter's in the toolpaths. Later to edit other boxes and even later creating toolpaths. It wouldn't let me add the OperationIDs to a list unless I labeled the list as <int[]> do they have a different ID system than geometry? I believed I have set up the parameters for the RotaryAxisParams but I'm not sure how to load it into the operation. My best guess is that it has something to do with my list not populating correctly. void changeOperations() { var operations = new List<int[]>(); var rotaryPD = 0.0; DialogManager.AskForNumber("Enter New Rotary PD", ref rotaryPD); OperationsManager.RefreshOperationsManager(true); operations.Add(SearchManager.GetOperationIDs(true)); var axisSub = new RotaryAxisSubstitution{ }; var axisParams = new RotaryAxisParams{ Enabled = true, Diameter = rotaryPD, AxisSubstitution = axisSub }; foreach (var selectedOperation in operations){ selectedOperation.RotaryAxis = axisParams; selectedOperation.commit(); } OperationsManager.RefreshOperationsManager(true); } changeOperations();
  18. Zaffin_D, I blocked out (/* */) the second half of the UtilitiesFacade.cs and only kept the void OffsetCutChain and that worked out for me. Although, your code seems to have the same error that mine does. Whatever is on the first starting level gets moved to a new level. The geo on level 76 ended on level 502 while geo from level 75 stayed on level 75. If I call 75 first, 75 ends up on 502 and geo on level 76 stays on level 76. utilities.OffsetCutChain(76, lowerCut, upperCut); utilities.OffsetCutChain(75, lowerCut2, upperCut2); I have put the MCAM file I am working to in the gitHub folder https://github.com/UberGamz/CustomNethook
  19. My current issue is that it moves my geometry. For example, if I call offset_75 before offset_76 it will move the geometry on level 75 to level 502 (the last 'move to level' line). If I call offset_76 before offset_75 it moves all the geometry from level 76 to level 502. I thought I was being diligent about unselecting all geometry, clearColors, Repaint, but it still seems to grab the geometry. void offsetCutchain75(){ SelectionManager.UnselectAllGeometry(); LevelsManager.RefreshLevelsManager(); LevelsManager.SetMainLevel(75); var shown = LevelsManager.GetVisibleLevelNumbers(); foreach (var level in shown){ LevelsManager.SetLevelVisible(level, false); } LevelsManager.SetLevelVisible(75, true); LevelsManager.RefreshLevelsManager(); GraphicsManager.Repaint(true); var selectedCutChain = ChainManager.ChainAll(75); var chainDirection = ChainDirectionType.Clockwise; int createdUpperLevel = 500; int createdLowerLevel = 501; LevelsManager.SetLevelName(500, "Upper Created Cut Geo"); LevelsManager.SetLevelName(501, "Lower Created Cut Geo"); foreach (var chain in selectedCutChain){ chain.Direction = chainDirection; var lowerChainLarge = chain.OffsetChain2D(OffsetSideType.Right, .0225, OffsetRollCornerType.None, .5, false, .005, false); var lowerChainSmall = chain.OffsetChain2D(OffsetSideType.Left, .0025, OffsetRollCornerType.None, .5, false, .005, false); var cutResultGeometry = SearchManager.GetResultGeometry(); foreach (var entity in cutResultGeometry){ entity.Color = 11; entity.Selected = true; entity.Commit(); } GeometryManipulationManager.MoveSelectedGeometryToLevel(createdLowerLevel, true); GraphicsManager.ClearColors(new GroupSelectionMask(true)); var upperChainLarge = chain.OffsetChain2D(OffsetSideType.Right, .0025, OffsetRollCornerType.None, .5, false, .005, false); var upperChainSmall = chain.OffsetChain2D(OffsetSideType.Left, .0385, OffsetRollCornerType.None, .5, false, .005, false); var cutResultGeometryNew = SearchManager.GetResultGeometry(); foreach (var entity in cutResultGeometryNew){ entity.Color = 10; entity.Selected = true; entity.Commit(); } GeometryManipulationManager.MoveSelectedGeometryToLevel(createdUpperLevel, true); GraphicsManager.ClearColors(new GroupSelectionMask(true)); } } void offsetCutchain76(){ SelectionManager.UnselectAllGeometry(); LevelsManager.RefreshLevelsManager(); LevelsManager.SetMainLevel(76); var shown = LevelsManager.GetVisibleLevelNumbers(); foreach (var level in shown){ LevelsManager.SetLevelVisible(level, false); } LevelsManager.SetLevelVisible(76, true); LevelsManager.RefreshLevelsManager(); GraphicsManager.Repaint(true); var selectedCutChain = ChainManager.ChainAll(76); var chainDirection = ChainDirectionType.Clockwise; int createdUpperLevel = 500; int createdLowerLevel = 501; LevelsManager.SetLevelName(500, "Upper Created Cut Geo"); LevelsManager.SetLevelName(501, "Lower Created Cut Geo"); foreach (var chain in selectedCutChain){ chain.Direction=chainDirection; var lowerChainLarge = chain.OffsetChain2D(OffsetSideType.Left, .0225, OffsetRollCornerType.None, .5, false, .005, false); var lowerChainSmall = chain.OffsetChain2D(OffsetSideType.Right, .0025, OffsetRollCornerType.None, .5, false, .005, false); var cutResultGeometry = SearchManager.GetResultGeometry(); foreach (var entity in cutResultGeometry){ entity.Color = 11; entity.Selected = true; entity.Commit(); } GeometryManipulationManager.MoveSelectedGeometryToLevel(createdLowerLevel, true); GraphicsManager.ClearColors(new GroupSelectionMask(true)); var upperChainLarge = chain.OffsetChain2D(OffsetSideType.Left, .0025, OffsetRollCornerType.None, .5, false, .005, false); var upperChainSmall = chain.OffsetChain2D(OffsetSideType.Right, .0385, OffsetRollCornerType.None, .5, false, .005, false); var cutResultGeometryNew = SearchManager.GetResultGeometry(); foreach (var entity in cutResultGeometryNew){ entity.Color = 10; entity.Selected = true; entity.Commit(); } GeometryManipulationManager.MoveSelectedGeometryToLevel(createdUpperLevel, true); GraphicsManager.ClearColors(new GroupSelectionMask(true)); } }
  20. I used an excerpt of your code to start understanding where my code is going wrong. The code you provided creates moves and alters level 101. I purposely left out the call to the "crease" parts of the code. This is very similar to my current issue. Did I load it incorrectly? var utilities = new UtilitiesFacade(); var lowerCut = new EntityData() { ColorID = 11, SmallOffsetRadius = 0.0025, LargeOffsetRadius = 0.0225, Level = new LevelData(501, "Lower Created Cut Geo") }; var upperCut = new EntityData() { ColorID = 10, SmallOffsetRadius = 0.0025, LargeOffsetRadius = 0.0385, Level = new LevelData(500, "Upper Created Cut Geo") }; utilities.OffsetCutChain(75, lowerCut, upperCut);
  21. I find myself starring at the screen instead of making any progress. I have attached the before and after photo of my intent. Would this particular instance be easier with strings? My current code works at coloring entities that start with a point (one of the shown orange ones to be specific) and it's listed below. I believe my logic is correct, but am going about it the incorrect manner. Any assist is appreciated! Logic :: GET ALL CHAIN PIECES COLOR ALL ENTITIES COLOR 3 (CHECKS TO SEE WHAT'S LEFT) IF ANY ENTITIES ARE COLOR 3 THEN LOOP FIND START POINT (N1) IF START POINT = aPOINT THEN COLOR 2 AND FIND NEXT CONNECTING SEGMENT AND GOTO N2 IF START POINT =/= aPOINT THEN FIND NEXT CONNECTING SEGMENT AND GOTO N1 FIND END POINT (N2) IF ENDPOINT = aPOINT THEN COLOR 2 AND FIND NEXT CONNECTING SEGMENT GOTO N3 IF ENDPOINT =/= aPOINT THEN COLOR 2 AND FIND NEXT CONNECTING SEGMENT AND GOTO N2 FIND NEXT START POINT (N3) IF START POINT = aPOINT THEN COLOR 2 AND FIND NEXT CONNECTING SEGMENT AND GOTO N2 IF START POINT =/= aPOINT THEN COLOR 1 AND FIND NEXT CONNECTING SEGMENT AND GOTO N3 FIND NEXT CONNECTING SEGMENT IF FIRST ENTITY ENDPOINT = SECOND ENTITY STARTPOINT THEN isNextSegment & RETURN ENTITY ID# IF FIRST ENTITY ENDPOINT =/= SECOND ENTITY STARTPOINT THEN isNotNextSegment & LOOP UNTIL TRUE foreach (var i in tempList8){ var GeoID = Geometry.RetrieveEntity(i); var firstEntity = 0; var secondEntity = 0; if (GeoID is ArcGeometry arc){ // if first entity is arc arcX1 = arc.EndPoint1.x; // Arc 1 x 1 arcX2 = arc.EndPoint2.x; // Arc 1 x 2 arcY1 = arc.EndPoint1.y; // Arc 1 y 1 arcY2 = arc.EndPoint2.y; // Arc 1 y 2 arcStartPoint = new Point3D(arcX1, arcY1, 0.0); arcEndPoint = new Point3D(arcX2, arcY2, 0.0); firstEntity = 1; } if (GeoID is LineGeometry line){ // if first entity is line lineX1 = line.EndPoint1.x; // line 1 x 1 lineX2 = line.EndPoint2.x; // line 1 x 2 lineY1 = line.EndPoint1.y; // line 1 y 1 lineY2 = line.EndPoint2.y; // line 1 y 2 lineStartPoint = new Point3D(lineX1, lineY1, 0.0); lineEndPoint = new Point3D(lineX2, lineY2, 0.0); firstEntity = 2; } foreach (var u in tempList8){ var nextGeoID = Geometry.RetrieveEntity(u); if (nextGeoID is ArcGeometry nextarc){ // if second entity is arc nextarcX1 = nextarc.EndPoint1.x; // Arc 2 x 1 nextarcX2 = nextarc.EndPoint2.x; // Arc 2 x 2 nextarcY1 = nextarc.EndPoint1.y; // Arc 2 y 1 nextarcY2 = nextarc.EndPoint2.y; // Arc 2 y 2 nextarcStartPoint = new Point3D(nextarcX1, nextarcY1, 0.0); nextarcEndPoint = new Point3D(nextarcX2, nextarcY2, 0.0); secondEntity = 1; } if (nextGeoID is LineGeometry nextline){ // if second entity is line nextlineX1 = nextline.EndPoint1.x; // line 2 x 1 nextlineX2 = nextline.EndPoint2.x; // line 2 x 2 nextlineY1 = nextline.EndPoint1.y; // line 2 y 1 nextlineY2 = nextline.EndPoint2.y; // line 2 y 2 nextlineStartPoint = new Point3D(nextlineX1, nextlineY1, 0.0); nextlineEndPoint = new Point3D(nextlineX2, nextlineY2, 0.0); secondEntity = 2; } if ((firstEntity == 1) && (secondEntity == 1)){ foreach (var v in tempList9){ var w = PointGeometry.RetrieveEntity(v); if (w is PointGeometry point){ var ux = point.Data.x; var uy = point.Data.y; Point3D uPoint = new Point3D(ux, uy, 0.0); var startDistance = Math.Abs(VectorManager.Distance(uPoint, arcStartPoint)); var endDistance = Math.Abs(VectorManager.Distance(uPoint, arcEndPoint)); if (startDistance <= tolerance){ GeoID.Color = 10; GeoID.Commit(); } } } }//If arc and arc if ((firstEntity == 1) && (secondEntity == 2)){}//If arc and line if ((firstEntity == 2) && (secondEntity == 1)){}//If line and arc if ((firstEntity == 2) && (secondEntity == 2)){}//If line and line } }
  22. This is outstanding! Definitely hits me like a brick and it's certainly shows I have a lot to learn about C#. It's so clean and organized I'm going to use this as a reference when I'm finished so I can make the code faster. I imagine the DWG files I'll be working with are going to get quite complicated.
  23. Roger, To clarify, I tried the BreakAtMidpoint method but it gave me 3 arcs instead of 2 so I decided to try another method which seems to be working.

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