Floating labels, fixed to window coordinates

Floating labels, fixed to window coordinates

thomasa88
Advocate Advocate
882 Views
8 Replies
Message 1 of 9

Floating labels, fixed to window coordinates

thomasa88
Advocate
Advocate

I want to put some text labels on top of the 3d workspace area in Fusion. The labels should be at fixed 2D coordinates relative to the window. Think something like the labels on the Browser. Is this possible?

 

I have not digged that far into CustomGraphics, but they seem to be saved to the document, which I don't want. My labels are more of status labels.

 

0 Likes
883 Views
8 Replies
Replies (8)
Message 2 of 9

BrianEkins
Mentor
Mentor

What you want to do is possible and is all covered in the Custom Graphics overview topic in the help.

 

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-ED78D886-0B51-4FCA-98FA-A549EDEF7C04

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

thomasa88
Advocate
Advocate

Nice!

 

Then, one more question: How do I control whether the graphics is saved in the document?

 

I had something like this when I did some tests, and the lines got saved in the document and I had to delete the programmatically.

 

 

 

        design: adsk.fusion.Design = app_.activeProduct
        graphics_ = design.rootComponent.customGraphicsGroups.add()
        graphics_.isSelectable = False
        draw_line(camera.eye, camera.target, Colors.ORANGE.value)


def draw_line(from_point, to_point, color):
    coord_array = [*from_point,
                   *to_point]
    coords = adsk.fusion.CustomGraphicsCoordinates.create(coord_array)
    indices = [0, 1]
    lines = graphics_.addLines(coords, indices, False)
    lines.weight = 1.5
    lines.color = adsk.fusion.CustomGraphicsShowThroughColorEffect.create(color, 0.4)
    return lines

 

 

 

Edit: I guess adding the graphics to the rootComponent makes them get saved.

Edit2: And it seems that CustomGraphicsGroups is only referenced by Component?

0 Likes
Message 4 of 9

BrianEkins
Mentor
Mentor

Custom graphics are never saved.  They exist only while the document remains open.  If you close the document and reopen it the graphics will be gone.

 

As far as where graphics can be created, you are correct that graphics can only be created on a component.  It does not have to be the root component.

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

thomasa88
Advocate
Advocate

Thanks, it must have been a short-circuit in my brain. Graphics never disappeared when I reloaded my add-in (since I did not delete them), but as you say, they are not saved to the document.

 

 

I have played around a bit with CustomGraphics and it seems usable for my labels. However, I have some problem with text. I can billboard the text just fine, but I'm having trouble placing it. It seems that the text does not respect my transformation matrix.

 

In the sample below, I'm putting the text relative to the lower left corner. I'm trying to move "Some text" using a transformation matrix, but it stays fixed in place (or, for high numbers, disappears completely). Drawing meshes at custom points seems to work fine.

 

I just noticed that if I hover over the text, the blue hover text actually changes position when I change my matrix (I'm changing the x origin value), as can be seen in the image (my cursor was not captured).

 

Any ideas?

 

#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    _ui = None
    try:
        _app = adsk.core.Application.get()
        _ui  = _app.userInterface        
        doc = _app.activeDocument
        prods = doc.products
        _des = prods.itemByProductType('DesignProductType')
        if not _des:
            raise Exception('Failed to get fusion design.')

        _cgGroups = _des.rootComponent.customGraphicsGroups

        if _cgGroups.count > 0:
            _cgGroups.item(0).deleteMe()

        cgGroup = adsk.fusion.CustomGraphicsGroup.cast(_cgGroups.add())

        viewPt = adsk.core.Point2D.create(200,200)

        corner = adsk.fusion.ViewCorners.lowerLeftViewCorner
        attr = adsk.fusion.CustomGraphicsViewPlacement.create(adsk.core.Point3D.create(), corner, viewPt)
        cgGroup.viewPlacement = attr

        attr = adsk.fusion.CustomGraphicsViewScale.create(1, adsk.core.Point3D.create())
        cgGroup.viewScale = attr

        bbStyle = adsk.fusion.CustomGraphicsBillBoardStyles.ScreenBillBoardStyle
        attr = adsk.fusion.CustomGraphicsBillBoard.create(adsk.core.Point3D.create())
        # #attr.axis = adsk.core.Vector3D.create(0,1,0)
        attr.billBoardStyle = bbStyle
        cgGroup.billBoarding = attr

        cgText = cgGroup.addText("Some text", 'Arial', 20, adsk.core.Matrix3D.create())


        matrix = adsk.core.Matrix3D.create()
        matrix.setWithCoordinateSystem(adsk.core.Point3D.create(100, 0, 0),
                                       adsk.core.Vector3D.create(1, 0, 0),
                                       adsk.core.Vector3D.create(0, 1, 0),
                                       adsk.core.Vector3D.create(0, 0, 1))
        cgText = cgGroup.addText("Other text", 'Arial', 20, matrix)

    except:
        if _ui:
           _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

thomasa88_0-1631163386064.png

 

 

0 Likes
Message 6 of 9

thomasa88
Advocate
Advocate

New idea: Transforms do not work with ViewPlacement.

0 Likes
Message 7 of 9

thomasa88
Advocate
Advocate

edit: ScreenBillBoardStyle is the problem. Without it applied to the group, I can apply a rotation transformation matrix on my text. With ScreenBillBoardStyle, the transformation is not applied.

0 Likes
Message 8 of 9

BrianEkins
Mentor
Mentor

I'm able to reproduce the problem and it seems to be a bug with the API.  I was also unable to find any workaround.  A bug has been reported.  Thank you for the simple sample to easily see the problem.

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

thomasa88
Advocate
Advocate

I seem to have a similar problem with addPointSet. No matter what coordinates I insert (CustomGraphicsCoordinates = [ x, y, z ]  (only one point)), the point always remains at (0, 0) in the lower right corner, to which I have set my CustomGraphicsViewPlacement.

0 Likes