Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Move face with MoveFeature not working

rolandas_vegis
Advocate

Move face with MoveFeature not working

rolandas_vegis
Advocate
Advocate

Hello,

 

I have been trying to move a face using API and it does not seem to be working. I always get invalidEntity error.

#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>

using namespace adsk::core;
using namespace adsk::fusion;

extern "C" XI_EXPORT bool run(const char* context)
{
	auto app = Application::get();
	const auto select = app->userInterface()->activeSelections()->item(0);
	Ptr<BRepFace> face = select->entity();
	const auto moveFeatures = face->body()->parentComponent()->features()->moveFeatures();

	const auto objectCollection = ObjectCollection::create();
	objectCollection->add(face);

	Ptr<Vector3D> normal;
	face->evaluator()->getNormalAtParameter(Point2D::create(0.5, 0.5), normal);
	normal->scaleBy(10);
	auto matrix = Matrix3D::create();
	matrix->translation(normal);
	const auto input = moveFeatures->createInput(objectCollection, matrix);
	const auto feature = moveFeatures->add(input);
	if (!feature)
	{
		std::string error;
		app->getLastError(&error);
		app->userInterface()->messageBox(error);
	}

	return true;
}

 

As you can see in sample code it is as simple as it gets, yet I get errors. 

Is this a bug or am I doing something wrong?

0 Likes
Reply
369 Views
4 Replies
Replies (4)

Jorge_Jaramillo
Collaborator
Collaborator

Hi @rolandas_vegis ,

 

The problem you have in your script is on line #15.  On it you selected a body's face to be moved.

The MoveFeature is intended to works over bodys, not over faces as it states in the API documentation:

 

inputEntitiesObjectCollectionAn ObjectCollection containing the entities to move. This collection can only contain BRepBody objects in parametric modeling. It can be BRep bodies, T-Spline bodies, mesh bodies mixed or faces and features mixed in non-parametric modeling.

 

I believe you might need a ExtrudeFeature instead.

 

Hope this help.

 

Regards,

Jorge

0 Likes

rolandas_vegis
Advocate
Advocate
But you can move faces using move command in the UI. And in documentation it says: "or faces and features mixed in non-parametric modeling."

For my purposes move would be better than extrude.
0 Likes

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

 

Yes, you're right.

 

Two answers about what you wrote:

1.  In non-parametric mode your script works well.  Just disable capture design history.

Good point. I didn't read it completely as you did.

 

 

 

2. For parametric design:

 

You can move a face in the UI, but it is not registered as a MoveFeature in the component's MoveFeatures's property.

You can check it with this commands before and after you make the move in the UI (run them from the text commands (make it visible with Ctrl-Alt-C or File > View > Show Text Commands)):

# set app variable
app = adsk.core.Application.get()

# print moveFeatures's and extrudeFeatures's in root component
app.activeProduct.rootComponent.features.moveFeatures.count 
app.activeProduct.rootComponent.features.extrudeFeatures.count

# print type of action on last item in the timeline
app.activeProduct.timeline.item(app.activeProduct.timeline.count - 1).entity

 

In my case I got this before:

 

wtallerdemadera_0-1660238403747.png

 

And this is the output after I made a move face in the UI:

wtallerdemadera_1-1660238640078.png

 

Take a look at the counters, their remain the same. And the last sentence returned an error trying to the get .entity property for this type of action (this use to happen with other types of operations like adding a canvas, and some others).

So, with the information in the data model of the design at the moment, I don't know the type of action it was registered as, but for sure, it isn't move neither extrude feature.  Something weird here. Isn't it?

 

Regards,

Jorge

0 Likes

rolandas_vegis
Advocate
Advocate
It is also weird that it only works in non-parametric mode, while using Fusion tools works in parametric also. Official Autodesk answer would be nice.
0 Likes