Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Creation of a CircularPatternFeature of a component using the C++ API

rudisoft
Enthusiast

Creation of a CircularPatternFeature of a component using the C++ API

rudisoft
Enthusiast
Enthusiast

Why doesn't this work?

		void makeCircularPattern(Ptr<Component> component, Ptr<Component> root) {
			Ptr<ObjectCollection>inputEntites = adsk::core::ObjectCollection::create();
			if (!inputEntites) return;
			inputEntites->add(component);
			Ptr<CircularPatternFeatures>circularFeats = root->features()->circularPatternFeatures();
			if (!circularFeats) return;
			Ptr<CircularPatternFeatureInput>circularFeatInput = circularFeats->createInput(inputEntites, component->yConstructionAxis());
			if (!circularFeatInput) return;
			circularFeatInput->quantity(ValueInput::createByReal(3));
			circularFeatInput->totalAngle(ValueInput::createByString("360 deg"));
			Ptr<CircularPatternFeature>circularFeat = circularFeats->add(circularFeatInput);
			if (!circularFeat) return;
			Application::get()->userInterface()->messageBox(""+circularFeat->quantity());
		}

There are some components in the document already, they're all created by API calls, so I have their handles easily. Since I want to make a bunch of circular patterns, the best thing to do is obviously to create a private void function in the CommandEventHandler.

 

I've tried various different ways of doing this, but the Ptr<CircularPatternFeature>circularFeat = circularFeats->add(circularFeatInput); would always return NULL. Even though there's no C++ sample for CircularPattern Feature API Sample API Sample, It looks pretty straight forward to generate the corresponding C++ sample. And it compiles with a breeze.

 

What I've tried:

- Use Ptr<CircularPatternFeatures>circularFeats = root->features()->circularPatternFeatures(); instead of Ptr<CircularPatternFeatures>circularFeats = component->features()->circularPatternFeatures(); also fails;

- Using bodies instead of components in inputEntites->add(body); works fine just like in the examples.

 

Everything else before works like a charm.

 

Any idea?

 

Thanks and greets.

0 Likes
Reply
545 Views
3 Replies
Replies (3)

ekinsb
Alumni
Alumni

You don't actually pattern the component but instead pattern an occurrence (which references a component).  The UI makes this a bit confusing but you can read more about it here: http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
1 Like

rudisoft
Enthusiast
Enthusiast

Hi Brian,

 

thanks for your answer. I believe I have thoroughly understood the concept of occurrences. Following your suggestion this means, that whatever I want to pattern circularly, it needs to be the component and not it's occurrence, right?

 

So, I've redone parts of the code as follows. I'm aware this willrotate the component around it's yConstructionAxis.

 

 

void makeCircularPattern(Ptr<Component> component) {
	Ptr<ObjectCollection>inputEntites = adsk::core::ObjectCollection::create();
	if (!inputEntites) return;
	inputEntites->add(component);
	Ptr<CircularPatternFeatures>circularFeats = component->features()->circularPatternFeatures();
	if (!circularFeats) return;
	Ptr<CircularPatternFeatureInput>circularFeatInput = circularFeats->createInput(inputEntites, component->yConstructionAxis());
	if (!circularFeatInput) return;
	circularFeatInput->quantity(ValueInput::createByReal(3));
	circularFeatInput->totalAngle(ValueInput::createByString("360 deg"));
	Ptr<CircularPatternFeature>circularFeat = circularFeats->add(circularFeatInput);
	if (!circularFeat) return;
	Application::get()->userInterface()->messageBox(""+circularFeat->quantity());
}

this is how it's called:
Ptr<Design> design = _app->activeProduct();
Ptr<Component> root = design->rootComponent();
Ptr<Occurrences>occurences = root->occurrences();
[...]
Ptr<Occurrence>shaftOccurrence = occurences->addNewComponent(Matrix3D::create()); // the occurences can be reused
shaftOccurrence->activate();
Ptr<Component>shaft = shaftOccurrence->component();
Ptr<Sketches> shaftsketches = shaft->sketches();
Ptr<Sketch> shaftsketch = shaftsketches->add(shaft->xZConstructionPlane());
shaftsketch->name("shaft bottom sketch");
Ptr<SketchCircles>shaftCircles = shaftsketch->sketchCurves()->sketchCircles();
Ptr<SketchCircle>shaftToHousing = shaftCircles->addByCenterRadius(Point3D::create(camShaftHolesRadius, 0, 0), housingRollerInnerDiam / 2);
shaft->features()->extrudeFeatures()->addSimple(shaftsketch->profiles()->item(0),
ValueInput::createByReal(-17), FeatureOperations::NewBodyFeatureOperation);
makeCircularPattern(shaft);


The line Application::get()->userInterface()->messageBox(""+circularFeat->quantity()); never gets executed since the circularFeats->add(circularFeatInput) returns null.

 

I also tried to pattern the occurrence instead of the component:

 

void makeCircularPattern(Ptr<Occurrence> component, Ptr<Component>root) {
	Ptr<ObjectCollection>inputEntites = adsk::core::ObjectCollection::create();
	if (!inputEntites) return;
	inputEntites->add(component);
	Ptr<CircularPatternFeatures>circularFeats = root->features()->circularPatternFeatures();
	if (!circularFeats) return;
	Ptr<CircularPatternFeatureInput>circularFeatInput = circularFeats->createInput(inputEntites, root->yConstructionAxis());
	if (!circularFeatInput) return;
	circularFeatInput->quantity(ValueInput::createByReal(3));
	circularFeatInput->totalAngle(ValueInput::createByString("360 deg"));
	Ptr<CircularPatternFeature>circularFeat = circularFeats->add(circularFeatInput);
	if (!circularFeat) return;
	Application::get()->userInterface()->messageBox(""+circularFeat->quantity());
}
by calling it like this:
makeCircularPattern(shaftOccurrence,root);

 

 

Here, I had to pass root component since the occurrencees don't have features() and yConstructionAxis().

 

And it all worked!

 

Maybe we keep this for reference in case someone else runs into the same problem.

 

Thanks for helpting again, Brian.

 

 

0 Likes

rudisoft
Enthusiast
Enthusiast

This is the result now.

0 Likes