Custom Feature API Preview - Feedback Thread

Custom Feature API Preview - Feedback Thread

prainsberry
Autodesk Autodesk
14,686 Views
81 Replies
Message 1 of 82

Custom Feature API Preview - Feedback Thread

prainsberry
Autodesk
Autodesk

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
14,687 Views
81 Replies
Replies (81)
Message 41 of 82

rolandas_vegis
Advocate
Advocate

Hello,

 

I started trying the custom feature API and run into some issues with grouping.

 

I have a command which extrudes and creates a new occurrence and grounds it.

The features then look like so:

rolandasvegis_0-1639999979272.png

 

The issue is when I try to group them I can only pass the extrude feature and it leaves the other 2  timeline objects out. So I tried getting the objects directly from timeline and however got the error: Not a valid feature type.

 

Quote from documentation: "A "feature" in this case is an object that is visible in the timeline". I can't use a TimelineObject nor can I use TimelineObject->entity() (which in my case returns an Occurrence object).

 

So my question would be how do I group these features which are creation of new occurence and grounding?

0 Likes
Message 42 of 82

tykapl.breuil
Advocate
Advocate

You can put each of these call into a base feature (you'll lose the icon in the timeline however)

Message 43 of 82

kandennti
Mentor
Mentor

Hi @rolandas_vegis .

 

I didn't know what the third command was, but I don't think you can put "New occurrence" in a group.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-DD80F08D-C24E-4B38-A344-4F7D680B5D43 

1.png

 

Even FusionBoxer, published by @prainsberry , does not include the "New occurrence" in the group.

1.png

https://github.com/tapnair/FusionBoxer 

 

Message 44 of 82

tykapl.breuil
Advocate
Advocate

You are right, I misremembered what my code does. What works is creating an empty basefeature before creating the occurence and the new occurence timeline icon gets put into the custom feature.

0 Likes
Message 45 of 82

rolandas_vegis
Advocate
Advocate

Yes creating an empty base feature works, but it is a workaround. In my opinion API should support grouping of all types of timeline objects.

Message 46 of 82

rolandas_vegis
Advocate
Advocate

The capability to use User Parameters would be nice. While having custom parameters associated with a feature is a step in the right direction, User Parameters should be the next step. That way it would be possible to use a single parameter in multiple features in a model and updating it only once instead of going through every feature separately and changing it.

 

AFAIK this is not currently possible, because we have no way of knowing when a User parameter was used, we just get the value of it on input changed event. Now that we have recompute event that is the only part that is missing to achieve this.

0 Likes
Message 47 of 82

rolandas_vegis
Advocate
Advocate

I have run into a possible bug with custom feature parameters when changing the extrude value.

 

Recompute event code:

 

		const auto feature = eventArgs->customFeature();
		auto value = feature->parameters()->item(0)->value();

		const auto valueInput = ValueInput::createByReal(value);
		Ptr<ExtrudeFeature> extrude = feature->features().at(0);
		const auto extent = extrude->extentOne();
		if (Ptr<DistanceExtentDefinition> disDef = extent->cast<DistanceExtentDefinition>())
		{
			const auto distanceParam = disDef->distance();
			distanceParam->value(value);

			Application::get()->userInterface()->messageBox(std::to_string(value));
		}

 

 

 

Screencast showing the problem:

https://autode.sk/3yKYsQt

 

As you can see when changing the parameter first time, no change is made to model. When changing it for 2nd time the value from first change is applied. When changing it for the 3rd time the value from 2nd change is applied. Even though you can see the message box displaying correct values from the recompute event.

0 Likes
Message 48 of 82

I am still stuck on the two problems I mentioned with the custom pockets demo (post 1, post 2). In one case, the creation of the pocket fails, in the other, the pocket is at the wrong place. @prainsberry could you have a look?

0 Likes
Message 49 of 82

pludikar
Collaborator
Collaborator

Hi,

I've been on hiatus for the last 18 months, and I'm slowly getting back.  🙂

 

I'm not sure if it's me but is the custom pocket example working?  I get a 

"RuntimeError: 5 : Combine1(Custom Pocket1) / Tool Body Error // 1 Reference Failures The tool body is lost, try editing this feature to reselect tool body."

 

ExecutePreviewHandler does what it's supposed to, but CreateExecuteHandler doesn't.  If I add the following around line 202

 

 

            combineInput.isKeepToolBodies = True

 

and comment out (around line 224)

 

            # custFeatInput.setStartAndEndFeatures(baseFeat, combineFeature)

 

 

Then I get the tool bodies, and the feature.  If I make .isKeepToolBodies = False then it fails.

 

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 50 of 82

pludikar
Collaborator
Collaborator

Further to my last post:

it appears that, for some unknown reason, after CreateExecuteHandler is fired, the CreatePocketBody function gets fired twice in succession. The second time it fails because the original body has already incorporated the custom feature.

 

I initially suspected that it might have been F360's interaction with VSCode, so I tried restarting F360, and simply running the addin (ie not stepping through with the debugger).  I also installed a fresh copy of the Addin, just in case I had done anything inadvertently with the code in the debugger.  Same issue!

 

Before reinstalling the addin - I added logger statements to each function.  This is what I got:

 

2022-02-04 19:56:35,642; CustomPocket; DEBUG; 52; run ; Running
2022-02-04 19:56:39,745; CustomPocket; DEBUG; 131; notify ; Creating Pocket Command
2022-02-04 19:56:41,519; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,520; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,529; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,530; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,543; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,544; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,598; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,599; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,732; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,733; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,778; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,779; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,927; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,928; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,935; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,936; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,982; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:41,982; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:42,475; CustomPocket; DEBUG; 466; notify ; PreSelect
2022-02-04 19:56:42,477; CustomPocket; DEBUG; 190; notify ; ValidateInputsHandler
2022-02-04 19:56:42,477; CustomPocket; DEBUG; 423; notify ; Execute Preview
2022-02-04 19:56:42,478; CustomPocket; DEBUG; 535; CreatePocketBody ; Creating pocketBody
2022-02-04 19:56:42,565; CustomPocket; DEBUG; 190; notify ; ValidateInputsHandler
2022-02-04 19:56:42,576; CustomPocket; DEBUG; 190; notify ; ValidateInputsHandler
2022-02-04 19:56:44,730; CustomPocket; DEBUG; 190; notify ; ValidateInputsHandler
2022-02-04 19:56:44,736; CustomPocket; DEBUG; 190; notify ; ValidateInputsHandler
2022-02-04 19:56:44,752; CustomPocket; DEBUG; 190; notify ; ValidateInputsHandler
2022-02-04 19:56:44,757; CustomPocket; DEBUG; 215; notify ; CreateExecuteHandler
2022-02-04 19:56:44,757; CustomPocket; DEBUG; 535; CreatePocketBody ; Creating pocketBody
2022-02-04 19:56:44,794; CustomPocket; DEBUG; 492; notify ; ComputeCustomFeature
2022-02-04 19:56:44,794; CustomPocket; DEBUG; 535; CreatePocketBody ; Creating pocketBody
2022-02-04 19:56:44,820; CustomPocket; ERROR; 266; notify ; Exception
Traceback (most recent call last):
  File ".../AppData/Roaming/Autodesk/Autodesk Fusion 360/API/AddIns/customPocket/CustomPocket.py", line 264, in notify
    comp.features.customFeatures.add(custFeatInput)
  File ".../AppData/Local/Autodesk/webdeploy/production/a92224e805924f40fe2f5cb1ea196540cf83211e/Api/Python/packages\adsk\fusion.py", line 14412, in add
    return _fusion.CustomFeatures_add(self, input)
RuntimeError: 5 : Combine1(Custom Pocket1) / Tool Body Error // 1 Reference Failures The tool body is lost, try editing this feature to reselect tool body. /// TOOL_BODY_REFERENCE_LOST - Body 1 missing / Compute Failed // ALL_TOOL_BODY_REFERENCE_LOST - All tool bodies are lost, try editing this feature to reselect tool bodies.
2022-02-04 19:57:08,303; CustomPocket; DEBUG; 98; stop ; Stopping

 

Based on this, it looks like either the customFeature team have introduced a bug, or an update of F360 has resulted in breaking something.  I hope this helps.

 

Regards

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 51 of 82

pludikar
Collaborator
Collaborator

@prainsberry @kandennti 

 

Could someone confirm if the issue I'm seeing can be reproduced somewhere other than my computer?  If it's just happening on my computer I would really like to know.

 

I've shutdown and restarted my computer as well as restarting F360 from fresh - same problem!  I've not reinstalled F360 yet.

 

I put a flag into the script in an attempt to prevent CreatePocketBody function from being executed twice - interesting with my modification, the first time I try to make the custom feature, it fails, but subsequent times it doesn't. 

 

I also noticed (using APIDebug.eventHandlers text command) that the number of event handlers increases by 4 each time the custom feature button is executed - this feels like the handlers are not being released after they've been used.

 

To save anyone having to put the logging statements in - I've attached the zipped customPocket.py file.

 

Regards

Peter

 

 

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 52 of 82

kandennti
Mentor
Mentor

Hi @pludikar .

 

I tried it, but it was in the same state.

Round Emboss does not seem to be working as a Custom Feature either.

 

FusionBoxer published by @prainsberry  works as Custom Features, so there may be some hints there.

https://github.com/tapnair/FusionBoxer 

0 Likes
Message 53 of 82

pludikar
Collaborator
Collaborator

@kandennti 

 

I very much appreciate you responding - I was starting to get worried that there was something in my setup that wasn't working.

 

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 54 of 82

pludikar
Collaborator
Collaborator

@prainsberry 

 

So the issue in the Custom Pocket example (here) is: 

adding to customFeatures during  the CreateExecuteHandler causes the ComputeCustomFeature eventHandler to trigger (line 224).

 

That means during in CreateExecuteHandler , you not only create the feature the first time, which is needed to populate the  custFeatInput.setStartAndEndFeatures(baseFeat, combineFeature) - (line , but when you add the feature, ComputeCustomFeature attempts to add the feature again - and fails, because it's already there!

 

I was able to prove this by adding a global variable which bypasses the ComputeCustomFeature during the CreateExecute event.

global _enableHandler
...
#around line 224
_enableHandler = False
comp.features.customFeatures.add(custFeatInput)
_enableHandler = True

 

and in the CustomComputeFeature notify method - 

def notify(self, args) # - line 439
global _enableHandler
if not _enableHandler
    return

  

This fixes the example code - but it's a work around!!  and... I consider this to be a bug!!

 

The code behind comp.features.customFeatures.add(custFeatInput) - line 224 should be fixed to automatically prevent the ComputeCustomFeature event from being fired.

 

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 55 of 82

pludikar
Collaborator
Collaborator

@prainsberry 

I appreciate that this customFeature thread was started over a year ago, but as it's still pinned on the forum I assumed that it was still alive, and AD is still looking for feedback and any issues.  I've posted a few time now, and it feels like I'm sending posts into a black hole.  Hopefully I'm wrong.

 

Any way - assuming that someone eventually gets to read this.  I've found that using a BrepBody as a customFeature dependency entity doesn't appear to trigger the customFeatureCompute event.  Changing the body to respective edges kicks the compute event into life! 

 

There may be a logical reason AD missed this, but I see this as one of the most critical entities.  If I have a cuboid body with say, 12 edge features, at the moment I would have to make sure that all 12 edges are registered as dependencies, as well as, potentially, all faces that touch those edges.  That seems a bit excessive, particularly when registering the body, that's parent to the edges, would do exactly the same trick.  Monitoring changes to the body.revisionId would ensure that any change in face or edge would trigger the compute event.

 

I dare say that there are also cases when you do want to trigger from specific edges, or faces - but that's already accounted for.

 

Peter 

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 56 of 82

ginavenolia
Contributor
Contributor

I have noticed that my add-in behaves differently in recent versions of Fusion. Originally each time my add-in was recomputed, the name of the body it produced would remain constant, and operations done to that body would recompute in turn. As of a week or two ago, some change to Fusion causes the name of the body to change ("Body 2" to "Body 3" to "Body 4", etc., or if renamed, "My Body" to "My Body (1)" to "My Body (1) (1)", etc.).  Any subsequent operations on the body fail to recompute since they can't find the body, which is especially annoying.

 

Here's a screencast that illustrates the current behavior. For simplicity's sake I'm using the Custom Pocket example code, modified to create a body instead of cutting it, by commenting out lines 196-201 and 400-404. As you can see, each time I edit the sketch (by moving the circle), the pocket body is given a new name because it's being recomputed.

 

Is this a bug introduced in a recent version of Fusion? Is there something I can do in my code to get back to the old behavior?

0 Likes
Message 57 of 82

pludikar
Collaborator
Collaborator

@prainsberry @BrianEkins

 

Hi Brian,

Do you have any insight into what's happening on customFeatures?  I've posted several times over the last week or two and it's like my posts go into a black hole - not even a glimmer of a reaction from anyone.

 

It appears that customFeatures have been broken by some relatively recent F360 update. 

 

I was trying to get an edge dependency working, but all the code variants I've tried, all come back with an "InternalValidationError".  In principle, it's obvious - if you use an edge as a basis for a feature that changes the edge, then the edge stops being a valid entity, because it's just been replaced - normal expected F360 behaviour.

 

However, in this case (customFeatures) - the edge you use should be related to the edge before the transaction, and not the current edge.  Is there something I've missed?  or is this a quirk of the latest F360/customFeature manifestation?

 

I've attached a copy of the customPocket example AddIn - modified to use an edge dependency.  If you have time, could you confirm that my changes are legitimate/or not as the case may be.  I've been going around in circles for the last few days, and so I'd appreciate knowing if it's me or the customFeature.

 

Regards

Peter 

 

 

 

 

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 58 of 82

pludikar
Collaborator
Collaborator

Hi @ginavenolia

 

I suspect that customFeature is very broken, and hopefully someone from AD will acknowledge that soon.  There are big warning notices everywhere customFeatures are mentioned in the API user and reference manuals, which highlight the possible fragility of these API objects.  I think that’s what we’re currently experiencing.

 

Having been through numerous updates to F360 in the past, I wouldn’t expect any ability to roll back to earlier versions of the API.  Unfortunately, I think you’ll just have to hold your breath until the API team come up with a working update.

 

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
Message 59 of 82

ginavenolia
Contributor
Contributor

Hey @pludikar

 

I've been watching your posts about your frustrations. This feature seems to be suffering from a bit of neglect. I'm hoping that the AD team gets back to making it awesome!

 

-Gina

0 Likes
Message 60 of 82

pludikar
Collaborator
Collaborator

Hi Gina

 

Nice to know that at least one person has seen my posts.  I obviously failed - I was trying not to let my frustrations show too much 🙂 

 

Unfortunately, I think it's very unprofessional of AD not to react at all to any of my posts - I hope this isn't a reflection on their underlying product, which, I agree, is normally awesome.  A simple "Yeah, we hear you" would be sufficient.

 

It's also a bit incongruous of AD to prominently pin this thread asking for feedback, and then do nothing when it comes.

 

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).