Moving a sketch circle tangent too two projected arcs

Moving a sketch circle tangent too two projected arcs

rusty.bird
Advocate Advocate
960 Views
2 Replies
Message 1 of 3

Moving a sketch circle tangent too two projected arcs

rusty.bird
Advocate
Advocate

I made a script to move a sketched circle tangent between two projected arcs but it is not moving when I run it.  Can anybody help me figure out why its not working properly?   I have attached some pictures and the file aswell. 

  

Here is my script:

	// Prompt the user to select a plane.
	Ptr<Selection> selection1 = ui->selectEntity("Select a Face On the Rolls", "Faces");
	Ptr<BRepFace> plane1 = selection1->entity();

	// Get the selected face and create a sketch on it
	Ptr<Sketches> skt = rootComp->sketches();
	Ptr<Sketch> skt1 = skt->addWithoutEdges(plane1);

	Ptr<SketchCurves> curves = skt1->sketchCurves();

	Ptr<SketchCircles> circles = curves->sketchCircles();

	// Create a circle with a diameter
	Ptr<SketchCircle> circle1 = circles->addByCenterRadius(Point3D::create(0, -30, 0), 20);
	if (!circle1)
		return false;

	Ptr<SketchDimensions> dims = skt1->sketchDimensions();

	// Add the dimension to the circle
	Ptr<SketchDimension> dim1 = dims->addDiameterDimension(circle1, adsk::core::Point3D::create(0, 0, 0));
	if (!dim1)
		return false;

	// Prompt the user to select a bRepEdge.
	Ptr<Selection> selection2 = ui->selectEntity("Select The Round Edge On A Roll", "Edges");
	Ptr<BRepEdge> edge1 = selection2->entity();

	Ptr<SketchCurve> proj1;
	proj1 = skt1->project(edge1);

	// Prompt the user to select another bRepEdge.
	Ptr<Selection> selection3 = ui->selectEntity("Select The Other Round Edge On A Roll", "Edges");
	Ptr<BRepEdge> edge2 = selection3->entity();

	Ptr<SketchCurve> proj2;
	proj2 = skt1->project(edge2);

	Ptr<GeometricConstraints> constraints = skt1->geometricConstraints();

	Ptr<GeometricConstraint> tanCon1 = constraints->addTangent(circle1, proj1);
	if (!tanCon1)
		return false;

	Ptr<GeometricConstraint> tanCon2 = constraints->addTangent(circle1, proj2);
	if (!tanCon2)
		return false;

 

0 Likes
Accepted solutions (1)
961 Views
2 Replies
Replies (2)
Message 2 of 3

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi,

 

Your problem is with variables proj1 and proj2.

 

This sentence:

 

proj1 = skt1->project(edge1);

 

returns an ObjectCollection and you are expecting a SketchCurve as the proj1 variable was declared.

 

You need to change this sentence by:

 

proj1 = skt1->project(edge1)->item(0);

 

 

The same fix need to be made for proj2.

 

It solved the problem in my tests.

 

Regards,

Jorge Jaramillo

 

Message 3 of 3

rusty.bird
Advocate
Advocate

Yes this worked.  Thanks 

0 Likes