Access Section Analysis?

thomasa88
Advocate

Access Section Analysis?

thomasa88
Advocate
Advocate

Is there any way in the API to access sections created by the Section Analysis tool?

0 Likes
Reply
1,679 Views
16 Replies
Replies (16)

BrianEkins
Mentor
Mentor

The Section Analysis command functionality has not been exposed through the API.  However, depending on what you need, you might still be able to accomplish it using the API.  The "Section Analysis" command doesn't seem to provide any analysis but instead shows a graphics representation of the model cut along a specified plane.  If you want to control the display of existing sections, that's not available.  However, you can get some true section analysis using a combination of some API functionality.

  1. First, you can use the planeIntersection method to calculate the intersection between a defined plane and a body.  This creates a wire body which is a wire frame representation of the intersection.
  2. You can use the createFaceFromPlanarWires method to create a BRepFace object that represents the intersection.
  3. Finally, you can use the areaProperties method to calculate the area properties of the face.  This will return things like the area, perimeter, principal axes, moments of inertia, etc.

Here's an example script that demonstrates this.  It displays the area but you can get all of the other area properties from the returned AreaProperties object.

import adsk.core, adsk.fusion, traceback

def run(context):
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent

        constPlaneSel = ui.selectEntity('Select a construction plane', 'ConstructionPlanes')
        constPlane = adsk.fusion.ConstructionPlane.cast(constPlaneSel.entity)

        bodySel = ui.selectEntity('Select body to section', 'Bodies')
        body = adsk.fusion.BRepBody.cast(bodySel.entity)

        tempBRep = adsk.fusion.TemporaryBRepManager.get()
        intWireBody = tempBRep.planeIntersection(body, constPlane.geometry)        

        intBody = tempBRep.createFaceFromPlanarWires([intWireBody])

        inputs = adsk.core.ObjectCollection.create()
        inputs.add(intBody.faces.item(0))

        areaProps = des.areaProperties(inputs)

        baseFeat = root.features.baseFeatures.add()
        baseFeat.startEdit()
        newBody = root.bRepBodies.add(intBody, baseFeat)
        newBody.name = 'Intersection'
        baseFeat.finishEdit()

        ui.messageBox('Area: ' + str(areaProps.area) + ' cm^2')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) 

 

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

thomasa88
Advocate
Advocate

Thank you for putting time and effort into this. I should have been more clear about exactly what I want to do.

 

I'm writing an add-in for naming things directly after creation. I got annoyed about all my unnamed section views, so I wanted to include them in the add-in. So I basically wanted to access the "name" property of the section views in the browser.

0 Likes

kandennti
Mentor
Mentor

Hi @thomasa88 .

 

I've tried a few things with the TextCommands(Txt).

Browser.DumpXml <export file path>

https://github.com/kantoku-code/Fusion360_Small_Tools_for_Developers/blob/master/TextCommands/TextCo...

 

If you examine the exported xml file file, it appears to contain the name of the Section Analysis.

 

You can find out how to run TextCommands from the API here.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/use-textcommands/td-p/9645688

 

0 Likes

thomasa88
Advocate
Advocate

@kandenntiVery interesting with the text commands! However, in this case, I'm not sure that it helps.

I see the commands for creating Section Analysis, but I don't know if it helps me.. I want to rename existing sections.

 

Toolkit.browser lists "Analysis", but I don't know if I can go from there.

FusionDoc.FusionDocShowHideCmd indicates that browser nodes can be accessed.

FusionDoc.SetObjectName sounds right, but the help text says it is for selecting

NamedView.UpdateNamedViewName  is for named views.

 

These sound promising:

NuCommands.RenameCommand

PInterfaces.Rename

 

Any idea how I can supply the right arguments?

 

Btw, I get the feeling that the Text Commands are for some sort of automated testing of Fusion.

1 Like

thomasa88
Advocate
Advocate

Ok, I'm almost there:

 

* Toolkit.browser: Flat browser view. Does not update contents after renaming a section (via GUI or RenameCommand). Here I can see e.g. Section3.
* ????
* Selections.Add 826 Here I add my section's entity ID to selections
* NuCommands.RenameCommand MySection Rename it to "MySection"


I need to figure out how to get from section name to entity ID. Or possibly some kind of name path (Analysis:Section3) to entity ID.


PSelections.Get gave me the ID when I selected manually, but I need to do it programmatically.

 

PSelections.Get
[{"occurrence":{"source":{"segId":24,"entityId":3,"rootId":""},"path":[]},"entity":{"segId":24,"entityId":826,"rootId":""},"type":"Na::VisualAnalysisSelection"}]

 

1 Like

kandennti
Mentor
Mentor

Understand that the use of TextCommands is different from "getting to the goal" with "possible" alone.

0 Likes

kandennti
Mentor
Mentor

I haven't tried it in detail, but "FusionDoc" is about drawings,
I think "PInterfaces(P~)" is related to PCB(Electronic).

0 Likes

thomasa88
Advocate
Advocate

After a long evening with Fusion Text Commands, I think I got it!

