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. More struggles I'm getting the offset correctly, but I'm trying to hold the geo somewhere. Assuming the entity data is changed to the new entity, resultLineGeo1 should change colors. The original geometry changes to color 25 and then color 30 even though the spacing of everything is correct Basically, I want the original geo one color, the chain that's offset 0.010 to be another, and the last chain another color. foreach (var chain in angleChain) { var resultChain1 = chain.OffsetChain2D(OffsetSideType.Left,0.010,OffsetRollCornerType.None, 0, true, 0.005, true); var resultChainGeo1 = ChainManager.GetGeometryInChain(resultChain1); foreach (var resultEntity in resultChainGeo1) { resultEntity.Color = 25; resultEntity.Commit(); resultLineGeo1 = resultEntity.GetEntityID(); } } foreach (var chain in angleChain) { var resultChain2 = chain.OffsetChain2D(OffsetSideType.Left, 0.020, OffsetRollCornerType.None, 0, true, 0.005, true); var resultChainGeo2 = ChainManager.GetGeometryInChain(resultChain2); foreach (var resultEntity in resultChainGeo2) { resultEntity.Color = 30; resultEntity.Commit(); resultLineGeo2 = resultEntity.GetEntityID(); } }
  2. That'd still be bigger than MTOL but you are absolutely correct. I got lucky in this instance, I could've used rounding instead of a tolerance. Doubles are scary.
  3. First, you have to 'unflip' all the entities or it won't matter. var allChains = ChainManager.ChainAll(75); foreach (var chain in allChains) { chain.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(chain); 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(); } } } Then you can send the list(int) of entities to the CLI package static Mastercam::Database::Chain^ SelectionManager::ChainLinker (System::Collections::Generic::List<int>^ GeoList){ bool successful; Mastercam::Database::Chain^ returnChain; // NETHook side chain CHAIN* tempChain; // CLI side chain ent entity; // blank entity std::vector<ent> entities; // Blank vector list needed for CreateChain method for (auto i=0;i<GeoList->Count;i++){ GetEntityByID(GeoList[i], entity, &successful); // Gets ent value and assigns to entity entities.push_back(entity); // adds entity to vector list } tempChain = SelectionManager::CreateChain(entities); // Sends Entity List to chain creator (in order) returnChain = SelectionManager::GetNetChain(tempChain); return returnChain; } It used CreateChain which adds entities and creates a 'native' chain static CHAIN* SelectionManager::CreateChain(std::vector<ent>& entities) { CHAIN* chain; short err = alloc_chain(&chain, FALSE /* partial*/); bool result = (err == 0 && chain != nullptr); if (result) { CHAIN_ENT* last_chain_ent = nullptr; for (auto& entity : entities) { short errCode = add_curve_to_chain(&entity, 0, TRUE, 0, chain, &last_chain_ent); if (errCode != CHAIN_OK) // bail out ! { result = false; break; } } } return (result ? chain : nullptr); } We can use GetNetChain to convert it from a 'native' chain to a NetHook chain (using ChainData Interop -- it has NETHookApiReflection) static Mastercam::Database::Chain^ SelectionManager::GetNetChain(CHAIN* chain) { auto newChains = gcnew List<Chain^>(); //** you created a chain and now use it below if (chain) { for (auto currentChain = chain; currentChain != nullptr; currentChain = currentChain->next) { IntPtr chainPointer(currentChain); auto o = NETHookApiReflection::ConstructChain ( chainPointer ); if (o != nullptr) // Should never be, but just in case... { newChains->Add(dynamic_cast<Chain^> (o)); } } } return newChains[0]; } You can now control off offset direction of 'Open Chains'
  4. I have made some progress but I’m still stuck. I believe there are two options for what I need, and the help I need is with conversions. Option 1:: Needs conversion from DB_LIST_ENT_PTR ** to DB_LIST_ENT_PTR Option 2:: Needs conversion from CHAIN* to DB_LIST_ENT_PTR && Needs conversion from DB_LIST_ENT_PTR to IntPtr static Mastercam::Database::Chain^ SelectionManager::GetNetChain1(CHAIN* nativeChain) { Chain^ returnChain = nullptr; DB_LIST_ENT_PTR** chainPointer; ent chain; ent* entity; bool correct; int* entNumber; //dbEntityPtr ptr; <- native intPtr chain_to_eptrs(nativeChain, correct, chainPointer, entNumber); get_ent_from_eptr(chainPointer, entity); // <--Needs conversion from DB_LIST_ENT_PTR ** to DB_LIST_ENT_PTR auto geo = Geometry::RetrieveEntity(entity[0].ent_idn); auto geoArray = gcnew System::Collections::Generic::List<Geometry^>(); auto chainArray = ChainManager::ChainGeometry(geoArray->ToArray()); returnChain = chainArray[0]; return returnChain; } static Mastercam::Database::Chain^ SelectionManager::GetNetChain2(CHAIN* nativeChain) { Chain^ returnChain = nullptr; IntPtr point; DB_LIST_ENT_PTR nativeChainPoint; nativeChainPoint = nativeChain; //<--Needs conversion from CHAIN* to DB_LIST_ENT_PTR point = nativeChainPoint; //<--Needs conversion from DB_LIST_ENT_PTR to IntPtr returnChain = NETHookApiReflection::ConstructChain(point); return returnChain; } Chain^ NETHookApiReflection::ConstructChain (IntPtr ptr) { Chain^ chain = nullptr; if (ptr != IntPtr::Zero) { ConstructorInfo^ ChainConstructor = ReflectChainConstructorInfo(); Object^ o = ChainConstructor->Invoke (gcnew array<Object^> { ptr }); if (o != nullptr) // Should never be, but just in case... { chain = static_cast<Chain^> (o); } } return chain; }
  5. I'm stumped. How to get a IntPtr from a CHAIN* ?? static Mastercam::Database::Chain^ SelectionManager::GetNetChain(CHAIN* nativeChain) { System::IntPtr cPtr = NETHookApiReflection::GetFieldValue(nativeChain, "Data"); //<- Error Chain^ chain = nullptr; if (cPtr != IntPtr::Zero) { chain = NETHookApiReflection::ConstructChain(cPtr); } return chain; }
  6. The picture I added in the previous post is how everything starts. It's then separated like this new picture. Going in a counter clockwise direction around the initial image, one color must be offset one direction and the other color must be offset in the opposite direction. This is impossible to control with an open chain. If I can control the order of entities in the chain, I will be able to control the direction of the open chain. At least that's how things sound in my head The code I've come up with so far :: #Rookie Struggles static Mastercam::Database::Chain^ SelectionManager::ChainLinker (Mastercam::Database::Geometry^ GEO1){ bool successful; Mastercam::Database::Chain^ returnChain; // NETHook side chain CHAIN* tempChain; // CLI side chain ent entity; // blank entity GetEntityByID(GEO1->GetEntityID(), entity, &successful); // Gets ent value and assigns to entity std::vector<ent> entities; // Blank vector list needed for CreateChain method entities.push_back(entity); // adds entity to vector list tempChain = SelectionManager::CreateChain(entities); // Sends Entity List to chain creator (in order) //TODO -> Convert from CHAIN* to Mastercam::Database::Chain^ return returnChain; } /// <summary> Construct a Chain from the supplied list of entities. </summary> /// <param name="entities"> The (in order!) line and/or arc entities. </param> /// <returns> The new chain if successful, else null. </returns> /// static CHAIN* SelectionManager::CreateChain(std::vector<ent>& entities){ static CHAIN* SelectionManager::CreateChain(std::vector<ent>& entities) { CHAIN* chain; short err = alloc_chain(&chain, FALSE /* partial*/); bool result = (err == 0 && chain != nullptr); if (result) { CHAIN_ENT* last_chain_ent = nullptr; for (auto& entity : entities) { short errCode = add_curve_to_chain(&entity, 0, TRUE, 0, chain, &last_chain_ent); if (errCode != CHAIN_OK) // bail out ! { result = false; break; } } } return (result ? chain : nullptr); }
  7. Going to be trying this today. If you remember me trying to control the direction of open chains, that's what this is all about. Sure, they are all open chains, but they don't start that way. All the green need to go towards the inside and all the blue needs to go towards the outside. So all the greens get chained together (open chain) and all the blue get chained together (open chain). But since they start from a closed chain, I can put them in the correct order. I believe this is the only way to achieve the desired result.
  8. "The entity data is changed to the new entity" even though the entity itself is not moved sneaky sneaky. Appreciate the help as always!
  9. CopyAndTranslate sends back Geometry Entities, so I thought I'd have to commit them to the database. I'll give that a try later tonight. Thanks
  10. I guess I got it correct. It now returns a list of entities, in order, starting with the entity I mention. Does it chain the list correctly? Oh absolutely not. TBC! List<int> chainSorter(Chain inChain, int startId) { var tempListIn = new List<int>(); var tempListOut = new List<int>(); 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; } var finalList = chainSorter(chain, entity.GetEntityID()); var geoList = new List<Geometry>(); foreach (var entity2 in finalList){ geoList.Add(Geometry.RetrieveEntity(entity2)); } var newChains = ChainManager.ChainGeometry(geoList.ToArray()); foreach (var newChain in newChains){ var newChainGeo = ChainManager.GetGeometryInChain(newChain); foreach (var testPiece in newChainGeo){ testPiece.Color = 15; testPiece.Commit(); DialogManager.OK("", ""); } }
  11. Exactly my question I guess it's a bool that needs to be defined. Why are lists so difficult I'll probably have to have the result of the function be a list though. I can't get it to return a single chain, only an array of chains. bool predicate(int i){ if (i == startId){ return true; } return false; }
  12. In the name of progress! Will it work? Who knows! Not clear on how the predicate works though and finding specific examples instead of a general definition. Chain[] chainSorter(Chain inChain, Chain[] outChain, int startId) { var tempListIn = new List<int>(); var tempListOut = new List<Geometry>(); var geo = ChainManager.GetGeometryInChain(inChain); foreach (var ids in geo) { var geoId = ids.GetEntityID(); tempListIn.Add(geoId); } if (tempListIn[0] != startId) { Predicate<int> predicate = startId; // <- Error var index = tempListIn.FindIndex(predicate); var listSize = tempListIn.Count; for (var i=index; i<listSize; i++){ tempListOut.Add(Geometry.RetrieveEntity(i)); } for (var i = 0; i < index; i++){ tempListOut.Add(Geometry.RetrieveEntity(i)); } } outChain = ChainManager.ChainGeometry((tempListOut.ToArray())); return outChain; }
  13. In the ChainInterop though, Mastercam::Database::Geometry ^ChainData::FirstEntity::get () { return m_FirstEntity; } // Note: The setter is for internal use only! void ChainData::FirstEntity::set (Mastercam::Database::Geometry ^entity) { m_FirstEntity = entity; } So I was hoping it really was that easy.
  14. I'm feeling pretty dumb about this one. My code will copy an entity X+0.001 and Y+0.001 but that result will then be moved back down X-0.001 and Y-0.001 instead of the original geometry. The tooltip says the method does not move the original geometry so I'm confused. var freshChain = ChainManager.GetMultipleChains(""); var origin = new Point3D(0, 0, 0); var tempList1 = new List<int>(); var tempList2 = new List<int>(); foreach (var chain in freshChain) { var freshGeo = ChainManager.GetGeometryInChain(chain); foreach (var entity in freshGeo){ var changePoint1 = new Point3D(0.001,0.001, 0); var changePoint2 = new Point3D(-0.001, -0.001, 0); var tempGeo1 = entity.CopyAndTranslate(origin, changePoint1, new MCView(), new MCView()); var tempGeo2 = entity.CopyAndTranslate(origin, changePoint2, new MCView(), new MCView()); tempGeo1.Commit(); tempGeo2.Commit(); tempList1.Add(tempGeo1.GetEntityID()); tempList2.Add(tempGeo2.GetEntityID()); } }
  15. The intent is to have a result match that of the Drafting->Window without user input. *picture added* I've found calc_ordinate_dimension(), struct dm_params, and class DllImpExp DimParams. Searching the forums had me led to "autodim" which used to be a CHook that was later changed to "create-drafting-dimension-ordinate-window". src: I'm not finding anything relative to 'window' within the 'ordinate' search results though. What function will best serve my intent?
  16. What are the steps for converting a Mastercam::Database::Chain to a CHAIN *pChain?
  17. Ah, found the magic answer. Search for general idea, find in LIB and add that LIB, then Find in files (mastercam folder) the function name and then #include that file.h I needed #include "SolidsExtrude_CH.h" but didn't see it in my external dependencies so I didn't think I could use it.
  18. Finally got it to work. Admin rights are awful So I found the lib file I'm going to use, but it's not letting me call the method. What else am I missing? Extrude solid from chain and then cut that solid with other chains. I'll move on to draft dimensions after that. Does adding the LIB add more .h files? And I need to find which one it lives in?
  19. I get hit with a "You do not have permission to view this content." error. I contacted Sales but they seem confused as well Congratulations on retirement by the way!
  20. Is there a fast way to search all those libraries? Ex. What library contains the *insert example here*
  21. Brilliant! Thank you soooo much! Solution :: CLI :: static bool SelectionManager::AlterContourFinish(double maxStepdown, double minDepth, double maxDepth) { for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index) { auto op = TpMainOpMgr.GetMainOpList()[index]; if (op && (op->opcode == TP_SRF_FIN_CONTOUR ) && op->db.select_flag == true) { bool success = false; DB_LIST_ENT_PTR operationPointer = nullptr; //set cut method to zig zag op->u.r_contour.common.max_stepdown = maxStepdown; op->u.f_contour.depth.max_depth = maxDepth; op->u.f_contour.depth.min_depth = minDepth; operation_manager(op, OPMGR_REWRITE, &operationPointer, &success); if (success == false) { //TO DO : Handle any errors rewriting the operation } } } return true; } static bool SelectionManager::AlterPencilFinish(bool status, double limitOne, double limitTwo) { for (auto index = 0; index < TpMainOpMgr.GetMainOpList().GetSize(); ++index) { auto op = TpMainOpMgr.GetMainOpList()[index]; if (op && (op->opcode == TP_SRF_FIN_PENCIL ) && op->db.select_flag == true) { bool success = false; DB_LIST_ENT_PTR operationPointer = nullptr; //set cut method to zig zag op->u.f_pencil.limit.on = status; op->u.f_pencil.limit.z1 = limitOne; op->u.f_pencil.limit.z2 = limitTwo; operation_manager(op, OPMGR_REWRITE, &operationPointer, &success); if (success == false) { //TO DO : Handle any errors rewriting the operation } } } return true; }; NetHook :: var contourList = new List<int>(); var pencilList = new List<int>(); var selectedOps = SearchManager.GetOperations(true); var surfaceFinishContourOpID = Mastercam.IO.Interop.SelectionManager.GetOperations(15); var surfaceFinishPencilOpID = Mastercam.IO.Interop.SelectionManager.GetOperations(39); foreach (var op in surfaceFinishContourOpID) { foreach (var thisOp in selectedOps) { var selectedOp = thisOp.GetOperationID(); if (selectedOp == op) { contourList.Add(selectedOp); } } } foreach (var op in surfaceFinishPencilOpID) { foreach (var thisOp in selectedOps) { var selectedOp = thisOp.GetOperationID(); if (selectedOp == op) { pencilList.Add(selectedOp); } } } foreach (var op in contourList) { Mastercam.IO.Interop.SelectionManager.AlterContourFinish(0.2, -0.2, -0.2); var thisOp = SearchManager.GetOperation(op); thisOp.MarkDirty(); thisOp.Commit(false); } OperationsManager.RefreshOperationsManager(true); foreach (var op in pencilList) { Mastercam.IO.Interop.SelectionManager.AlterPencilFinish(true, -0.020, 0.00); var thisOp = SearchManager.GetOperation(op); thisOp.MarkDirty(); thisOp.Commit(false); } OperationsManager.RefreshOperationsManager(true); return MCamReturn.NoErrors;
  22. Copied the DLL file again and it works I mean, it found the method. The code itself totally doesn't work It doesn't actually SET any data
  23. VIsual studio is having no problem reading the method. Even shows the the inputs needed.
  24. It won't let me mark it 'public' because it says ": expected". Your portion also doesn't say public, is there another way to mark it so? Everything is inside the public class "public ref class SelectionManager" My code is directly under yours, inside the same file. Since yours works, I'd assume the dll was copied correctly.

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