JKLINE
-
Posts
166 -
Joined
-
Last visited
Content Type
Profiles
Forums
Downloads
Store
eMastercam Wiki
Blogs
Gallery
Events
Posts posted by JKLINE
-
-
Is it possible for you to use C++/CLI or NETHook instead?
-
-
I'm thinking perhaps collecting the Geometry and then making my own chain. Running into a problem though, with the geometry not changing direction.
I need the geometry to have the endpoint1 and endpoint2 be that way on the first and then for it to read endpoint2 to endpoint1. I think it's having trouble because there's only one entity.
-
I could use some help with creative thinking. If you have an X shape or t shape object, and you want to offset the chains to make them all closed and rounded edges, you can use the SLOT result method.
The issue is that they leave an overlap so you cannot use the result chain.
Untitled2 shows how the offset curves around end
untitled1 shows the beginning shape example.
-
Another lesson learned.
If you want to go CCW, the endpoints must be switched. It only grabs the first GEO in the CCW direction.
Chain chainFlipperCW(Chain inChain){ inChain.Direction = ChainDirectionType.Clockwise; var firstGeo = 0; var secondGeo = 0; var step = 0; var tempPoint = new Point3D(0, 0, 0); var tempAngle = 0.0; var chainGeo = ChainManager.GetGeometryInChain(inChain); if (step == 0){ firstGeo = chainGeo[0].GetEntityID(); step = 1; } if (step == 1){ for (var i = 1; i < chainGeo.Length; i++){ secondGeo = chainGeo[i].GetEntityID(); var firstGeoTemp = Geometry.RetrieveEntity(firstGeo); var secondGeoTemp = Geometry.RetrieveEntity(secondGeo); if (firstGeoTemp is LineGeometry line1){ if (secondGeoTemp is LineGeometry line2){ var firstEndPoint = line1.EndPoint2; var secondStartPoint = line2.EndPoint1; if (VectorManager.Distance(firstEndPoint, secondStartPoint) >= 0.001){ tempPoint = line2.Data.Point1; line2.Data.Point1 = line2.Data.Point2; line2.Data.Point2 = tempPoint; line2.Selected = false; line2.Commit(); } } if (secondGeoTemp is ArcGeometry arc2){ var firstEndPoint = line1.EndPoint2; var secondStartPoint = arc2.EndPoint1; if (VectorManager.Distance(firstEndPoint, secondStartPoint) >= 0.001){ tempAngle = arc2.Data.StartAngleDegrees; arc2.Data.StartAngleDegrees = arc2.Data.EndAngleDegrees; arc2.Data.EndAngleDegrees = tempAngle; arc2.Selected = false; arc2.Commit(); } } } if (firstGeoTemp is ArcGeometry arc1){ if (secondGeoTemp is LineGeometry line2){ var firstEndPoint = arc1.EndPoint2; var secondStartPoint = line2.EndPoint1; if (VectorManager.Distance(firstEndPoint, secondStartPoint) >= 0.001){ tempPoint = line2.Data.Point1; line2.Data.Point1 = line2.Data.Point2; line2.Data.Point2 = tempPoint; line2.Selected=false; line2.Commit(); } } if (secondGeoTemp is ArcGeometry arc2){ var firstEndPoint = arc1.EndPoint2; var secondStartPoint = arc2.EndPoint1; if (VectorManager.Distance(firstEndPoint, secondStartPoint) >= 0.001){ tempAngle = arc2.Data.StartAngleDegrees; arc2.Data.StartAngleDegrees = arc2.Data.EndAngleDegrees; arc2.Data.EndAngleDegrees = tempAngle; arc2.Selected = false; arc2.Commit(); } } } firstGeo = chainGeo[i].GetEntityID(); //Geometry.RetrieveEntity(firstGeo).Retrieve(); } } var tempChainGeo = ChainManager.GetGeometryInChain(inChain); for (var i = 0; i < tempChainGeo.Length; i++) { tempChainGeo[i].Retrieve(); } return inChain; } Chain chainFlipperCCW(Chain inChain) { inChain.Direction = ChainDirectionType.CounterClockwise; var firstGeo = 0; var secondGeo = 0; var step = 0; var tempPoint = new Point3D(0, 0, 0); var tempAngle = 0.0; var chainGeo = ChainManager.GetGeometryInChain(inChain); if (step == 0) { firstGeo = chainGeo[0].GetEntityID(); step = 1; } if (step == 1) { for (var i = 1; i < chainGeo.Length; i++) { secondGeo = chainGeo[i].GetEntityID(); var firstGeoTemp = Geometry.RetrieveEntity(firstGeo); var secondGeoTemp = Geometry.RetrieveEntity(secondGeo); if (firstGeoTemp is LineGeometry line1) { if (secondGeoTemp is LineGeometry line2) { var firstEndPoint = line1.EndPoint1; var secondStartPoint = line2.EndPoint2; if (VectorManager.Distance(firstEndPoint, secondStartPoint) >= 0.001) { tempPoint = line2.Data.Point2; line2.Data.Point2 = line2.Data.Point1; line2.Data.Point1 = tempPoint; line2.Selected = false; line2.Commit(); } } if (secondGeoTemp is ArcGeometry arc2) { var firstEndPoint = line1.EndPoint1; var secondStartPoint = arc2.EndPoint2; if (VectorManager.Distance(firstEndPoint, secondStartPoint) >= 0.001) { tempAngle = arc2.Data.EndAngleDegrees; arc2.Data.EndAngleDegrees = arc2.Data.StartAngleDegrees; arc2.Data.StartAngleDegrees = tempAngle; arc2.Selected = false; arc2.Commit(); } } } if (firstGeoTemp is ArcGeometry arc1) { if (secondGeoTemp is LineGeometry line2) { var firstEndPoint = arc1.EndPoint1; var secondStartPoint = line2.EndPoint2; if (VectorManager.Distance(firstEndPoint, secondStartPoint) >= 0.001) { tempPoint = line2.Data.Point2; line2.Data.Point2 = line2.Data.Point1; line2.Data.Point1 = tempPoint; line2.Selected = false; line2.Commit(); } } if (secondGeoTemp is ArcGeometry arc2) { var firstEndPoint = arc1.EndPoint1; var secondStartPoint = arc2.EndPoint2; if (VectorManager.Distance(firstEndPoint, secondStartPoint) >= 0.001) { tempAngle = arc2.Data.EndAngleDegrees; arc2.Data.EndAngleDegrees = arc2.Data.StartAngleDegrees; arc2.Data.StartAngleDegrees = tempAngle; arc2.Selected = false; arc2.Commit(); } } } firstGeo = chainGeo[i].GetEntityID(); //Geometry.RetrieveEntity(firstGeo).Retrieve(); } } var tempChainGeo = ChainManager.GetGeometryInChain(inChain); for (var i = 0; i < tempChainGeo.Length; i++) { tempChainGeo[i].Retrieve(); } return inChain; }
-
If an entity is blue, offset to the left. If an entity is green, offset to the right.
Impossible to control.
But, if the endpoint of the first entity and the start point of the second entity touch, then continue the loop.
If the endpoint of the first entity and the start point of the second entity do not touch, then the entity is 'flipped' and needs to be regenerated so that the two ends switch places.
Everything was working out great, I just didn't realize I had to Retrieve after making all the changes
-
foreach(var alteredGeo in alteredGeoList) { alteredGeo.Retrieve(); }
Bleh
-
I switched to for (var i = 0; i < geoList.Count; i++) and it's working now
seems I only have one issue left, for now anyways flippedGeometry
I have it inspect the chain, and then reconstruct the chain, but it isn't spitting out in the correct order. I have two start points touching each other, throwing off the entire chain.
Chain chainFlipper(Chain inChain){ inChain.Direction = ChainDirectionType.CounterClockwise; var firstGeo = 0; var secondGeo = 0; var step = 0; var tempPoint = new Point3D(0, 0, 0); var tempAngle = 0.0; var chainGeo = ChainManager.GetGeometryInChain(inChain); if (step == 0){ firstGeo = chainGeo[0].GetEntityID(); step = 1; } if (step == 1){ for (var i = 1; i < chainGeo.Length; i++){ secondGeo = chainGeo[i].GetEntityID(); var firstGeoTemp = Geometry.RetrieveEntity(firstGeo); var secondGeoTemp = Geometry.RetrieveEntity(secondGeo); if (firstGeoTemp is LineGeometry line1){ if (secondGeoTemp is LineGeometry line2){ var firstEndPoint = line1.EndPoint2; var secondStartPoint = line2.EndPoint1; if (VectorManager.Distance(firstEndPoint, secondStartPoint) >= 0.001){ tempPoint = line2.Data.Point1; line2.Data.Point1 = line2.Data.Point2; line2.Data.Point2 = tempPoint; line2.Commit(); } } if (secondGeoTemp is ArcGeometry arc2){ var firstEndPoint = line1.EndPoint2; var secondStartPoint = arc2.EndPoint1; if (VectorManager.Distance(firstEndPoint, secondStartPoint) >= 0.001){ tempAngle = arc2.Data.StartAngleDegrees; arc2.Data.StartAngleDegrees = arc2.Data.EndAngleDegrees; arc2.Data.EndAngleDegrees = tempAngle; arc2.Commit(); } } } if (firstGeoTemp is ArcGeometry arc1){ if (secondGeoTemp is LineGeometry line2){ var firstEndPoint = arc1.EndPoint2; var secondStartPoint = line2.EndPoint1; if (VectorManager.Distance(firstEndPoint, secondStartPoint) >= 0.001){ tempPoint = line2.Data.Point1; line2.Data.Point1 = line2.Data.Point2; line2.Data.Point2 = tempPoint; line2.Commit(); } } if (secondGeoTemp is ArcGeometry arc2){ var firstEndPoint = arc1.EndPoint2; var secondStartPoint = arc2.EndPoint1; if (VectorManager.Distance(firstEndPoint, secondStartPoint) >= 0.001){ tempAngle = arc2.Data.StartAngleDegrees; arc2.Data.StartAngleDegrees = arc2.Data.EndAngleDegrees; arc2.Data.EndAngleDegrees = tempAngle; arc2.Commit(); } } } firstGeo = chainGeo[i].GetEntityID(); } } return inChain; }
-
I've made sure that GeoList is storing the numbers correctly. They are all in the correct order. But when I go to use 'foreach var entity in GeoList' it doesn't stay in order. Should I just switch to for i=0 ect ect?
-
Getting an error where sometimes, any chain after the first one, goes clockwise. I'm having a rough time tracking down the root.
List<int> chainSorter(Chain inChain, int startId) { var tempListIn = new List<int>(); var tempListOut = new List<int>(); inChain.Direction = ChainDirectionType.CounterClockwise; var geo = ChainManager.GetGeometryInChain(inChain); foreach (var ids in geo){ var geoId = ids.GetEntityID(); tempListIn.Add(geoId); } if (tempListIn[0] != startId){ bool predicate(int u){ if (u == startId){ return true; } return false; } var index = tempListIn.FindIndex(predicate); var listSize = tempListIn.Count; for (var i = index; i < listSize; i++){ tempListOut.Add(tempListIn[i]); } for (var i = 0; i < index; i++){ tempListOut.Add(tempListIn[i]); } return tempListOut; } else { return tempListIn; } }
var freshChain = ChainManager.ChainAll(75); foreach(var chain in freshChain){ var tempList400 = new List<double>(); var chainDetails = new Mastercam.Database.Interop.ChainDetails();// Preps the ChainDetails plugin var chainDirection = ChainDirectionType.CounterClockwise;// Going to be used to make sure all chains go the same direction chain.Direction = chainDirection; var chainGeo = ChainManager.GetGeometryInChain(chain); foreach (var entity1 in chainGeo){ var endpoint1 = entity1.EndPoint1.x; var endpoint2 = entity1.EndPoint2.x; var xMedian = (endpoint1+endpoint2)/2; tempList400.Add(xMedian); } tempList400.Sort(); foreach (var entity1 in chainGeo){ var templist10 = new List<int>(); // temporarily holds geoID of chainEntities var endpoint1 = entity1.EndPoint1.x; var endpoint2 = entity1.EndPoint2.x; var xMedian = (endpoint1 + endpoint2) / 2; if (xMedian == tempList400[0]) { var finalList = chainSorter(chain, entity1.GetEntityID());
-
resultArc1.id = 'A'; needs to be resultArc1.id = A_ID;
How embarrassing Works like a charm.
-
The problem with the easy way is that it'd require math The only information I have is the arc data and the point data. I don't know the angle from the center of the circle to the point.
Everything appears to be working, and the level manager shows I have entities created. I just can't see them And I can't select them. I also can't add their IDs to the return list (it says the IDs don't exist).
static System::Collections::Generic::List<int>^ SelectionManager::BreakArcAtPoint(Mastercam::Curves::ArcGeometry^ arc, Mastercam::BasicGeometry::PointGeometry^ point) { System::Collections::Generic::List<int>^ newGeoIDs; bool successful = false; p_3d pointy; ent firstEnt; ent secondEnt; GetEntityByID(arc->GetEntityID(), firstEnt, &successful); GetEntityByID(point->GetEntityID(), secondEnt, &successful); DB_LIST_ENT_PTR resultGeoID1; DB_LIST_ENT_PTR resultGeoID2; short newSel = ALIVE_BIT; MC_BYTE mc_byte = MC_WHITE; int newLevel = 76; attributes newAttrib; bool geoStored; p_3d newArcCenterPoint = firstEnt.eptr->eptr->u.ar.c; p_3d newArc1StartPoint = firstEnt.eptr->eptr->u.ar.ep1; p_3d newArc2EndPoint = firstEnt.eptr->eptr->u.ar.ep2; p_3d breakPoint = secondEnt.eptr->eptr->u.pt; a_2d newArc1; a_2d newArc2; bool arcCreated; constr_arc_new(newArc1StartPoint.ConvertTo2d(), breakPoint.ConvertTo2d(), newArcCenterPoint.ConvertTo2d(), true, 0.005, &newArc1, &arcCreated); if (arcCreated == true) { ent resultArc1; resultArc1.id = 'A'; resultArc1.u.ar.c = newArc1.c.ConvertTo3d(); resultArc1.u.ar.r = newArc1.r; resultArc1.u.ar.sa = newArc1.sa; resultArc1.u.ar.sw = newArc1.sw; store_ent(&resultArc1, &resultGeoID1, newSel, mc_byte, newLevel, newAttrib, &geoStored, true);//include DbLolo_CH.h if (geoStored == true) { // newGeoIDs->Add(resultGeoID1->eptr->ent_idn); <-- Error } } constr_arc_new(breakPoint.ConvertTo2d(), newArc2EndPoint.ConvertTo2d(), newArcCenterPoint.ConvertTo2d(), true, 0.005, &newArc2, &arcCreated); if (arcCreated == true) { ent resultArc2; resultArc2.id = 'a'; resultArc2.u.ar.c = newArc2.c.ConvertTo3d(); resultArc2.u.ar.r = newArc2.r; resultArc2.u.ar.sa = newArc2.sa; resultArc2.u.ar.sw = newArc2.sw; store_ent(&resultArc2, &resultGeoID2, newSel, mc_byte, newLevel, newAttrib, &geoStored, true);//include DbLolo_CH.h if (geostored == true) { // newgeoids->add(resultgeoid2->eptr->ent_idn); <-- Error } } return newGeoIDs; }
-
Some progress has been made! Getting an object error from the constr_arc_new method line. I'm guessing one of the supplied parameters is failing or is unpopulated.
static System::Collections::Generic::List<int>^ SelectionManager::BreakArcAtPoint(Mastercam::Curves::ArcGeometry^ arc, Mastercam::BasicGeometry::PointGeometry^ point) { System::Collections::Generic::List<int>^ newGeoIDs; bool successful = false; p_3d pointy; auto firstEnt = std::make_unique<ent>(); auto secondEnt = std::make_unique<ent>(); GetEntityByID(arc->GetEntityID(), *firstEnt, &successful); GetEntityByID(point->GetEntityID(), *secondEnt, &successful); DB_LIST_ENT_PTR resultGeoID1; DB_LIST_ENT_PTR resultGeoID2; short newSel = ALIVE_BIT; MC_BYTE mc_byte = MC_WHITE; int newLevel = 75; attributes newAttrib; bool geoStored; if (secondEnt->id == P_ID) { pointy = secondEnt->u.pt; } std::vector<ent> firstEntity; if (firstEnt->id == A_ID) { ent tempEnt; tempEnt.id = 'A'; tempEnt.u.ar.c = firstEnt->u.ar.c; tempEnt.u.ar.r = firstEnt->u.ar.r; tempEnt.u.ar.sa = firstEnt->u.ar.sa; tempEnt.u.ar.sw = firstEnt->u.ar.sw; firstEntity.push_back(tempEnt); } p_3d newArcCenterPoint = firstEntity[0].eptr->eptr->u.ar.c; p_3d newArc1StartPoint = firstEntity[0].eptr->eptr->u.ar.ep1; p_3d newArc2EndPoint = firstEntity[0].eptr->eptr->u.ar.ep2; double newArcRad = firstEntity[0].eptr->eptr->u.ar.r; a_2d newArc1; a_2d newArc2; bool arcCreated; constr_arc_new(newArc1StartPoint.ConvertTo2d(), pointy.ConvertTo2d(), newArcCenterPoint.ConvertTo2d(), true, 0.005, &newArc1 ,&arcCreated); if (arcCreated == true) { std::vector<ent> firstNewArc; ent tempEnt1; tempEnt1.id = 'A'; tempEnt1.u.ar.c = newArc2.c.ConvertTo3d(); tempEnt1.u.ar.r = newArc2.r; tempEnt1.u.ar.sa = newArc2.sa; tempEnt1.u.ar.sw = newArc2.sw; firstEntity.push_back(tempEnt1); store_ent(&firstNewArc[0], &resultGeoID1, newSel, mc_byte, newLevel, newAttrib, &geoStored, true);//include DbLolo_CH.h if (geoStored == true) { newGeoIDs->Add(resultGeoID1->eptr->ent_idn); } } constr_arc_new(pointy.ConvertTo2d(), newArc2EndPoint.ConvertTo2d(), newArcCenterPoint.ConvertTo2d(), true, 0.005, &newArc1, &arcCreated); if (arcCreated == true) { std::vector<ent> secondNewArc; ent tempEnt2; tempEnt2.id = 'A'; tempEnt2.u.ar.c = newArc2.c.ConvertTo3d(); tempEnt2.u.ar.r = newArc2.r; tempEnt2.u.ar.sa = newArc2.sa; tempEnt2.u.ar.sw = newArc2.sw; firstEntity.push_back(tempEnt2); store_ent(&secondNewArc[0], &resultGeoID2, newSel, mc_byte, newLevel, newAttrib, &geoStored, true);//include DbLolo_CH.h if (geoStored == true) { newGeoIDs->Add(resultGeoID2->eptr->ent_idn); } } return newGeoIDs; }
-
What am I missing?
static System::Collections::Generic::List<int>^ SelectionManager::BreakArcAtPoint(Mastercam::Curves::ArcGeometry^ arc, Mastercam::BasicGeometry::PointGeometry^ point) { System::Collections::Generic::List<int>^ newGeoIDs; bool successful = false; p_3d pointy; auto firstEnt = std::make_unique<ent>(); auto secondEnt = std::make_unique<ent>(); GetEntityByID(arc->GetEntityID(), *firstEnt, &successful); GetEntityByID(point->GetEntityID(), *secondEnt, &successful); if (secondEnt->id == P_ID) { pointy = secondEnt->u.pt; } std::vector<ent> firstEntity; if (firstEnt->id == A_ID) { ent tempEnt; tempEnt.id = 'A'; tempEnt.u.ar.c = firstEnt->u.ar.c; tempEnt.u.ar.r = firstEnt->u.ar.r; tempEnt.u.ar.sa = firstEnt->u.ar.sa; tempEnt.u.ar.sw = firstEnt->u.ar.sw; firstEntity.push_back(tempEnt); } p_3d newArcCenterPoint = firstEntity[0].eptr->eptr->u.ar.c; p_3d newArc1StartPoint = firstEntity[0].eptr->eptr->u.ar.ep1; p_3d newArc2EndPoint = firstEntity[0].eptr->eptr->u.ar.ep2; double newArcRad = firstEntity[0].eptr->eptr->u.ar.r; a_2d newArc1; a_2d newArc2; bool arcCreated; constr_arc_new(newArc1StartPoint.ConvertTo2d(), pointy.ConvertTo2d(), newArcCenterPoint.ConvertTo2d(), true, 0.005, &newArc1 ,&arcCreated); constr_arc_new(pointy.ConvertTo2d(), newArc2EndPoint.ConvertTo2d(), newArcCenterPoint.ConvertTo2d(), true, 0.005, &newArc1, &arcCreated); ent entToStore; DB_LIST_ENT_PTR resultGeoID; short newSel; MC_BYTE mc_byte; int newLevel; attributes newAttrib; bool geoStored; store_ent(&entToStore, &resultGeoID, newSel, mc_byte, newLevel, newAttrib, &geoStored,true);//include DbLolo_CH.h newGeoIDs->Add(resultGeoID->eptr->ent_idn); return newGeoIDs; }
-
I just heard back from the SDK team. They say it'll be a part of the new SDK package for Mastercam 2024, so I'm lost in the sauce until then.
Sounds like I'll just have to create my own C++ package.
Given geo and point,
if geoID = L, newLine (line.endpoint1, point), newLine (line.endpoint2,point), deleteGeo
return list of new IDs
if geoID = A, newArc (arc.endpoint1, point), newLine (arc.endpoint2,point), deleteGeo
IDK, something like this I suppose.
I started something like this yesterday, but I couldn't figure out the store_ent given an a_2d or l_2d
-
Ever seen anything like this? I've ran out of debug ideas
Original geo is the white line. Chained it and offset with OffsetChain2D both directions.
Input chain has 4 entities, meanwhile one of the results has 5 entities and the other has 6 entities.
I've verified that the chain going into the OffsetChain2D method has only 4 entities. I've also offset the chains by hand and that worked as intended. I extracted the geometry to a fresh Mastercam file and ran only the OffsetChain2D method on it and it worked as intended. Meaning my code works and the geometry isn't the problem.
Why would my result have more entities than the starting chain?
-
I'm not finding any method related to it anywhere. Only found it in the FT file of Mastercam itself.
-
Have you ever used BreakAtPoints?
-
I do actually love my job and the challenge of both the Net and C++ side of things
In my entire life, I've been quick at learning things because of Murphy's Law I find that most people only see certain problems once in a while so it takes a while to learn things. Meanwhile, I face every problem as soon as it CAN be a problem.
Would've have gotten this far without support though, that's for sure.
Project Based Learning. Just over 3 months old.
-
2 minutes ago, byte said:
Would clearing the result bit before hand help?
I definitely would I hate it here
GetResultGeometry is the pure evil.
-- The issue I'll have with threading is when more than one thread ends up with a result. A problem for tomorrow though.
I appreciate the help!
-
16 hours ago, byte said:
While it may say that in the description, the truth is that it returns the chain that you passed to it
Just get the result geometry and you will be back in business
Don't worry, I even screwed that up too I'm working on getting the middle line to work (resultGeo1). But it seems linked to the original geometry, because it hates me
foreach (var chain in angleChain) { chain.OffsetChain2D(OffsetSideType.Left,0.010,OffsetRollCornerType.None,0,false,0.005,false); var resultGeo1 = SearchManager.GetResultGeometry(); angleGeoResult1.Add(resultGeo1[0]); GraphicsManager.ClearColors(new GroupSelectionMask(true)); foreach (var tempEnt in angleGeoResult1) { tempEnt.Color = 50; tempEnt.Commit(); } } foreach (var chain in angleChain) { chain.OffsetChain2D(OffsetSideType.Left, 0.020, OffsetRollCornerType.None, 0, false, 0.005, false); var resultGeo2 = SearchManager.GetResultGeometry(); angleGeoResult2.Add(resultGeo2[0]); GraphicsManager.ClearColors(new GroupSelectionMask(true)); foreach (var tempEnt in angleGeoResult2) { tempEnt.Color = 60; tempEnt.Commit(); } }
-
I wish Translate had an option to translate from itself instead of world coordinates.
The same way offset Contour works, just for one item
-
It could be reffering to the chain that was offset, and not the actual result chain.
Using result geometry causes issues when I start adding process threading.
CLI it is!
-
I thought OffsetChain2D returned the 'new' geo.
So there's no way to get it without SearchManager.Result?
The tooltip::
Return Value
Type: Chain
The "offset" Chain, else null if failed.I found DllImpExp bool OffsetChains (CHAIN *pChains, OffsetChainsParams ¶ms, EptrArray &resultEptrs); if there's no way to do it through NET.
How to start
in Mastercam C-Hook, NET-Hook and VBScript Development
Posted
I would also join one forum up (this subgroup is for C-Hooks and such). There appears to be more support and activity there for Post related activities.