Scale selected item

Scale selected item

p_krola
Enthusiast Enthusiast
443 Views
2 Replies
Message 1 of 3

Scale selected item

p_krola
Enthusiast
Enthusiast

I would like to scale the selected item. However, executing the script below does not scale.

 

 

#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>
#include <iostream>
#include <format>
#include <string>

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


Ptr<Application> app;
Ptr<UserInterface> ui;

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

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

	// Have a body selected.
	Ptr<Selection> select = ui->selectEntity("Select a body", "Bodies");
	Ptr<BRepBody> body = select->entity();

	Ptr<Product> product = app->activeProduct();


	Ptr<Design> design = product;

	// Get the root component of the active design
	Ptr<Component> rootComp = design->rootComponent();

	// Create an uniformed input for scale feature input

	
	Ptr<ObjectCollection> inputColl = ObjectCollection::create();

	inputColl->add(body);
	

	// Point for scale
	Ptr<Point3D> centerPoint = Point3D::create(0, 0, 0);

	Ptr<ValueInput> scaleFactor = ValueInput::createByReal(10);

	Ptr<Features> feats = rootComp->features();

	Ptr<ScaleFeatures> scales = feats->scaleFeatures();

	Ptr<ScaleFeatureInput> scaleUniformInput = scales->createInput(inputColl, centerPoint, scaleFactor);

	Ptr<ScaleFeature> scaleUniform = scales->add(scaleUniformInput);


	app->log("scale");



	return true;
}

#ifdef XI_WIN

#include <windows.h>

BOOL APIENTRY DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved)
{
	switch (reason)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

#endif // XI_WIN

 

 

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

john.kirchner
Autodesk
Autodesk
Accepted solution

You are most likely getting an error along the lines of "invalid ref point"

The point arg for the createInput should be one of these types:

johnkirchner_0-1663869642765.png


What you are passing in is a Point3D type. If you follow the Scale Feature API Sample the centerPoint var created with Point3D::create(0,0,0) gets used to create a SketchCircle. The SketchCircle comes with a SketchPoint when it's created which is grabbed at basePt = sketchPts->item(0). basePt is ultimately what is used as the point arg in the createInput method.

One thing you could change the input point to is maybe a BRepVertex on the body - you can get that with body->verticies()->item(0) with the item # being up to you which point you want.

Otherwise if you just want the origin you can grab that with rootComp->originConstructionPoint()

So:

Ptr<ConstructionPoint> centerPoint = rootComp->originConstructionPoint();

 

 


Let me know if that helps!



0 Likes
Message 3 of 3

p_krola
Enthusiast
Enthusiast
Accepted solution

Thank you very much for help. I was able to fix this problem. The second error was related to the component. scaleFeatures needs the Component to which belongs to the body .

 

Ptr<Component> comp = body->parentComponent();

Ptr<ScaleFeatures> scales = comp->features()->scaleFeatures();

 

 

Everything works fine now:)

 

0 Likes