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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bug with ProjectToSurface (or I am miss-understand occurrence/proxies) ?

Message 1 of 2
315 Views, 1 Reply

Bug with ProjectToSurface (or I am miss-understand occurrence/proxies) ?

I've been using ProjectToSurface() a lot in a project. But when I started to move the base Occurrence it basically stopped working the way I would expect. 


I have a very simple project with a single added component and by associated occurrence. I apply a transform when I construct this, Then I create my geometry as normal, always referencing this new component, never root. Everything works fine, until I use ProjectToSurface() then my projection point ends up in the wrong place. 


It looks like it has been transformed to exactly TWICE what my original Transform was on the original occurrence.



Here is a simple C++ example: (just the run() not the DllMain)


extern "C" XI_EXPORT bool run(const char* context)
	app = Application::get();
	if (!app)
		return false;

	ui = app->userInterface();
	if (!ui)
		return false;

	Ptr<Design> ptrDesign = app->activeProduct();

	// Setup a matrix to move the new component
	Ptr<Matrix3D> mTranslation = adsk::core::Matrix3D::create();
	Ptr<Vector3D> v3DAction = adsk::core::Vector3D::create(0, 0, 50);

	// Construct a new Component & Occurrence which is translated to +50 Y
	Ptr<Component> ptrChildComponent = ptrDesign->rootComponent()->occurrences()->addNewComponent(mTranslation)->component();
	ptrChildComponent->name("Moved Component");

	// Construct a simple box
	Ptr<Sketch> ptrBoxSketch = ptrChildComponent->sketches()->addWithoutEdges(ptrChildComponent->xZConstructionPlane());
	ptrBoxSketch->sketchCurves()->sketchLines()->addTwoPointRectangle(Point3D::create(0,  0, 0), Point3D::create(20, 20, 0));
	Ptr<ExtrudeFeatures> extrudeFeatures = ptrChildComponent->features()->extrudeFeatures();	
	Ptr<ExtrudeFeature> oExtrudedFeature = extrudeFeatures->addSimple(ptrBoxSketch->profiles()->item(0), ValueInput::createByReal(20), FeatureOperations::NewBodyFeatureOperation);
	Ptr<BRepBody> ptrBox = oExtrudedFeature->bodies()->item(0);

	// Grab the Front face oif the box	
	Ptr<BRepFace> oBoxFrontFace = ptrBox->faces()->item(5);
	// Define a point in Model space just in-front of the box
	Ptr<Point3D> pInitialPoint = Point3D::create(oBoxFrontFace->centroid()->x(), oBoxFrontFace->centroid()->y()-25, oBoxFrontFace->centroid()->z());

	// Construct a new sketch so that we can create a sketch point
	Ptr<Sketch> ptrSketchPointSketch = ptrChildComponent->sketches()->addWithoutEdges(ptrChildComponent->xZConstructionPlane());	
	auto oSketchPoint = ptrSketchPointSketch->sketchPoints()->add(ptrSketchPointSketch->modelToSketchSpace(pInitialPoint));

	// Now create a sketch on the front face of the box body we created early (in real life this might be at an angle, which is why we're projecting)
	Ptr<Sketch> ptrWorkingSketch = ptrChildComponent->sketches()->addWithoutEdges(oBoxFrontFace);

	// Now project the sketchpoint onto the working sketch which we'll use
	std::vector<Ptr<BRepFace>> faces;

	std::vector<Ptr<Base>> points;

	auto oResult = ptrWorkingSketch->projectToSurface(faces, points, SurfaceProjectTypes::AlongVectorSurfaceProjectType, ptrChildComponent->yConstructionAxis());

	// Make it easy to see what's happened

	return true;


Am I using these child objects in the wrong way? I don't care about the multiple occurrences for a given component, I just want child components of my root in different places.


Side note:

I am having the exact same issue with BoundaryFill in the API. It gives me transient BRepBodies from its cells which are in the wrong place (same issue), but in it's case when I complete the operation it does return me geometry in the original location, but picking the correct cell is difficult as they're not where they should be. I can post a repro of that too.

Labels (1)
Message 2 of 2

Thanks for this case.

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

Post to forums