coincidentConstraint Does Not Work

coincidentConstraint Does Not Work

tperam
Advocate Advocate
837 Views
4 Replies
Message 1 of 5

coincidentConstraint Does Not Work

tperam
Advocate
Advocate

 

coincidentConstraint Does Not Work,

 

Hi, 

    the following C++ Code to Test addCoincident(point, entity) Does Not Work.

 

I will appreciate if someone can make it work.

 

Regards,

Thurai

 

////////////////////////////////////////////////////////////

extern "C" XI_EXPORT bool run(const char* context)
{
 Ptr<Application> app = Application::get();
 if (!app)
  return false;
 ui = app->userInterface();
 if (!ui)
  return false;
 Ptr<Documents> docs = app->documents();
 if (!docs)
  return false;
 // Create a document.
 Ptr<Document> doc = docs->add(DocumentTypes::FusionDesignDocumentType);
 if (!doc)
  return false;
 Ptr<Design> design = app->activeProduct();
 if (!design)
  return false;
 // Get the root component of the active design
 Ptr<Component> rootComp = design->rootComponent();
 if (!rootComp)
  return false;
 // Create sketch
 Ptr<Sketches> sketches = rootComp->sketches();
 if (!sketches)
  return false;
 Ptr<Sketch> sketch = sketches->add(rootComp->xYConstructionPlane());
 if (!sketch)
  return false;
 Ptr<SketchCurves> sketchCurves = sketch->sketchCurves();
 if (!sketchCurves)
  return false;
 // Draw some circles.
 Ptr<SketchCircles> sketchCircles = sketchCurves->sketchCircles();
 if (!sketchCircles)
  return false;
 Ptr<SketchLines> sketchLines = sketchCurves->sketchLines();
 if(!sketchLines)
  return false;
 // Get sketch texts
 Ptr<SketchPoints> sketchPoints = sketch->sketchPoints();
 if (!sketchPoints)
  return false;

 /* Add Coincident Constraint */
// returnValue = geometricConstraints_var->addCoincident(point, entity);
 // Use the returned lines to add some constraints.
 Ptr<GeometricConstraints> constraints = sketch->geometricConstraints();
 if(!constraints)
  return false;

    Ptr<Point3D> point3D = Point3D::create(0, 0, 0);
 Ptr<SketchPoint> sketchPoint = sketchPoints->add(point3D);
 if (!sketchPoint)
  return false;

 Ptr<Circle3D> circle3D = sketchCircles->addByCenterRadius(Point3D::create(8, 5, 0), 5);
 if (!circle3D)
  return false;
 Ptr<Point3D> center = circle3D->center();
 Ptr<SketchPoint> sketchPoint2 = sketchPoints->add(center);
 if (!sketchPoint2)
  return false;
 Ptr<CoincidentConstraint> coincidentConstraint = constraints->addCoincident(sketchPoint2, sketchPoint);
 if(!coincidentConstraint)
 return false;
 
 return true;
}

#ifdef XI_WIN
#include <windows.h>
BOOL APIENTRY DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved)
{
 switch (reason)
 {
 case DLL_PROCESS_ATTACH:
 case DLL_THREAD_ATTACH:
 case DLL_THREAD_DETACH:
 case DLL_PROCESS_DETACH:
  break;
 }
 return TRUE;
}
#endif // XI_WIN

////////////////////////////////////////////////////////////

 

 

 

0 Likes
Accepted solutions (1)
838 Views
4 Replies
Replies (4)
Message 2 of 5

prainsberry
Autodesk
Autodesk

What is the outcome of this script and what is the outcome you are expecting?  I think I may know the issue, but want to make sure I understand your problem first.



Patrick Rainsberry
Developer Advocate, Fusion 360
0 Likes
Message 3 of 5

tperam
Advocate
Advocate

Hi Patrick,

    I was expecting Circle3D to move from sketchPoint2((8, 5, 0) to sketchPoint(0,0,0).

 

Thanks,

Regards,

Thurai

0 Likes
Message 4 of 5

prainsberry
Autodesk
Autodesk
Accepted solution

OK, yah thats what I thought you were going for. 

In your code you are creating: 

sketchPoint2, sketchPoint

These are now just generic new points in the sketch, they are not associated or fixed to the positions where you created them.  So effectively what you have done is create two new points and made them coincident. Which doesn't really do much.  

 

What you want to do, and I apologize for any syntax errors, C++ is not my expertise.  But basically you want to create a constraint between the actual center "Sketch Point" of the circle and the fixed origin of the sketch.

Ptr<CoincidentConstraint> coincidentConstraint = constraints->addCoincident(circle3D->centerSketchPoint, sketch->originPoint);

 



Patrick Rainsberry
Developer Advocate, Fusion 360
Message 5 of 5

tperam
Advocate
Advocate

Hi Painsberry,

 

The following as you suggested Worked Okay. 

 

Thanks.

 

 // Use the returned lines to add some constraints.
 Ptr<GeometricConstraints> constraints = sketch->geometricConstraints();
 if(!constraints)
  return false;

 Ptr<SketchCircle> circle5 = sketchCircles->addByCenterRadius(Point3D::create(8, 5, 0), 5);
 if (!circle5)
  return false;
 
 Ptr<CoincidentConstraint> coincidentConstraint = constraints->addCoincident(circle5->centerSketchPoint(), sketch->originPoint());
 if(!coincidentConstraint)
  return false;
0 Likes