Appearance properties

There is an article related to Appearance‘s and a sample script installed with Fusion 360 that shows how to access Appearances from the libraries and assign them to objects in the model: “ApplyAppearanceToSelection.py

In some cases you may want to drill down into the properties of the Appearance‘s which are used in the model, to find e.g. the texture that is being used by a given Appearance.
The following Python sample only shows how to access the name and value of the properties, but there are more than that available. If you look at the Property object in the online help file, then in the “Derived Classes” section you’ll see that quite a few other objects are derived from that. If you wanted to access all the properties then you’d need to handle all of them and check all their properties: http://help.autodesk.com/view/NINVFUS/ENU/?guid=GUID-db167e70-665f-4101-ba3c-3bcc88000fc7

import adsk.core, adsk.fusion, adsk.cam, traceback
def exportProperties(properties, indent, outputFile):
for prop in properties:
if type(prop) is adsk.core.AppearanceTextureProperty:
outputFile.writelines(indent + prop.name + "n")
try:
exportProperties(prop.value.properties, indent + "  ", outputFile)
except:
outputFile.writelines(indent + "  Couldn't get sub propertiesn")
elif type(prop) is adsk.core.ColorProperty:
if prop.value:
color = prop.value
outputFile.writelines(indent +
"red = " + str(color.red) +
"; green = " + str(color.green) +
"; blue = " + str(color.blue) +"n")
else:
outputFile.writelines(indent + prop.name + " = " + str(prop.value) + "n")
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui  = app.userInterface
fileDialog = ui.createFileDialog()
fileDialog.isMultiSelectEnabled = False
fileDialog.title = "Get the file to save to"
fileDialog.filter = 'Text files (*.txt)'
fileDialog.filterIndex = 0
dialogResult = fileDialog.showSave()
if dialogResult == adsk.core.DialogResults.DialogOK:
fileName = fileDialog.filename
else:
return
design = app.activeProduct
with open(fileName, 'w') as outputFile:
for appearance in design.appearances:
outputFile.writelines(">>>>> " + appearance.name + " <<<<<n")
exportProperties(appearance.appearanceProperties, "  ", outputFile)
except:
if ui:
ui.messageBox('Failed:n{}'.format(traceback.format_exc()))

You will get something like this:

>>>>> Oak - Semigloss <<<<<
Material Type = 0
URN =
Emission = False
Reflectance = 0.06027025
URN =
Emissive Luminance = 0.0
red = 255; green = 255; blue = 255
URN =
Depth = 0.5
red = 255; green = 255; blue = 255
URN =
Translucency = False
red = 255; green = 255; blue = 255
URN =
Anisotropy = 0.0
URN =
Image
Couldn't get sub properties
URN =
NDF = surface_ndf_ggx
Image
Source = /Users/adamnagy/Library/Containers/com.autodesk.mas.fusion360/
Data/Library/Application Support/Autodesk/Common/Material Library/16021701/
slib/resource/1/Mats/wood_oak_bump.jpg
URN =
Amount = 0.003
Amount = 1.0
Bump Type = bumpmap_height_map
Sharing = common_shared
red = 80; green = 80; blue = 80
Tint = False
Link texture transforms = False
Map Channel = 1
Map Channel = 1
UVW Source = 0
Offset Lock = False
Offset = 0.0
Offset Y = 0.0
Sample Size = 18.0
Size Y = 36.0
Scale Lock = True
U Offset = 0.0
Horizontal = True
U Scale = 1.0
UV Scale = 1.0
V Offset = 0.0
Vertical = True
V Scale = 1.0
Rotation = 0.0
URN =
Rotation = 0.0
URN =
Roughness = 0.2
URN =

-Adam


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading