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. We can see that it is a List of KeyValue pairs. -> ChainEntities = gcnew List<KeyValuePair<Mastercam::Database::Geometry ^, bool>> (); The Key is the geometry entity. (Not the ID of the entity.) The Value is a flag that lets us know if this entity is marked “flipped” in the chain. If you really want to “extract” add these entities to another List. foreach (var t in chainEntityList){ templist10.Add(t.Key);
  2. - try this - var chainDetails = new Mastercam.Database.Interop.ChainDetails(); foreach (var chain in selectedChains) { // The GetData method in the ChainDetails class returns a ChainData object. var chainData = chainDetails.GetData(chain); var chainEntityList = chainData.ChainEntities; var startPoint = chainData.StartPoint; var endPoint = chainData.EndPoint; . . . }
  3. No way to tell what is happening here just by looking at pictures. We would need your sample part file and your project code to investigate this. Send to [email protected] along with your company contact info.
  4. If you make a change to an operation manually using Mastercam's User Interface Mastercam marks it 'dirty', you should have your add-in mark it dirty, or just have it regen the toolpath.
  5. A couple things. var operations = new List<int[]>(); 1> No. You don't want a List of arrays (of integers). 2> You have not retrieved the actual "operation" here. You are looping through the IDs. foreach (var selectedOperation in operations){ selectedOperation.RotaryAxis = axisParams; selectedOperation.commit(); } Try this... private void ChangeOperations() { var rotaryPD = 0.0; DialogManager.AskForNumber("Enter New Rotary PD", ref rotaryPD); OperationsManager.RefreshOperationsManager(true); var operationIDs = SearchManager.GetOperationIDs(true); var axisSub = new RotaryAxisSubstitution { }; var axisParams = new RotaryAxisParams { Enabled = true, Diameter = rotaryPD, AxisSubstitution = axisSub }; foreach (var opID in operationIDs) { var op = SearchManager.GetOperation(opID); op.RotaryAxis = axisParams; op.Commit(); } OperationsManager.RefreshOperationsManager(true); }
  6. Just curious to what result you were looking for. You are breaking the entities into 2 pieces using BreakManyPieces, correct? ...at a point Where is the "at point" in this?
  7. I do not believe that is supported in the NET-Hook API. Would need a C-Hook add-in code for that. If you wish to contact us [[email protected]] with your company contact into, I believe we have a sample C-Hook project that demonstrates creating a Draft Surface.
  8. This can be done with a C-Hook type add-in. What version of Mastercam? The add-in would . . . 1. Ask the user for the level number to place the surfaces on. 2. All solids (or should this just all visible solids?) would be processed. 3. All solids that had surfaces made would then be "hidden". You can mail us with your company contact info -> [email protected] and we can see what may be done.
  9. I suggest always first try using the non-full rebuild overload of Repaint() to see if that is enough. GraphicsManager.Repaint(); The "true" parameter forces a complete rebuild of the graphics. GraphicsManager.Repaint(true); If that's what you really need, then you can accept the time hit of doing this. But if just the simple GraphicsManager.Repaint() is "good enough" that's going to be faster. Also be careful of putting a full rebuild call Repaint(true) within a loop. Doing so is rarely correct and can really slow down your add-in's execution. ---------------- This is not a correct method signature for an "entry" method (incorrect parameter type) -> public Mastercam.App.Types.MCamReturn CustomNethookRun(Mastercam.App.Types.MCamReturn notused) Should be -> public Mastercam.App.Types.MCamReturn CustomNethookRun(int param) ---------------- If you have geometry other than lines on level #101, code in connectUpperLines will throw an Exception -> var line = (LineGeometry)creaseGeo; This is because the upperCreaseID list of IDs contains IDs for all geometry from that level. So, for example if there is an arc on that level, its ID is getting added to the upperCreaseID list and when the code attempts to cast what is an ArcGeometry to a LineGeometry => failure. Either make sure you do not add non-line entities to that list of entity IDs, or check before you cast. foreach (var i in upperCreaseID) { if (set == 0) { var creaseGeo = Geometry.RetrieveEntity(i); // Make sure that this entity is a line before casting. if (creaseGeo is LineGeometry line) { var line = (LineGeometry)creaseGeo; creaseX1 = line.EndPoint1.x; // <...snipped...> } } }
  10. var geom = Mastercam.Database.Geometry.RetrieveEntity(id); /// <summary> Alter the color and or level of the lines. </summary> /// /// <param name="geoIDs"> The list of geometry IDs to process. </param> /// <param name="color"> (Optional) The color to set the entity to (0 = no change). </param> /// <param name="level"> (Optional) The level to set the entity to (0 = no change). </param> private void AlterLines(List<int> geoIDs, int color = 2, int level = 100) { if (color <= 0 && level <= 0) { return; // nothing to do! } // Retrieve the entities "by their ID" foreach (var id in geoIDs) { var geom = Mastercam.Database.Geometry.RetrieveEntity(id); if (color > 0) { geom.Color = (color < 255) ? color++ : color = 1; } if (level > 0) { geom.Level = level++; } geom.Commit(); } Mastercam.IO.LevelsManager.RefreshLevelsManager(); // optional } /// <summary> Ask the use to select some lines and then gather up /// the IDs of the user selected entities. </summary> private void Demo() { var geomask = new Mastercam.Database.Types.GeometryMask { Lines = true }; var userSelectedGeometry = Mastercam.IO.SelectionManager.AskForMultipleGeometry("Select lines", geomask); if (userSelectedGeometry != null) { Mastercam.IO.SelectionManager.UnselectAllGeometry(); // optional var geoIDs = new List<int>(); foreach (var entity in userSelectedGeometry) { geoIDs.Add(entity.GetEntityID()); } AlterLines(geoIDs); } }
  11. Move this line out so that it is only called once after the loop that processes the geometry. >Mastercam.IO.GraphicsManager.Repaint(true); The 'true' makes it do a "full rebuild" of the graphics and that can be (time) expensive depending on the geometry in the part file. >Why would it matter if the geometry has been "flipped"? Are you referring to the direction of a chain? Not the direction of the chain itself, but the “direction” of the entities at the ends of the chain. Think of a chain that ends with a line. The endpoint #2 of that defined geometry line may not be the same position as the end of the chain it is in. It is possible that the end of the chains is at the endpoint #1 position of the line. When that happens (we cannot change the line geometry entity itself), the Chain Entity (which "points" to that line) is marked as “flipped”, so the system can know travelling down that line (in the chain) actually goes from endpoint #2 -> endpoint #1 of that line. The ChainDataInterop mentioned is a C++/CLI project. This type of "hybrid" project allows for creating code that uses functionality in the C-Hook SDK that is not in the NET-Hook API. It creates a .NET Assembly that your NET-Hook project can use just like it does for the std. NET-Hook API. You would add a Reference in your NET-Hook project to this ChainDataInterop.dll, just like you do for the NET-Hook API when you add the NETook3_0.DLL in your project.
  12. Getting “details” about a Chain using the NET-Hook API. You can get the geometry in a Chain, but you do not know if the first or last entity has been “flipped”. You need that to know the true endpoint. This functionality is available in a C-Hook add-in (using the C-Hook API). There is a story in our backlog to add this to the NET-Hook API. What version of Mastercam are you running? For now…. You can use a “interop” DLL that will gather up more *details about a Chain. You add a reference to your NET-Hook project (just like you do for the NETHook3_0.dll) to this ChainDaraInterop.dll *Chain detail properties include: GetFirstEndPoint, GetLastEndPoint, GetFirstEntityID, GetLastEntityID, IsFirstEnttyFlipped, IsLastEntityFlipped. If you email us -> [email protected] with your company contact information and we can see about getting you this “ChainDataInterop” project.
  13. Altering a line - /// <summary> Shows the line end points. </summary> /// /// <remarks> Using a custom format. </remarks></remarks> /// /// <param name="line"> The line. </param> private void ShowLineEndPoints(Mastercam.Curves.LineGeometry line) { MessageBox.Show($"ep1 > X:{line.EndPoint1.x:N4} Y:{line.EndPoint1.y:N4} Z:{line.EndPoint1.z:N4}{Environment.NewLine}ep2 > X:{line.EndPoint2.x:N4} Y:{line.EndPoint2.y:N4} Z:{line.EndPoint2.z:N4}", "Line Endpoints", MessageBoxButtons.OK, MessageBoxIcon.Information); } /// <summary> Shows the line data. </summary> /// /// <remarks> Using the ToString() method in the LineGeometry class. </remarks></remarks> /// /// <param name="line"> The line. </param> private void ShowLineData(Mastercam.Curves.LineGeometry line) { MessageBox.Show(line.ToString(), "Line Data", MessageBoxButtons.OK, MessageBoxIcon.Information); } /// <summary> Demo altering the endpoint of a line. </summary> private void DemoAlterLine() { var geomask = new Mastercam.Database.Types.GeometryMask { Lines = true }; var geo = Mastercam.IO.SelectionManager.AskForGeometry("Select a line", geomask); if (geo != null) { // Downcast the geometry object to a LineGeometry so we can access its "line specific" properties. var line = (Mastercam.Curves.LineGeometry)geo; ShowLineData(line); // Alter endpoint #2 line.Data.Point2.x += 1.1; line.Data.Point2.y += 0.5; line.Commit(); Mastercam.IO.GraphicsManager.Repaint(true); ShowLineEndPoints(line); } }
  14. Remove these lines from your code. They do not look to being doing anything useful here.
  15. Once we have created an offset contour you want to move the new geometry to another level. // The new geometry created by OffsetChain2D is marked as a “result”. var upperChainLarge = selectedChain.OffsetChain2D(. . .); // To mark the “result” geometry as “selected” we can do this -> SelectionManager.SelectGeometryByMask(Mastercam.IO.Types.QuickMaskType.Result); // Now we move this “selected” geometry to another level. GeometryManipulationManager.MoveSelectedGeometryToLevel(createdUpperLevel, true); Or we can do this –> // The new geometry created by OffsetChain2D is marked as a “result”. var upperChainLarge = selectedChain.OffsetChain2D(. . .); // Get the “result” geometry var resultGeometry = SearchManager.GetResultGeometry(); // To mark the “result” geometry as “selected” we can do this -> foreach (var item in resultGeometry) { item.Selected = true; item.Commit(); } // Now we move this “selected” geometry to another level. GeometryManipulationManager.MoveSelectedGeometryToLevel(createdUpperLevel, true); Or if we just wish to move the new offset geometry to another level (without marking them as "selected") -> // The new geometry created by OffsetChain2D is marked as a “result”. var upperChainLarge = selectedChain.OffsetChain2D(. . .); // Get the “result” geometry var resultGeometry = SearchManager.GetResultGeometry(); // Change the level on each to the “result” geometries foreach (var entity in resultGeometry) { entity.Level = createdUpperLevel; entity.Commit(); }
  16. Yes, you can install multiple versions of Mastercam on a system. I have 2019/2020/2021/2022/2023 and 2024 installed on mine.
  17. Maybe this? (Knowledge Base Article 17789) How to add file extensions to Code Expert – myMastercam
  18. chain_manager is in the MCMill.lib Is this library being included in the project? Project properties -> Linker -> Input page Or just add this #pragma after the #includes at the top of the .cpp where you are using chain_manager #pragma comment (lib, "MCMill.lib")
  19. What a well done (and beautiful) presentation. Thanks Aaron!
  20. Yes, chain_it(…) prompts the user to select the chains(s). I believe the mc_op_getChains(...) gets the chains from a Solid operation. You are passing in a DB ptr to a Solid and getting out the Chains (if any). The return is the number of chains found and returned via the [out] CHAIN **chains variable. See chain_all_selected(…) in Chain_CH.h You need to select the entities to be chained. Not difficult, but you want to have plan first. Are the entities all by themselves on a separate level? Or are they all a specific color? Or both? You could select the entities by level and/or color, and/or by some other property that is unique to those entities. I you would like working sample code of using this, email us SDK[at]Mastercam[dot]com with your company contact info.
  21. It is doubtful that mc_op_getChains(…) is what you need for this. What type of geometry is being chained – wireframe, or solids? What it the type of operation the chain is being assigned to?
  22. Yes, you can import from a .mcam file just like you do when using .mcam-operations files. I cannot tell what is causing the issue from just what I can see in the image. What version of Mastercam are you running? If you wish, send us your project to SDK[at]Mastercam[dot]com along with your company contact info, and we’ll take a look. When you ZIP up a Visual Studio project. Do not include the ‘x64’ folder and its subfolders. Just makes the ZIP huge with files we do not need, as Visual Studio will recreate them when you build the project.
  23. Step #1 -> First determine what functionality you need to accomplish. What exactly you want your add-in to do. List out all these “steps” it needs accomplish the desire end result. This step is skipped or rushed past all too often! "I want my add-in to automate creating toolpaths." Great! – You have the end goal. What individual steps are needed to get there? These are the important details. With that detailed information, now we can then determine which style of add-in you can use to do that. A C-Hook with C++ is always in the mix of “I can do it with this type of add-in”. But, if you can do want you need with the NET-Hook (C#) style add-in, that may be an easier route to take. If starting out learning C++ (and maybe C#), I would just start with C++. If you know C or C++, going then to C# is fairly easy.
  24. Mastercam has several types of add-ins. C-Hook style -> Done in C++ (or C++/CLI) NET-Hook style -> Done with C# or VB.NET C# Scripts -> Obviously done in C# (New in Mastercam 2022) The non C-Hook types do not provide as much functionality as a C-Hook type solution. Which to use? First determine what functionality you need to accomplish what you want your add-in to do. Does this require a C-Hook? If so, there is your answer. If it does not? If you know C++, doing C# for a .NET type add-in is not that difficult. If I can do want I need with a NET-Hook style add-in, that is my first choice. This from someone that spends the majority of their time programming C++.
  25. You first need to determine which of the above outputs are referencing a string selection. Then you could add another item to that string select table, post process a toolpath that you know should generate the errors and see what happens. (Make the new string added to the string select table something unique that will be obvious if you see it in the NC output if that new string is output.) Without the PST file my first guess would be to look at what is occurring for these items - *sg20code pwtcode pctype If the issue is not one of these, you will need to look at the others.

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