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: 

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

3 REPLIES 3
Reply
Message 1 of 4
rudisoft
343 Views, 3 Replies

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

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.

3 REPLIES 3
Message 2 of 4
ekinsb
in reply to: rudisoft

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
Message 3 of 4
rudisoft
in reply to: ekinsb

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.

 

 

Message 4 of 4
rudisoft
in reply to: rudisoft

This is the result now.

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