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: 

Custom Feature API Preview - Feedback Thread

80 REPLIES 80
Reply
Message 1 of 81
prainsberry
6760 Views, 80 Replies

Custom Feature API Preview - Feedback Thread

Fusion 360 Custom Feature APIFusion 360 Custom Feature API

 

 

 

 

 

 

 

With the release of Fusion 360 today, we are very excited to announce the availability of a preview of the new Custom Feature API.  This is a long-awaited capability for the Fusion 360 API and our first iteration is now available Please note we are considering this “Preview” functionality as there are some limitations and only some specific workflows that we support That said this a MAJOR enhancement to the Fusion 360 API 

 

You can now not only define a custom command dialog for your add-in, but you can actually define it as a full feature definition This means that parametric timeline updates, model parameter changes and user edits will all now behave as expected for any other feature in Fusion 360 There is a lot of information to digest for this one, so if this interests you, check out our help documentation and learn more about this functionality. 

 

We would love to hear more about how you would like to use it, what you have built, or would like to build.  We would like to use this thread to capture feedback about the current capabilities, as well as what you would like to see next.  



Patrick Rainsberry
Developer Advocate, Fusion 360
Tags (1)
Labels (1)
80 REPLIES 80
Message 21 of 81
ginavenolia
in reply to: ginavenolia

I see now that this was addressed in earlier messages on this thread. Sorry for the repeat. I'll use 'pcs' until a better solution is provided.
Message 22 of 81

@florian.pommereningDGUYA I REALLY appreciate this feedback and apologize for the delay in the response. 

In my own testing I have encountered most of the issues you raised.  I wanted to get back to you briefly, but I intend to put together a very detailed response to your questions along with some of the others raised in this thread.  It might take a couple days, but I am thinking that some type of comprehensive "FAQ" will go a long way.  



Patrick Rainsberry
Developer Advocate, Fusion 360
Message 23 of 81
prainsberry
in reply to: ginavenolia

@ginavenolia Thank you also for this great feedback.  The key issue you are facing with multiple bodies and selections is another one that I will add to the list I mentioned above and it merits a much more detailed answer than I can give right now.  I will try to get a comprehensive answer together in the next couple of days to a number of these questions.  



Patrick Rainsberry
Developer Advocate, Fusion 360
Message 24 of 81

@prainsberryan FAQ sounds great. Looking forward to it.

Message 25 of 81
kandennti
in reply to: prainsberry

Hi @prainsberry .

 

I wanted to understand the Custom Feature, so I started with a simple one.

 

The desired process is very simple: select a body and a sketch, and place the body at several points on the sketch.
(In CATIA V5, there is a command called UserPattern that does this, and I would like to reproduce it.)

 

Due to lack of understanding, I modified the "Custom Pocket" sample in the documentation to create this.
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-FA7EF128-1DE0-4115-89A3-795551E2DEF2 

 

It's not finished yet, but here's a video to see how it works.

 

The first time the create command is executed, it is placed successfully.
However, when I go to edit, the preview runs correctly, but when I press the OK button to execute, the placed bodies disappears.

When I go to edit again, the preview resumes, but when I click the OK button to execute, the placed bodies still disappears.

 

To find the cause, I logged out the event processing.
(The file I created is attached.)
The output after pressing the OK button in the dialog looks like this.

 

OnExecute begin
OnExecute end

 

 

"Custom Pocket" has also been modified to log output in the same way.
Here is the output after clicking the OK button in the dialog.

 

OnExecute begin
customFeatureCompute begin
customFeatureCompute end
OnExecute end

 

 

The one I created was not triggering the customFeatureCompute event.
But I could not figure out why the trigger was not firing.
It is possible that I am overlooking something simple.

 

I have modified the "Custom Pocket" itself to check the following for differences in processing.
・Changed "CustomFeature.parameters" to have no parameters at all.
 -> The customFeatureCompute event was fired.
・Changed CustomFeature.features to have only one BaseFeature.
 -> The customFeatureCompute event was fired.

 

I also created a similar one using "apper" published by prainsberry, and the same problem occurred.

 

The icons in the attached "UserPattern" are from "Custom Pocket". Please forgive me if I use the same icons as in "Custom Pocket".

Message 26 of 81
nnikbin
in reply to: kandennti

Hi @kandennti 

It seems dependency to the body prevents execution of the compute mothod. Perhaps it is a bug.

 

Just for testing, I removed the dependency to the body and replaced every line of code that needs the body with the first body of the parent component of the sketch. Also I changed  _editedCustomFeature to customFeature in lines 512 and 513. It fires the compute method and changing the sketch or moving the sketch points updates the output.

 

Please see the attached file

 

Even replacing the dependency to the body with dependency to another sketch does not prevent firing the compute method. So it seems the problem is beiing dependent on a body. 

 

I didn't have time to add a dependency to a body to the  Autodesk custom feature samples and test if it prevents them to work correctly.

 

Message 27 of 81
prainsberry
in reply to: prainsberry

