<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Programmatically Change Material Properties in Process Material Library in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/programmatically-change-material-properties-in-process-material/m-p/11534087#M5134</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11904179"&gt;@jon6CUA5&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We have created a sample that dumps the materialProperties of a selected body.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        msg: str = 'Select'
        selFilter: str = 'Bodies'
        sel: adsk.core.Selection = selectEnt(msg, selFilter)
        if not sel:
            return

        body: adsk.fusion.BRepBody = sel.entity
        material: adsk.core.Material = body.material
        dump(f'-- {material.name} : {material.id} --')
        props: adsk.core.Properties = material.materialProperties
        dump('(Property.name : Property.id : Property.value : Property.isReadOnly)')
        for idx in range(props.count):
            prop: adsk.core.Property = props.item(idx)
            dump(f'{prop.name} : {prop.id} : {prop.value} : {prop.isReadOnly}')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def dump(s):
    adsk.core.Application.get().log(f'{s}')
    print(s)


def selectEnt(
        msg: str,
        filterStr: str) -&amp;gt; adsk.core.Selection:

    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui: adsk.core.UserInterface = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems that each material has different properties that it owns, so I felt that I had to provide an itemById method and an itemByName method.&lt;/P&gt;</description>
    <pubDate>Sun, 06 Nov 2022 13:29:14 GMT</pubDate>
    <dc:creator>kandennti</dc:creator>
    <dc:date>2022-11-06T13:29:14Z</dc:date>
    <item>
      <title>Programmatically Change Material Properties in Process Material Library</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/programmatically-change-material-properties-in-process-material/m-p/11532074#M5132</link>
      <description>&lt;P&gt;I know I can modify basic properties like Density, etc. by retrieving the material from app.materialProperties, but these material objects do not seem to have nesting properties like Length, Width, Frame width, Item separation. Is there another way to access those properties?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2022 22:17:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/programmatically-change-material-properties-in-process-material/m-p/11532074#M5132</guid>
      <dc:creator>jon6CUA5</dc:creator>
      <dc:date>2022-11-04T22:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically Change Material Properties in Process Material Library</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/programmatically-change-material-properties-in-process-material/m-p/11533155#M5133</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11904179"&gt;@jon6CUA5&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't have a solution for you. It is not obvious for me from the Fusion API how to get properties. So, how do you access various properties from&amp;nbsp;&lt;SPAN&gt;materialProperties and&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;appearanceProperties. The only property I know how to get is&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;appearanceProperties&lt;/SPAN&gt;&lt;SPAN&gt;.itemByName(&lt;/SPAN&gt;&lt;SPAN&gt;'Image'&lt;/SPAN&gt;&lt;SPAN&gt;). Are all property names in the from Fusion material dialog as seen by the user? For example, I got the "Image" name from the "Material Editor" dialog. If so, how would one handle names that appear in sub dialog? I hope all prop names are in a flat data structure.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Nov 2022 16:46:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/programmatically-change-material-properties-in-process-material/m-p/11533155#M5133</guid>
      <dc:creator>sophiadoan</dc:creator>
      <dc:date>2022-11-05T16:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically Change Material Properties in Process Material Library</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/programmatically-change-material-properties-in-process-material/m-p/11534087#M5134</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11904179"&gt;@jon6CUA5&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We have created a sample that dumps the materialProperties of a selected body.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        msg: str = 'Select'
        selFilter: str = 'Bodies'
        sel: adsk.core.Selection = selectEnt(msg, selFilter)
        if not sel:
            return

        body: adsk.fusion.BRepBody = sel.entity
        material: adsk.core.Material = body.material
        dump(f'-- {material.name} : {material.id} --')
        props: adsk.core.Properties = material.materialProperties
        dump('(Property.name : Property.id : Property.value : Property.isReadOnly)')
        for idx in range(props.count):
            prop: adsk.core.Property = props.item(idx)
            dump(f'{prop.name} : {prop.id} : {prop.value} : {prop.isReadOnly}')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def dump(s):
    adsk.core.Application.get().log(f'{s}')
    print(s)


def selectEnt(
        msg: str,
        filterStr: str) -&amp;gt; adsk.core.Selection:

    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui: adsk.core.UserInterface = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems that each material has different properties that it owns, so I felt that I had to provide an itemById method and an itemByName method.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2022 13:29:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/programmatically-change-material-properties-in-process-material/m-p/11534087#M5134</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2022-11-06T13:29:14Z</dc:date>
    </item>
  </channel>
</rss>

