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:

Roger Martin from CNC Software

CNC Software
  • Posts

    2,870
  • Joined

  • Last visited

  • Days Won

    6

Everything posted by Roger Martin from CNC Software

  1. Shoot an email to [email protected] with all your company contact info. Also, if you send a message to sdk inbox, I can reply to that with the "How to figure out which lib file is missing!" document.
  2. https://my.mastercam.com/communities/3rd-party-developers/c-hook-downloads/ Under "Mastercam C-Hook documents", see the "How to figure out which lib file is missing!" document.
  3. JKLINE, You are looking to create a Draft surface with a NET-Hook add-in?
  4. Also... It does not appear to make a different in the output in "this" case, but... // Be careful doing '=' or '!=' comparisons of floating point values. //if (chain.Area != t.Area) // No if (Math.Abs(chain.Area - t.Area) < Mastercam.IO.SettingsManager.SystemTolerance) // Yes, check against some tolerance
  5. 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; Result -> Yes, you can share the ChainDataInterop project.
  6. Below is an image of the end-result Level Manager I get. I see 49 entities on Level #80 and 49 entities on Level #81. So where is “geometry on level 81 gets moved” ? -------------------------------- After you have done an XForm operation the resulting entities are marked by Mastercam as a “result” group. You should be able to retrieve those entities that are a “result of the last Xform” doing this. var resultGeom = SearchManager.GetResultGeometry(); ------------------------- Get rid of the lines setting an array = null e.g. The last 4 lines of the translate method - // NOT needed tempSelectedGeometry1Result = null tempSelectedGeometry1 = null; tempSelectedGeometry2Result = null; tempSelectedGeometry2 = null; And other locations in the code - selectedGeometry = null; // NOT needed //ask to reclaim the memory from the list System.GC.Collect(); // NOT needed Will these cause problems? Probably not, but the are not needed and just add "noise" to the code.
  7. Break it down... Create a method that does just the "move" of the geometry. Work out that process out in isolation of all the 'other' code. Once you know that it works and how it works, you can concentrate your efforts on the other code in your add-in. This is "Clear Color" that clears the Group/Result markings on geometry. Probably not going to help and maybe *not* want you want. See NOTE below. No. Just no. Is this what is happening? I am restating basically what x4g said here. -> "If you translate something make sure you call retrieve on the entity if you are holding a list of pointers to the entities," Your add-in has selected geometry, then is translates/rotates/moves that geometry using some XForm method. After the XForm operation are you then still "looking" at the original geometry your add-in holds in a list? Looking at the docs for: GeometryManipulationManager.TranslateGeometry Method GeometryManipulationManager.CopySelectedGeometryToLevel Method Etc. -> NOTE! Any Geometry objects that get altered will NOT be reflected in that entity's data "on the NET-Hook side" if that entity's data is being held in a NET-Hook Geometry object! You can use GetResultGeometry() to retrieve the result of the XForm operation.
  8. Corrupt in what way? If you do Statistics on the file after the run, are the missing entities included in the count? If you remove the shortenChain### calls, does that make a difference? If you do a rebuild graphics after the run, does that make a difference? Since I have almost nothing to go on there, I'm reduced to guessing.
  9. In the NET-Hook API there is a Area property on a Chain Chain.Area Property Gets the area within the chain, assuming it's closed. Namespace: Mastercam.Database public double Area { get; }
  10. A "chain nested inside of another chain" should not make any difference. I would suggest "breaking down your process" and then building it back step-by-step. To start forget about doing the level manipulations, etc. ? -> Starting with level 80, it creates level 500 which should match level 200 and it creates level 501 which should match level 300 First, nail down just the first step you want to do with the chains. (e.g. Offsetting the Chains) Once you have that figured out, then you can add back in the other processes your add-in is supposed to do.
  11. In the NET-Hook API [https://nethookdocs.mastercam.com] Version History - Mastercam 2023 -> Added: FilletChain method to the GeometryManipulationManager class. Mastercam.GeometryUtility.Types.FilletChainsParams Mastercam.GeometryUtility.Types.BreakManyPiecesParameters Mastercam.GeometryUtility.Types -> FilletStyle Enumeration Mastercam.GeometryUtility.Types -> ReFilletOption Enumeration We do have a sample 2023 NET-Hook project that demos this "new in 2023" functionality.
  12. So.... It appears al the chains should now be going Clockwise. Can we verify that? The only other thin here is the OffsetChain2D that we assume worked proper for each chain, so that's probably not the issue. With a clockwise Chain and OffsetSidedType.Right it looks like you are wanting to new offset chain to be "inside" the original chain. If you cannot get the OffsetChain2D result to be "correct", lease send us the geometry file and the offsetting code you are using.
  13. I do not know what is meant by this. -> You have geometry on a level. You chain all “this level”. I think this would work to get all the chains going the same direction: CW or CCW Loop through the chains and set the Direction of each chain to the desired ChainDirectionType Now are not all the chains going the same direction? Now that you know the chain’s direction you can know which “side” to use in the OffsetChains2D call.
  14. chain.OffsetChain2D in the NET-Hook API is doing what you can via Mastercam’s UI with (Wireframe) Offset Chains. If there is something you can do via the Offset Chains UI that cannot be done with a NET-Hook, let us know and we will investigate.
  15. Something file in your memory about the NET-Hook API - Whenever you are doing Commit on an Operation. If you have not altered the geometry (chains, drill points, etc.) assigned to that operation. In other words, you are just updating "parameters" of the operation. Use the Commit overload that takes a boolean parameter and pass "false" -> op.Commit(false); "false" here tells it not to look at (or touch) the geometry in the operation when doing the Commit (update).
  16. Try this (it may or may not help) - Change the Commit calls on the operations to include the 'false' parameter. op.Commit(false);
  17. What is the exact operation "type" you are altering here? A Surface operation? => Not with the NET-Hook API as this time.
  18. 1> What is the goal of this add-in? I’ve read the Logic:: description. (Not that I understood it.) I see the image you posted, but that itself doesn’t help me know that me what the process is supposed to be. 2> This is just a code fragment (albeit a very large one!) It has many repeated code sections. I would suggest breaking it down. * Trying to follow logic through a 1300+ lines of code in one method is going to cause you grief. 3> Why the templist9 and templist10 that contain the geometry entity IDs? Seems it may be an unnecessary complication. *Example: Don’t repeat code if possible. Break that out to its own method. This section of code is essentially repeated 40+ times! (Copy/Paste is not your friend here.) //foreach (var v in tempList9) //{ // var w = Geometry.RetrieveEntity(v);// Gets point based on GeoID // if (w is PointGeometry point) // { // 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 entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint); // if (entityPointDistance <= tolerance) // { // step = 4; // } // } //} if (SearchTempList9(tempList9, nextArcStartPoint)) { step = 4; } A single method to call can replace those instances of repeated code. ///<summary> Search the list of entities for a matching point position </summary> /// ///<param name="entIdList"> The list of entity IDs to search </param> ///<param name="pt"> The point position to look for in the list </param>\ /// ///<returns> Thrue if a match was found, else false </returns> private bool SearchTempList9(List<int> entIdList, Point3D pt) { foreach (var entId in entIdList) { var geom = Geometry.RetrieveEntity(entId); if (geom is PointGeometry point) { var ux = point.Data.x; // X location of point var uy = point.Data.y; // Y location of point var uPoint = new Point3D(ux, uy, 0.0); // Saves point location var entityPointDistance = VectorManager.Distance(uPoint, pt); if (entityPointDistance <= tolerance) { return true; } } } return false; } The code below builds but is not tested. (since I do not know exactly want it is supposed to do!) Could I have introduced new bugs to this quick & dirty refactoring or the code>? Absolutely. using System; using System.Collections.Generic; using Mastercam.BasicGeometry; using Mastercam.Curves; using Mastercam.Database; using Mastercam.Database.Types; using Mastercam.Math; namespace Customer { public class Support { private double tolerance = Mastercam.IO.SettingsManager.SystemTolerance; private List<int> tempList9 = new List<int>(); private List<int> templist10 = new List<int>(); public void DoIt() { double entityStartDistance; double entityEndDistance; Point3D lineStartPoint; Point3D lineEndPoint; Point3D nextLineStartPoint; Point3D nextLineEndPoint; Point3D arcStartPoint; Point3D arcEndPoint; Point3D nextArcStartPoint; Point3D nextArcEndPoint; var firstEntity = 0; var step = 0; 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 ChainManager.StartChainAtLongest(selectedChains); foreach (var chain in selectedChains) { var chainData = chainDetails.GetData(chain); var chainEntityList = chainData.ChainEntities; foreach (var t in chainEntityList) { (t.Key).Color = 9; (t.Key).Commit(); } } foreach (var chain in selectedChains) { templist10.Clear(); step = 0; chain.Direction = chainDirection; var chainEntity = ChainManager.GetGeometryInChain(chain); if (step == 0) { System.Windows.Forms.MessageBox.Show("step 0"); foreach (var entity in chainEntity) { if (entity is ArcGeometry arc && step == 0) { step = SearchTempList9Arcs(entity, step); } else if (entity is LineGeometry line && step == 0) { step = SearchTempList9Lines(entity, step); } } } if (step == 1) { System.Windows.Forms.MessageBox.Show("step 1"); foreach (var entity in chainEntity) { if (firstEntity == 1 && step == 1) { var thisEntity = Geometry.RetrieveEntity(templist10[0]); if (thisEntity is ArcGeometry arc && step == 1) { GetEndPoints(arc, out arcStartPoint, out arcEndPoint); if (entity is ArcGeometry nextArc && (entity.GetEntityID() != templist10[0]) && step == 1) { GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint); entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint); entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint); if (entityStartDistance <= tolerance && step == 1) { UpdateEntityColorAndList10(entity, 10); step = 2; firstEntity = 1; if (SearchTempList9(tempList9, nextArcEndPoint)) { step = 3; } } if (entityEndDistance <= tolerance && step == 1) { UpdateEntityColorAndList10(entity, 10); step = 4; firstEntity = 1; if (SearchTempList9(tempList9, nextArcStartPoint)) { step = 3; } } } if (entity is LineGeometry nextLine && (entity.GetEntityID() != templist10[0]) && step == 1) { GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint); entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint); entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint); if (entityStartDistance <= tolerance && step == 1) { UpdateEntityColorAndList10(entity, 10); step = 2; firstEntity = 2; if (SearchTempList9(tempList9, nextLineEndPoint)) { step = 3; } } if (entityEndDistance <= tolerance && step == 1) { UpdateEntityColorAndList10(entity, 10); step = 4; firstEntity = 2; if (SearchTempList9(tempList9, nextLineStartPoint)) { step = 3; } } } } } if (firstEntity == 2 && step == 1) { var thisEntity = Geometry.RetrieveEntity(templist10[0]); if (thisEntity is LineGeometry line && step == 1) { GetEndPoints(line, out lineStartPoint, out lineEndPoint); if (entity is ArcGeometry nextArc && (entity.GetEntityID() != templist10[0]) && step == 1) { GetEndPoints(entity as ArcGeometry, out nextArcStartPoint, out nextArcEndPoint); entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint); entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint); if (entityStartDistance <= tolerance && step == 1) { UpdateEntityColorAndList10(entity, 10); step = 2; firstEntity = 1; if (SearchTempList9(tempList9, nextArcEndPoint)) { step = 3; } } if (entityEndDistance <= tolerance && step == 1) { UpdateEntityColorAndList10(entity, 10); step = 4; firstEntity = 1; if (SearchTempList9(tempList9, nextArcStartPoint)) { step = 3; } } } if (entity is LineGeometry nextLine && (entity.GetEntityID() != templist10[0]) && step == 1) { GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint); entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint); entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint); if (entityStartDistance <= tolerance && step == 1) { UpdateEntityColorAndList10(entity, 10); step = 2; firstEntity = 2; if (SearchTempList9(tempList9, nextLineEndPoint)) { step = 3; } } if (entityEndDistance <= tolerance && step == 1) { UpdateEntityColorAndList10(entity, 10); step = 4; firstEntity = 2; if (SearchTempList9(tempList9, nextLineStartPoint)) { step = 3; } } } } } } } if (step == 2) { System.Windows.Forms.MessageBox.Show("step 2"); foreach (var entity in chainEntity) { if (firstEntity == 1 && step == 2) { var thisEntity = Geometry.RetrieveEntity(templist10[0]); if (thisEntity is ArcGeometry arc && step == 2) { GetEndPoints(arc, out arcStartPoint, out arcEndPoint); if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 2) { GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint); entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint); entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint); if (entityStartDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 2; firstEntity = 1; if (SearchTempList9(tempList9, nextArcEndPoint)) { step = 3; } } if (entityEndDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 4; firstEntity = 1; if (SearchTempList9(tempList9, nextArcStartPoint)) { step = 5; } } } if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 2) { GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint); entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint); entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint); if (entityStartDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 2; firstEntity = 2; if (SearchTempList9(tempList9, nextLineEndPoint)) { step = 3; } } if (entityEndDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 4; firstEntity = 2; if (SearchTempList9(tempList9, nextLineStartPoint)) { step = 5; } } } } } if (firstEntity == 2 && step == 2) { var thisEntity = Geometry.RetrieveEntity(templist10[0]); if (thisEntity is LineGeometry line && step == 2) { GetEndPoints(line, out lineStartPoint, out lineEndPoint); if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 2) { GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint); entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint); entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint); if (entityStartDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 2; firstEntity = 1; if (SearchTempList9(tempList9, nextArcEndPoint)) { step = 3; } } if (entityEndDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 4; firstEntity = 1; if (SearchTempList9(tempList9, nextArcStartPoint)) { step = 5; } } } if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 2) { GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint); entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint); entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint); if (entityStartDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 2; firstEntity = 2; if (SearchTempList9(tempList9, nextLineEndPoint)) { step = 3; } } if (entityEndDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 4; firstEntity = 2; if (SearchTempList9(tempList9, nextLineStartPoint)) { step = 5; } } } } } } } // Gets Geo that connects first entity end point to second entity start point (offset 2) if (step == 3) { System.Windows.Forms.MessageBox.Show("step 3"); foreach (var entity in chainEntity) { if (firstEntity == 1 && step == 3) { var thisEntity = Geometry.RetrieveEntity(templist10[0]); if (thisEntity is ArcGeometry arc && step == 3) { GetEndPoints(arc, out arcStartPoint, out arcEndPoint); if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 3) { GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint); entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint); entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint); if (entityStartDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 3; firstEntity = 1; if (SearchTempList9(tempList9, nextArcEndPoint)) { step = 2; } } if (entityEndDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 5; firstEntity = 1; if (SearchTempList9(tempList9, nextArcStartPoint)) { step = 4; } } } if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 3) { GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint); entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint); entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint); if (entityStartDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 3; firstEntity = 2; if (SearchTempList9(tempList9, nextLineEndPoint)) { step = 2; } } if (entityEndDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 5; firstEntity = 2; if (SearchTempList9(tempList9, nextLineStartPoint)) { step = 4; } } } } } if (firstEntity == 2 && step == 3) { var thisEntity = Geometry.RetrieveEntity(templist10[0]); if (thisEntity is LineGeometry line && step == 3) { GetEndPoints(line, out lineStartPoint, out lineEndPoint); if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 3) { GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint); entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint); entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint); if (entityStartDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 3; firstEntity = 1; if (SearchTempList9(tempList9, nextArcEndPoint)) { step = 2; } } if (entityEndDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 5; firstEntity = 1; if (SearchTempList9(tempList9, nextArcStartPoint)) { step = 4; } } } if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 3) { GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint); entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint); entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint); if (entityStartDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 3; firstEntity = 2; if (SearchTempList9(tempList9, nextLineEndPoint)) { step = 2; } } if (entityEndDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 5; firstEntity = 2; if (SearchTempList9(tempList9, nextLineStartPoint)) { step = 4; } } } } } } } // Gets Geo that connects first entity end point to second entity start point (offset 1) if (step == 4) { System.Windows.Forms.MessageBox.Show("step 4"); foreach (var entity in chainEntity) { if (firstEntity == 1 && step == 2) { var thisEntity = Geometry.RetrieveEntity(templist10[0]); if (thisEntity is ArcGeometry arc && step == 2) { GetEndPoints(arc, out arcStartPoint, out arcEndPoint); if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 2) { GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint); entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint); entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint); if (entityStartDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 2; firstEntity = 1; if (SearchTempList9(tempList9, nextArcEndPoint)) { step = 3; } } if (entityEndDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 4; firstEntity = 1; if (SearchTempList9(tempList9, nextArcStartPoint)) { step = 5; } } } if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 2) { GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint); entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint); entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint); if (entityStartDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 2; firstEntity = 2; if (SearchTempList9(tempList9, nextLineEndPoint)) { step = 3; } } if (entityEndDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 4; firstEntity = 2; if (SearchTempList9(tempList9, nextLineStartPoint)) { step = 5; } } } } } if (firstEntity == 2 && step == 2) { var thisEntity = Geometry.RetrieveEntity(templist10[0]); if (thisEntity is LineGeometry line && step == 2) { GetEndPoints(line, out lineStartPoint, out lineEndPoint); if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 2) { GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint); entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint); entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint); if (entityStartDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 2; firstEntity = 1; if (SearchTempList9(tempList9, nextArcEndPoint)) { step = 3; } } if (entityEndDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 4; firstEntity = 1; if (SearchTempList9(tempList9, nextArcStartPoint)) { step = 5; } } if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 2) { GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint); entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint); entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint); if (entityStartDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 2; firstEntity = 2; if (SearchTempList9(tempList9, nextLineEndPoint)) { step = 3; } } if (entityEndDistance <= tolerance && step == 2) { UpdateEntityColorAndList10(entity, 10); step = 4; firstEntity = 2; if (SearchTempList9(tempList9, nextLineStartPoint)) { step = 5; } } } } } } } // Gets Geo that connects first entity start point to second entity start point (offset 2) if (step == 5) { System.Windows.Forms.MessageBox.Show("step 5"); foreach (var entity in chainEntity) { if (firstEntity == 1 && step == 3) { var thisEntity = Geometry.RetrieveEntity(templist10[0]); if (thisEntity is ArcGeometry arc && step == 3) { GetEndPoints(arc, out arcStartPoint, out arcEndPoint); if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 3) { GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint); entityStartDistance = VectorManager.Distance(arcEndPoint, nextArcStartPoint); entityEndDistance = VectorManager.Distance(arcEndPoint, nextArcEndPoint); if (entityStartDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 3; firstEntity = 1; if (SearchTempList9(tempList9, nextArcEndPoint)) { step = 2; } } if (entityEndDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 5; firstEntity = 1; if (SearchTempList9(tempList9, nextArcStartPoint)) { step = 4; } } } if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 3) { GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint); entityStartDistance = VectorManager.Distance(arcEndPoint, nextLineStartPoint); entityEndDistance = VectorManager.Distance(arcEndPoint, nextLineEndPoint); if (entityStartDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 3; firstEntity = 2; if (SearchTempList9(tempList9, nextLineEndPoint)) { step = 2; } } if (entityEndDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 5; firstEntity = 2; if (SearchTempList9(tempList9, nextLineStartPoint)) { step = 4; } } } } } if (firstEntity == 2 && step == 3) { var thisEntity = Geometry.RetrieveEntity(templist10[0]); if (thisEntity is LineGeometry line && step == 3) { GetEndPoints(line, out lineStartPoint, out lineEndPoint); if (entity is ArcGeometry nextArc && (entity.Color != 10) && (entity.Color != 11) && step == 3) { GetEndPoints(nextArc, out nextArcStartPoint, out nextArcEndPoint); entityStartDistance = VectorManager.Distance(lineEndPoint, nextArcStartPoint); entityEndDistance = VectorManager.Distance(lineEndPoint, nextArcEndPoint); if (entityStartDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 3; firstEntity = 1; if (SearchTempList9(tempList9, nextArcEndPoint)) { step = 2; } } if (entityEndDistance <= tolerance && step == 3) { entity.Color = 11; entity.Commit(); templist10.Clear(); templist10.Add(entity.GetEntityID()); step = 5; firstEntity = 1; if (SearchTempList9(tempList9, nextArcStartPoint)) { step = 4; } //foreach (var v in tempList9) //{ // var w = Geometry.RetrieveEntity(v);// Gets point based on GeoID // if (w is PointGeometry point) // { // 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 entityPointDistance = VectorManager.Distance(uPoint, nextArcStartPoint); // if (entityPointDistance <= tolerance) // { // step = 4; // } // } //} } } if (entity is LineGeometry nextLine && (entity.Color != 10) && (entity.Color != 11) && step == 3) { GetEndPoints(nextLine, out nextLineStartPoint, out nextLineEndPoint); entityStartDistance = VectorManager.Distance(lineEndPoint, nextLineStartPoint); entityEndDistance = VectorManager.Distance(lineEndPoint, nextLineEndPoint); if (entityStartDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 3; firstEntity = 2; if (SearchTempList9(tempList9, nextLineEndPoint)) { step = 2; } } if (entityEndDistance <= tolerance && step == 3) { UpdateEntityColorAndList10(entity, 11); step = 5; firstEntity = 2; if (SearchTempList9(tempList9, nextLineStartPoint)) { step = 4; } } } } } } } // Gets Geo that connects first entity start point to second entity start point (offset 1) } } } ///<summary> Search the list of entities for a matching point position </summary> /// ///<param name="entIdList"> The list of entity IDs to search </param> ///<param name="pt"> The point position to look for in the list </param> /// ///<returns> Thrue if a match was found, else false </returns> private bool SearchTempList9(List<int> entIdList, Point3D pt) { foreach (var entId in entIdList) { var geom = Geometry.RetrieveEntity(entId); if (geom is PointGeometry point) { var ux = point.Data.x; // X location of point var uy = point.Data.y; // Y location of point var uPoint = new Point3D(ux, uy, 0.0); // Saves point location var entityPointDistance = VectorManager.Distance(uPoint, pt); if (entityPointDistance <= tolerance) { return true; } } } return false; } ///<summary> Search the list of entities for a matching point position </summary> /// ///<param name="entity"> The arc ntity to match </param> ///<param name="pt"> The point position to look for in the list </param> /// ///<returns> Thrue if a match was found, else false </returns> private int SearchTempList9Arcs(Geometry entity, int step) { if (entity is ArcGeometry arc && step == 0) { var arcStartPoint = new Point3D(); // Arc start point var arcEndPoint = new Point3D(); // Arc end point GetEndPoints(arc, out arcStartPoint, out arcEndPoint); foreach (var v in tempList9) { var w = Geometry.RetrieveEntity(v);// Gets point based on GeoID if (w is PointGeometry point && step == 0) { var ux = point.Data.x;// X location of point var uy = point.Data.y;// Y location of point var uPoint = new Point3D(ux, uy, 0.0);// Saves point location var arcStartDistance = Math.Abs(VectorManager.Distance(uPoint, arcStartPoint));// Distance between entity start point and crossover point var arcEndDistance = Math.Abs(VectorManager.Distance(uPoint, arcEndPoint));// Distance between entity end point and crossover point if (arcStartDistance <= tolerance /*&& step == 0*/) { entity.Color = 10;// Changes color of entity to 10 entity.Commit();// Saves entity into Mastercam Database templist10.Add(entity.GetEntityID()); step = 1;// Sets step to 1 } } } } return step; } ///<summary> Search the list of entities for a matching point position </summary> /// ///<param name="entity"> The line ntity to match </param> ///<param name="pt"> The point position to look for in the list </param> /// ///<returns> Thrue if a match was found, else false </returns> private int SearchTempList9Lines(Geometry entity, int step) { if (entity is LineGeometry line && step == 0) { var lineStartPoint = new Point3D(); // Line start point var lineEndPoint = new Point3D(); // Line end point GetEndPoints(line, out lineStartPoint, out lineEndPoint); foreach (var v in tempList9) { var w = Geometry.RetrieveEntity(v);// Gets point based on GeoID if (w is PointGeometry point && step == 0) { var ux = point.Data.x;// X location of point var uy = point.Data.y;// Y location of point var uPoint = new Point3D(ux, uy, 0.0);// Saves point location var lineStartDistance = Math.Abs(VectorManager.Distance(uPoint, lineStartPoint));// Distance between entity start point and crossover point var lineEndDistance = Math.Abs(VectorManager.Distance(uPoint, lineEndPoint));// Distance between entity end point and crossover point if (lineStartDistance <= tolerance && step == 0) { entity.Color = 10;// Changes color of entity to 10 entity.Commit();// Saves entity into Mastercam Database templist10.Add(entity.GetEntityID()); step = 1;// Sets step to 1 } } } } return step; } ///<summary> Get the start and end points of a line or arc entity. </summary> // /// <remarkis> The Z coordinate of the points is forced to be '0' </remarkis> /// ///<param name="geom"> The line or arc entity </param> ///<param name="startPt"> [out] The start point </param> ///<param name="endPt"> [out] The end point </param> private void GetEndPoints(Geometry geom, out Point3D startPoint, out Point3D endPoint) { if (geom is LineGeometry line) { startPoint = new Point3D(line.EndPoint1.x, line.EndPoint1.y, 0.0); endPoint = new Point3D(line.EndPoint2.x, line.EndPoint2.y, 0.0); } else if (geom is ArcGeometry arc) { startPoint = new Point3D(arc.EndPoint1.x, arc.EndPoint1.y, 0.0); endPoint = new Point3D(arc.EndPoint2.x, arc.EndPoint2.y, 0.0); } else { // TODO: Let the user that we where given something other than a line or arc! startPoint = new Point3D(); endPoint = new Point3D(); } } private void UpdateEntityColorAndList10(Geometry entity, byte color) { entity.Color = color; entity.Commit(); templist10.Clear(); templist10.Add(entity.GetEntityID()); } } }
  19. Found and fixed the issue with ChainEntities data retrieved by ChainDataInterop. Check your mail for more.
  20. You will need to -> Create new geometry and delete the old geometry or alter the endpoint location of the geometry.
  21. How may entities are in the chainEntityList being returned for the chain? If you step through in debug how many times is .Commit() being commanded?
  22. Absolutely! Any (even all) the entities in a chain may be marked as "flipped".
  23. No. A (.NET) List is like a (C++) std::vector and is “in order”. You do not [index] the “Key”, as it is not a list or array. You loop through the ChainEntities list for each item. The Key is the geometry entity, and the Value is the (bool) “am I flipped” flag for that entity.

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