Hey @nnikbin @kandennti @florian.pommereningDGUYA @ginavenolia et. al. I wanted to post a followup before the weekend.   so a few of just spent the last couple hours going through a majority of these recent questions in detail.  For good number of them I think it is going to be very hard to give concise answer written up with a few sentences of text.   The bottom line is that using the custom feature API is extremely powerful because it brings you much closer to the actual way in which Fusion 360 really functions itself.  As a result there are many nuances that as a user of parametric CAD you (or I) had never really thought about before probably.  Also for many of these questions posed recently there are a number of potential solution approaches and without getting significantly more details from you it will be hard to recommend the best approach.  

That said what became clear as we were discussing all of this today is that what I think we really need to do is provide some learning content that gives a much deeper dive into the mechanics of the parametric timeline, the compute cycle, reference dependencies and other topics.  This would have made a great AU class 🙂 but I think it is still something that we could put together.  I am thinking that it will likely be in the form of a video "class" that will walk through many of these foundational topics.  I think with that foundation it will be much easier to then answer some of the specifics about when you should or should not trigger a compute, what should or should not be in the preview, the execute or the compute handlers, and such topics.   I think with a better understanding of the fundamentals you will be better equipped to make some of these design decisions.  

Note this is much deeper than the basics of parametric timelines, and references that you would normally consider as even a very strong CAD power user and will really dig much deeper under the hood.  I am so excited for the possibilities here, but at the same time also understand the need for so much learning content to really take advantage of it.  

That said this will be a fairly large undertaking.  I am hoping to be able to really pour some time into it next week, and maybe I can release it in sections.   I really think it will be well worth it though.

Finally regarding all of the questions above there are a couple of them that actually can be answered more quickly and I will address those shortly in additional posts. 

Thank you for bearing with us and I can't tell you how much I appreciate your continued interest in this subject.



Patrick Rainsberry
Developer Advocate, Fusion 360
Message 28 of 81
prainsberry
in reply to: prainsberry

Regarding this question:

First, one task for the Edit Execute handler is update the dependencies on any newly selected entities. Because Custom Pocket example uses a single dependency it can get it (by ID) and then modify its .entity property. Because my add-in can have any number of entities selected, I need to be able to add and remove dependencies to reflect the changes in the number of entities selected. Adding is no problem, but there's no way I can see to remove a dependency if my selection gets smaller. Alternately, I'd be happy to clear the dependencies and add them all back, but alas there's not CustomFeatureDependencies.clear method. So the API only allows you to modify or add dependencies, so what do I do if I need to remove dependencies?

This can be done by calling the deleteMe() method on the actual dependency object.  So:

CustomFeatureDependency.deleteMe() 
To be clear not the thing the dependency references, but the dependency itself. 

 



Patrick Rainsberry
Developer Advocate, Fusion 360
Message 29 of 81
prainsberry
in reply to: prainsberry

Regarding this question:

Third, I can't think of a way of using updateBody to replace the CORRESPONDING bodies. Say the user invokes my add-in, selects entities A and then B, and then clicks OK. Then they edit my feature, clear the selection, and then select entities C and then A. Sure, I could replace A->C and B->A but I'd prefer replacing A->A and B->C. But how can I know which is which? How could I, say, associate an identifier with each body in the base feature, which I could use to find the correspondence with the new bodies?

 

I believe what you are really wanting to do here is to check the equivalency between the inputs.  Then ensure that the body created by the original input A is "updated" to correspond to the body created by "new A" input.

If I assumed that the inputs to your feature were edges for example, you may not know this but the Fusion 360 API supports equivalency checks.
SO if you had something like:
original_selection_A = selection_input.selection(0)

original_selection_B = selection_input.selection(1)

Where the user had selected 2 edges. 

Then later you clear the selections and pick 2 new entities like so:

new_selection_A = selection_input.selection(0)

new_selection_B = selection_input.selection(1)

Now (assuming you still have a reference to the originals) if new_selection_B and original_selection_A are actually the same edge in the model you will see this:

>> new_selection_B == original_selection_A

True

>> new_selection_B == original_selection_B

False

 

So you could do some checking initially with the new input selections against your previous dependencies.



Patrick Rainsberry
Developer Advocate, Fusion 360
Message 30 of 81
prainsberry
in reply to: prainsberry

Regarding the creation of a custom feature parameter with no units this is a bug.  As mentioned in the documentation you should be able to create a unit-less parameter by passing an empty string in the create method.  It has been documented and should be addressed shortly.  THANKS FOR THE CATCH.



Patrick Rainsberry
Developer Advocate, Fusion 360
Message 31 of 81
prainsberry
in reply to: prainsberry

Regarding this question:

"The createInput method used to create a CustomFeatureInput object has three arguments. The first ..."
--> The other two parameters are not discussed, which makes it a difficult to figure out how to set them.
Duplicated "the" in "Define a transaction marker so the the rollback".

 

This is no longer the case.  See updated documentation corresponding to the Fusion release from a couple days ago.  You no longer define the start and end parameter during creation.   This also solves some other problems in that now you can create your definition, add parameters and dependencies, do your creation, then add the individual resultant features to the custom feature. 

