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()))