Now the question remains: Is it stable? Both in regards to API changes and to program stability.

 

PAsset.RootIds 
["AssetSettings","ComponentInstancesRoot","ComponentsRoot","NamedTrackedEntitySet","ProteinAssetManager","UnitSystems","VisualAnalyses","WorkingModelPlaceholderRoot","rootInstance"]

PEntity.ID VisualAnalyses
59

Managed.Children VisualAnalyses
1

Managed.Child VisualAnalyses 0
{"segId":3,"entityId":179,"rootId":""}

PEntity.Properties 179
userName contains name. But see below.  userName is empty here if the user has never set it?
creationIndex shows the index for entities of this type? Is this the number after e.g. Section ---> "Section<num>"

PInterfaces.GetUserName 179
Section1

PInterfaces.Rename 179 "My section!"

 

And it's even possible to call the Python versions directly from add-ins!

Python functions. import the modules. Can find functions by comparing help info to text command help info.
import neu_dev
neu_dev.list_functions()

import neu_server
import neu_modeling
neu_server.get_entity_id("VisualAnalyses")

neu_modeling.get_child_count(59) 
4

neu_modeling.get_child(59, 0)
{'segId': 8, 'entityId': 826, 'rootId': ''}

neu_modeling.get_child(59, 0)['entityId']
826

neu_server.get_entity_properties(826)
neu_server.get_entity_properties(826)['userName'] #userName is empty here if the user has never set it?
neu_server.get_entity_properties(826)['creationIndex'] # e.g. 3 in Section3
3

neu_server.get_user_name(826)
sekt3


neu_server.rename(826, "section name")
1 Like

kandennti
Mentor
Mentor

It's great!

 

I don't think there are any guarantees on stability.
Basically, it's not a recommended technique for an API, and I feel it's more of a subterfuge.

 

"neu_dev", "neu_server" and "neu_modeling" I didn't notice that either.
Thanks for the good information.

1 Like

BrianEkins
Mentor
Mentor

@kandennti is correct. None of that functionality is officially supported.  It was typically added for some internal testing and there's nothing to guarantee the functionality won't change or be available at all in the future.  For an internal tool it's probably OK, but I would be hesitant to use these kinds of workarounds for anything I'm delivering to others.

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

amandaghassaeiS8KA2
Participant
Participant

@BrianEkins thanks for the info - I looked and it seems that turning section analysis visibility on/off is still not supported through the API.  I'm working on a script to render past versions of a design as a timelapse animation and it would help to be able to turn section analysis off before saving an image:

https://github.com/amandaghassaei/Fusion360-Design-Version-Timelapse

any plans to implement this?

Thanks,

Amanda

0 Likes

thomasa88
Advocate
Advocate

I looked through my earlier examples and checked the list from neu_dev.list_functions().

 

This seems to work pretty well (for now at least):

 

 

 

import neu_server 
import neu_modeling 
analyses = neu_server.get_entity_id("VisualAnalyses") 
for i in range(neu_modeling.get_child_count(analyses)):
    analysis = neu_modeling.get_child(analyses, i) 
    neu_server.set_entity_properties(analysis, {'isVisible': False} )

    # Dump all properties: neu_server.get_entity_properties(analysis)

 

 

edit. And cool idea!

 

And also most objects that have .items() seem to be directly iterable (i.e.  for item in object: do thing)

1 Like

amandaghassaeiS8KA2
Participant
Participant

Thanks for the code @thomasa88 !  I will give that a try.  So as I understand it the neu_ stuff is deprecated, but are there any docs still available for this?

0 Likes

kandennti
Mentor
Mentor
0 Likes

thomasa88
Advocate
Advocate

@amandaghassaeiS8KA2

I'm not sure that this interface has ever been supported and I have not seen any official documentation. Which is a bit funny, with how easily accessible it is. When I first started using fusion I thought it was a command interface to easily drive the program instead of using the mouse, as in, I believe, Autocad.

 

I have just used the info from kandetti in this post, and a lot of trial and error..:

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/access-section-analysis/m-p/9697019/highli...

@kandenntiThanks! 🙂

1 Like

amandaghassaeiS8KA2
Participant
Participant

In case anyone is still looking at this thread.  Took me a while, but I finally tried turning off the visibility of each section analysis with @thomasa88 's code, but found that it had no effect.  Instead, I found that I had to turn off the visibility of all analyses in addition to each individual analysis.  Doing this with just one or the other had no effect.

 

the code:

 

import neu_server 
import neu_modeling 
analyses = neu_server.get_entity_id("VisualAnalyses")
neu_server.set_entity_properties(analyses, {'isVisible': False} ) # turn off all analyses
for i in range(neu_modeling.get_child_count(analyses)):
    analysis = neu_modeling.get_child(analyses, i) 
    neu_server.set_entity_properties(analysis, {'isVisible': False})

 

maybe there is a draw or update call that gets triggered when the second round of visibility changes happens?

 

thanks again @thomasa88 for all the help!!  Code is working great now!

1 Like