API navigation

API navigation

oyvindTMNSU
Advocate Advocate
787 Views
5 Replies
Message 1 of 6

API navigation

oyvindTMNSU
Advocate
Advocate

 

 

What is actually the difference of grabbing the extrude feature by navigating for it through self assigned variables. And by using the "direct path" suggested in code hint.


app = adsk.core.Application.get() 
ui = app.userInterface
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType) product = app.activeProduct design = adsk.fusion.Design.cast(product) 
rootComp = design.rootComponent 

Difference between this:
extrudes = rootComp.features.extrudeFeatures

And this:

extrudes = adsk.fusion.extrudeFeatures

 

 

@BrianEkins  you use to have very good answers:) hope you understand the question

0 Likes
788 Views
5 Replies
Replies (5)
Message 2 of 6

BrianEkins
Mentor
Mentor

You need to use this.  It is assuming you have a reference to the root component in a variable named "rootComp". From the root component it called the features property, which returns a Features object.  It then calls the extrudeFeatures property on the returned Features object which returns an ExtrudeFeatures object.  The ExtrudeFeatures object provides access to all of the extrude features in that component and it also provides the functionality to create new extrude features.

extrudes = rootComp.features.extrudeFeatures

 

The other line you had is invalid.  However, if you capitalize the "e" in extrude features to get the line below it is valid Python but doesn't do anything useful.  The "adsk.fusion" portion is specifying a specific library that's delivered with Fusion and ExtrudeFeatures is one of the types defined in that library.  This line ends up with a variable containing the type definition but not an object that you can use in any way.

extrudes = adsk.fusion.ExtrudeFeatures

 

Where did you see an example of the second sample?

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 6

oyvindTMNSU
Advocate
Advocate

Ok. The second example is whats automatically comes up in visual studios if you start to type extrudes = ExtrudeFeatures (then a list of suggestions shows up, and if I click "ExtrudeFeatures" with an orange icon on the left of the text. The option replace "ExtrudeFeatures" with adsk.fusion.ExtrudeFeatures) same as I would use if I should cast ExtrudeFeatures.

0 Likes
Message 4 of 6

BrianEkins
Mentor
Mentor

What VS Code is doing isn't wrong but it's not what you want in this case.

 

When you type "extrudes = " and start typing it's providing a list of all of the known types.  All it knows is that you're assigning something to a variable.  It doesn't know what type that variable is so it shows all the types it currently knows about.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 5 of 6

oyvindTMNSU
Advocate
Advocate

I have attached a gif to show. 

So when is it right to use this kind of path that vs code suggest in the gif?

 

0 Likes
Message 6 of 6

BrianEkins
Mentor
Mentor

For me, code hints are primarily useful in two cases.

 

First, is when I know what I want and if it shows up in the list of code hints I can select it and save some time typing.

 

The second, and most useful, is when I have a known object type and it's showing me the methods and properties that object supports.  In this case, I think I know what I want but I may not be sure what the exact name is or I need a reminding of what's available.  Having a list to look through shows me what is supported and also saves me time typing.

 

An example is this. When I type the "." after "app" VS Code will show me all of the methods and properties that the Application object supports.  I can start to type userInterface and it will start to filter the list and I can choose it and insert it into my code.

 

app: adsk.core.Application = adsk.core.Application.get()
ui = app.

  

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes