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: 

Move face with MoveFeature not working

4 REPLIES 4
Reply
Message 1 of 5
rolandas.vegis
101 Views, 4 Replies

Move face with MoveFeature not working

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?

4 REPLIES 4
Message 2 of 5

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

Message 3 of 5

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.
Message 4 of 5

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

Message 5 of 5

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.

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