Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Moving a sketch circle tangent too two projected arcs

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
rusty.bird
148 Views, 2 Replies

Moving a sketch circle tangent too two projected arcs

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;

 

2 REPLIES 2
Message 2 of 3

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

Yes this worked.  Thanks 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report