So, fixing your python script worked? I'm jsut doing first plugin and I can't get the correcto locations of my ocurrences. SpurGear script have failed, both python and c++ version(The C++ version crashes!). Other scripts seem to do nothing. I'm using the latest version of both fusion and VS on Mac :/.
This is my plugin code, could you try it? it doesn't crash, it jsut returns the worng positions(posted here also: https://forums.autodesk.com/t5/fusion-360-api-and-scripts/billboards-at-wrong-location/m-p/9063494😞
#Author- Raul Huertas
#Description-
import adsk.core, adsk.fusion, adsk.cam, traceback
def esPisoQ(componente):
atributoPrevio = componente.attributes.itemByName('ITSTools', 'Tipo')
if atributoPrevio :
if atributoPrevio.value == "Piso" :
return True
else:
return False
else:
return False
def esMaqQ(componente):
atributoPrevio = componente.attributes.itemByName('ITSTools', 'Tipo')
if atributoPrevio :
if atributoPrevio.value == "Maquina" :
return True
else:
return False
else:
return False
def getN(componente, numeroStr):
print("TIPO: ", type(componente) ,"\n")
print("NOMBRE: ", (componente.fullPathName) ,"\n")
atributoPrevio = componente.attributes.itemByName('ITSTools', 'N')
if atributoPrevio :
return atributoPrevio.value
else:
return ""
def nMaquinaExisteQ( numeroStr ):
returnValue = false;
app = adsk.core.Application.get()
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
occs = rootComp.occurrences
for componente in occs:
if isinstance(componente, adsk.fusion.Occurrence):
atributoPrevio = componente.attributes.itemByName('ITSTools', 'NMaquina')
if atributoPrevio :
numeroStrActual = atributoPrevio.value
if numeroStrActual==numeroStr :
returnValue = true
break
return returnValue
def listar(componente):
print("TIPO: ", type(componente) ,"\n")
print("NOMBRE: ", (componente.fullPathName) ,"\n")
print("TRANSFORM: ", (componente.transform) ,"\n")
print("TRANSFORM ARRAY: ", (componente.transform.asArray()) ,"\n")
def ocultarVistaITS():
app = adsk.core.Application.get()
# des = adsk.fusion.Design.cast(app.activeProduct)
des = app.activeProduct
root = des.rootComponent
for graphGroup in root.customGraphicsGroups:
if graphGroup.id == "ITSMarks":
graphGroup.deleteMe()
break
return
def actualizarVistaITS():
app = adsk.core.Application.get()
# des = adsk.fusion.Design.cast(app.activeProduct)
des = app.activeProduct
root = des.rootComponent
ocultarVistaITS()
graphics = root.customGraphicsGroups.add()
graphics.id = "ITSMarks"
pointIndices = [0];
occs = root.occurrences
for componente in occs:
listar(componente)
if esMaqQ (componente):
# coordsOrg = adsk.core.Vector3D.create(0,0,0)
# coordsOrg.transformBy(componente.transform)
# coords = adsk.fusion.CustomGraphicsCoordinates.create([componente.transform.translation.x, componente.transform.translation.y, componente.transform.translation.z])
# points = graphics.addPointSet(coords, pointIndices,
# adsk.fusion.CustomGraphicsPointTypes.UserDefinedCustomGraphicsPointType,
# 'resourcesMaquina/32x32@2x.png')
identityMatrix = adsk.core.Matrix3D.create()
graphicsText = graphics.addText("Maquina", 'Arial', 50, identityMatrix)
# point = componente.boundingBox.minPoint
point = componente.transform.translation
billBoard = adsk.fusion.CustomGraphicsBillBoard.create(
adsk.core.Point3D.create(point.x, point.y, point.z)
)
billBoard.billBoardStyle = adsk.fusion.CustomGraphicsBillBoardStyles.ScreenBillBoardStyle
graphicsText.billBoarding = billBoard
adsk.doEvents()
elif esPisoQ(componente):
# coordsOrg = adsk.core.Vector3D.create(0,0,0)
# coordsOrg.transformBy(componente.transform)
# coords = adsk.fusion.CustomGraphicsCoordinates.create([componente.transform.translation.x, componente.transform.translation.y, componente.transform.translation.z])
# points = graphics.addPointSet(coords, pointIndices,
# adsk.fusion.CustomGraphicsPointTypes.UserDefinedCustomGraphicsPointType,
# 'resourcesPiso/32x32@2x.png')
text = 'Piso'
matrix = adsk.core.Matrix3D.create()
# matrix.translation = componente.transform.translation
graphicsText = graphics.addText(text, 'Arial', 50, matrix)
# billBoard = adsk.fusion.CustomGraphicsBillBoard.create(adsk.core.Point3D.create(componente.transform.translation.x, componente.transform.translation.y, componente.transform.translation.z))
(origin, xAxis, yAxis, zAxis) = componente.transform.getAsCoordinateSystem()
billBoard = adsk.fusion.CustomGraphicsBillBoard.create(origin)
billBoard.billBoardStyle = adsk.fusion.CustomGraphicsBillBoardStyles.ScreenBillBoardStyle
graphicsText.billBoarding = billBoard
adsk.doEvents()
app.activeViewport.refresh()
def configurarComoPiso(componente):
print("TIPO: ", type(componente) ,"\n")
print("NOMBRE: ", (componente.fullPathName) ,"\n")
print("TRANSFORM: ", (componente.transform) ,"\n")
print("TRANSFORM ARRAY: ", (componente.transform.asArray()) ,"\n")
# ui.messageBox(type(componente))
# ui.messageBox('componente.fullPathName)
atributoPrevio = componente.attributes.itemByName('ITSTools', 'Tipo')
if atributoPrevio :
if atributoPrevio.value != "Piso" :
componente.attributes.add('ITSTools', 'Tipo', "Piso");
else:
componente.attributes.add('ITSTools', 'Tipo', "Piso");
# print(componente.fullPathName, " configurado como Piso\n")
def configurarComoMaquina(componente):
print("TIPO: ", type(componente) ,"\n")
print("NOMBRE: ", (componente.fullPathName) ,"\n")
atributoPrevio = componente.attributes.itemByName('ITSTools', 'Tipo')
if atributoPrevio :
if atributoPrevio.value != "Maquina" :
componente.attributes.add('ITSTools', 'Tipo', "Maquina");
else:
componente.attributes.add('ITSTools', 'Tipo', "Maquina");
# print(componente.fullPathName, " configurado como Maquina\n")
def desmarcar(componente):
atributoPrevio = componente.attributes.itemByName('ITSTools', 'Tipo')
if atributoPrevio :
atributoPrevio.deleteMe()
# global mapping list of event handlers to keep them referenced for the duration of the command
#handlers = {}
handlers = []
cmdDefs = []
selection = []
botonMostrar = None
botonOcultar = None
def run(context):
ui = None
handlers.clear()
try:
app = adsk.core.Application.get()
ui = app.userInterface
def setLinearMarkingMenu(args):
try:
menuArgs = adsk.core.MarkingMenuEventArgs.cast(args)
commands = []
linearMenu = menuArgs.linearMarkingMenu
if args.selectedEntities:
sel0 = args.selectedEntities[0]
if isinstance(sel0, adsk.fusion.Occurrence):
linearMenu.controls.addSeparator('LinearSeparator')
if(esPisoQ(sel0)):
cmdDefSpecial = ui.commandDefinitions.itemById('ITSIndPiso')
linearMenu.controls.addCommand(cmdDefSpecial)
if(esMaqQ(sel0)):
cmdDefSpecial = ui.commandDefinitions.itemById('ITSIndMaq')
linearMenu.controls.addCommand(cmdDefSpecial)
cmdDefSpecial = ui.commandDefinitions.itemById('ITSPisoCommand')
linearMenu.controls.addCommand(cmdDefSpecial)
cmdDefSpecial = ui.commandDefinitions.itemById('ITSMaquinaCommand')
linearMenu.controls.addCommand(cmdDefSpecial)
cmdDefSpecial = ui.commandDefinitions.itemById('ITSDesmarcarCommand')
linearMenu.controls.addCommand(cmdDefSpecial)
except:
if ui:
ui.messageBox('setting linear menu failed: {}').format(traceback.format_exc())
def setRadialMarkingMenu(args):
try:
menuArgs = adsk.core.MarkingMenuEventArgs.cast(args)
except:
if ui:
ui.messageBox('setting radial menu failed: {}').format(traceback.format_exc())
class MarcarComoITSHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
command = args.command
onCommandExcute = MarcarComoITSExecuteHandler()
handlers.append(onCommandExcute)
command.execute.add(onCommandExcute)
except:
ui.messageBox('command created failed: {}').format(traceback.format_exc())
class MarcarComoITSExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
command = args.firingEvent.sender
cmdDef = command.parentCommandDefinition
if cmdDef:
if cmdDef.id == 'ITSPisoCommand':
if selection:
for componenteEntity in selection:
configurarComoPiso(componenteEntity)
actualizarVistaITS()
else:
ui.messageBox('No hay componente seleccionado.')
elif cmdDef.id == 'ITSMaquinaCommand':
if selection:
for componenteEntity in selection:
configurarComoMaquina(componenteEntity)
actualizarVistaITS()
else:
ui.messageBox('No hay componente seleccionado.')
elif cmdDef.id == 'ITSDesmarcarCommand':
if selection:
for componenteEntity in selection:
desmarcar(componenteEntity)
actualizarVistaITS()
else:
ui.messageBox('No hay componente seleccionado.')
elif cmdDef.id == 'ITSMostrarCommand':
actualizarVistaITS()
elif cmdDef.id == 'ITSOcultarCommand':
ocultarVistaITS()
else:
ui.messageBox('No hay definición de comando')
except:
if ui:
ui.messageBox('Error ejecutando comando: {}'.format(traceback.format_exc()))
class MyMarkingMenuHandler(adsk.core.MarkingMenuEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
setLinearMarkingMenu(args)
setRadialMarkingMenu(args)
# selected entities
global selection
selection.clear()
selection = args.selectedEntities
except:
if ui:
ui.messageBox('Marking Menu Displaying event failed: {}'.format(traceback.format_exc()))
# Add customized handler for marking menu displaying
onMarkingMenuDisplaying = MyMarkingMenuHandler()
handlers.append(onMarkingMenuDisplaying)
ui.markingMenuDisplaying.add(onMarkingMenuDisplaying)
# Add customized handler for commands creating
onCommandCreated = MarcarComoITSHandler()
handlers.append(onCommandCreated)
# CREAR COMANDOS
# Para indicar si es maquina
ITSIndMaq = ui.commandDefinitions.itemById('ITSIndMaq')
if not ITSIndMaq:
ITSIndMaq = ui.commandDefinitions.addButtonDefinition('ITSIndMaq', 'Tipo Actual: Máquina', 'Indica que este componente es máquina.', './resourcesITSLogo')
ITSIndMaq.commandCreated.add(onCommandCreated)
cmdDefs.append(ITSIndMaq)
ITSIndPiso = ui.commandDefinitions.itemById('ITSIndPiso')
if not ITSIndPiso:
ITSIndPiso = ui.commandDefinitions.addButtonDefinition('ITSIndPiso', 'Tipo Actual: Piso', 'Indica que este componente es piso.', './resourcesITSLogo')
ITSIndPiso.commandCreated.add(onCommandCreated)
cmdDefs.append(ITSIndPiso)
# Para crear maquinas
ITSMaquinaCommand = ui.commandDefinitions.itemById('ITSMaquinaCommand')
if not ITSMaquinaCommand:
ITSMaquinaCommand = ui.commandDefinitions.addButtonDefinition('ITSMaquinaCommand', 'Marcar como Máquina...', 'Marca este componente como máquina.', './resourcesITSLogo')
ITSMaquinaCommand.commandCreated.add(onCommandCreated)
cmdDefs.append(ITSMaquinaCommand)
# Para crear pisos
ITSPisoCommand = ui.commandDefinitions.itemById('ITSPisoCommand')
if not ITSPisoCommand:
ITSPisoCommand = ui.commandDefinitions.addButtonDefinition('ITSPisoCommand', 'Marcar como Piso...', 'Marca este componente como piso.', './resourcesITSLogo')
ITSPisoCommand.commandCreated.add(onCommandCreated)
cmdDefs.append(ITSPisoCommand)
# Para desmarcar
ITSDesmarcarCommand = ui.commandDefinitions.itemById('ITSDesmarcarCommand')
if not ITSDesmarcarCommand:
ITSDesmarcarCommand = ui.commandDefinitions.addButtonDefinition('ITSDesmarcarCommand', 'Desmarcar...', 'Quita cualquier atributo de ITS.', './resourcesITSLogo')
ITSDesmarcarCommand.commandCreated.add(onCommandCreated)
cmdDefs.append(ITSDesmarcarCommand)
# ui.messageBox('Right click to see the customized marking menu.')
#CREAR BOTON EN EL PANEL DE HERRAMIENTAS
global botonMostrar
global botonOcultar
ITSMostrarCommand = ui.commandDefinitions.itemById('ITSMostrarCommand')
if not ITSMostrarCommand:
ITSMostrarCommand = ui.commandDefinitions.addButtonDefinition('ITSMostrarCommand', 'Mostrar roles',
'Muestra los roles de cada componente',
'./resourcesOjoSI')
ITSMostrarCommand.commandCreated.add(onCommandCreated)
cmdDefs.append(ITSMostrarCommand)
panelObjetivo = ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
botonMostrar = panelObjetivo.controls.addCommand(ITSMostrarCommand)
botonMostrar.isPromotedByDefault = True
botonMostrar.isPromoted = True
ITSOcultarCommand = ui.commandDefinitions.itemById('ITSOcultarCommand')
if not ITSOcultarCommand:
ITSOcultarCommand = ui.commandDefinitions.addButtonDefinition('ITSOcultarCommand', 'Ocultar roles',
'Oculta los roles',
'./resourcesOjoNO')
ITSOcultarCommand.commandCreated.add(onCommandCreated)
cmdDefs.append(ITSOcultarCommand)
panelObjetivo = ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
botonOcultar = panelObjetivo.controls.addCommand(ITSOcultarCommand)
botonOcultar.isPromotedByDefault = True
botonOcultar.isPromoted = True
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
# ocultarVistaITS()
for obj in cmdDefs:
if obj.isValid:
obj.deleteMe()
else:
ui.messageBox(str(obj) + ' is not a valid object')
handlers.clear()
global botonMostrar
global botonOcultar
botonMostrar.deleteMe()
botonOcultar.deleteMe()
# ui.messageBox('Stop addin')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))