This will also solve this question if you reference the edge as a dependency before creating the features that consume it.  Again this is something that may make more sense with our yet to be created learning material.

 

 

I got some errors when adding an edge as a dependency. The error is not reproducible every time and I'm not sure what exactly caused it but it happened in the context of a preview execute of the feature (when changing options in the feature creation dialog). The call stack to the error ended in

    _fusion.CustomFeatureInput_addDependency(self, id, entity)
    RuntimeError 2: InternalValidationError: edge

 

 

 



Patrick Rainsberry
Developer Advocate, Fusion 360
Message 32 of 81
prainsberry
in reply to: prainsberry

I believe the last post should also provide the solution to this question:

 

When target is a body, this works as expected but if target is a component, the feature belongs to the target (not parentComponent) afterwards. That is, after the last line parentComponent.features.combineFeatures is still empty. This makes it then impossible to combine this feature with other features into a custom feature. The operation that crashes is parentComponent.features.customFeatures.createInput(). I didn't find a solution for this 



Patrick Rainsberry
Developer Advocate, Fusion 360
Message 33 of 81
prainsberry
in reply to: prainsberry

I know this is a ton of posts, but here is another little tip from one of the developers regarding the new method to create an empty definition to begin with:

 

This change can allow the creation order to be flipped around, which would be more natural in this case. You can now create a CustomFeature without specifying the start/end features. This will create an 'empty' custom feature along with the parameters. You can now add dependencies to to this feature, and use the names of the created parameters in expressions for any of the child features created afterwards. After creating all the child features, you can set the start/end feature.

One tip with this workflow: Add a flag in your code to 'ignore computes' so that your compute event handler can ignore the compute events for changes made to the custom feature during creation (like adding dependencies, or setting the child features, or the initial 'empty feature' compute). This is also useful to avoid compute events triggered by messing around with the custom feature during edit commands. (Basically, just ignore computes during create or edit. You should only need compute to react to input parameter and dependency changes.)



Patrick Rainsberry
Developer Advocate, Fusion 360
Message 34 of 81
kandennti
in reply to: nnikbin

Thank you, @nnikbin.

I appreciate it very much.

 

I did confirm that the customFeatureCompute event is being triggered in the fixed one.

 

I feel sure that the body dependency is the cause.
However, in the FusionBoxer published by @prainsberry, the on_compute method is executed using the BRepbody dependency.

 https://github.com/tapnair/FusionBoxer/blob/master/commands/OffsetBoundingBoxCommand.py#L440 

1.png

 

I feel like something is missing to fire the customFeatureCompute event...

Message 35 of 81
nnikbin
in reply to: kandennti

@kandennti 

Asumming that we have opened the attached file which contains a body named TestBody and a sketch named TestSketch, I changed CustomPocket.py and just added a dependency to the TestBody to it (adding the following code after line 223, without using the dependent body in program). It prevented firing of compute.

 

testBody: adsk.fusion.BRepBody = skPoint.parentSketch.parentComponent.bRepBodies.itemByName('TestBody')
custFeatInput.addDependency('body', testBody)

 

But adding a dependency to the TestSketch (adding the following code after line 223), did not prevent firing of compte.

 

testSketch: adsk.fusion.Sketch = skPoint.parentSketch.parentComponent.sketches.itemByName('TestSketch') custFeatInput.addDependency('sketch', testSketch)

 

As @prainsberry mentioned in one of his recent posts, it seems there are many nuances that we are unaware of. I look forward to Patrick's learning cotent.

Message 36 of 81
nnikbin
in reply to: nnikbin

Also adding a dependency to the first face of the TestBody (in my previous post) does not prevent firing of compute method.

 

testFace: adsk.fusion.BRepFace = skPoint.parentSketch.parentComponent.bRepBodies.itemByName('TestBody').faces.item(0)
custFeatInput.addDependency('face', testFace)

 

Message 37 of 81
kandennti
in reply to: nnikbin

@nnikbin Thank you for trying everything.

I couldn't try anything last weekend because I had a bad headache from the adverse reaction to the covid-19 vaccine.

 

Indeed, Sketch and BRepface are fine, but I found out that making BRepBody a dependency (even if it is irrelevant in processing) is the cause.
If I can figure out the cause, I might be able to come up with a way to work around it.

 

 

@prainsberry.

I don't know how much I can understand, but I'm looking forward to the AU class.

Message 38 of 81

I ran into two problems with the custom pocket demo (post 1, post 2). I'm not sure how if this is relevant to the design of custom features but maybe it is. In both cases one possible solution would be to create the tool body in the root component rather than in the active component but then the features bundled up in the custom feature would come from different timelines. Is that a problem?

Message 39 of 81
nnikbin
in reply to: prainsberry

Hi @prainsberry,

Is there any news about Custom Feature API?

Message 40 of 81
mcd8604
in reply to: ginavenolia

@ginavenolia 

I'm not sure if this will help, but have you tried working with Attributes yet?

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-BAF017FE-10B8-4612-BDE2-0EF5D4C6F800

If that link doesn't work, the page is under: Programming Interface / Fusion 360 API User's Manual / Attributes

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