<?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: change the color of a body using the api with python in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12639703#M1891</link>
    <description>&lt;P&gt;Hello j4n &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you for the code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;bRepBody_var.appearance &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; propertyValue&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;shows no context hints in the Visual Studio environment and as per my last message I am unable to effectively search...so being a dummy i cannot use this.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The larger code example is great except I want the body to be programmatically selected.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In my case the body is Bodies:piece, ie the body i want to change color of is named "piece".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have user input functioning in other ways and I'd like the user input to cause "piece" to be colored:&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;hexx_red&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"Paint - Enamel Glossy (Red)"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;hexx_yellow&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"Paint - Enamel Glossy (Yellow)"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;hexx_green&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"Paint - Enamel Glossy (Green)"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;hexx_white&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"Paint - Enamel Glossy (white)"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To highlight my confusion:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;piece&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;design&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;findEntityByToken&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'piece'&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;returns null.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;P.S.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This effort is part of my project in making the world's most difficult jigsaw. see: hexx.au&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If you contact me by email with your address I'll send you a puzzle ( if that appeals )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Mar 2024 07:01:20 GMT</pubDate>
    <dc:creator>andrew</dc:creator>
    <dc:date>2024-03-14T07:01:20Z</dc:date>
    <item>
      <title>change the color of a body using the api with python</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12631058#M1888</link>
      <description>&lt;P&gt;Hello &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have a functioning python script i wish to extend.&lt;/P&gt;&lt;P&gt;I want to change the color of the bodies in the design, I can do this via screen menus, but i want to do this via a script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My searches have not shown any promise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 01:03:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12631058#M1888</guid>
      <dc:creator>andrew</dc:creator>
      <dc:date>2024-03-11T01:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: change the color of a body using the api with python</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12632302#M1889</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;if you just want to play with appearance of a body for visual purposes you can just use the:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;bRepBody_var.appearance = propertyValue&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The tricky thing is how to obtain the appearance you want to to assign to the body. For that you need to load it from appropriate library, if it exists. If it doesn't you will have to copy existing appearance and set its properties to your liking.&lt;BR /&gt;&lt;BR /&gt;This is a sample code that first checks if the desired appearance already exists in one of the libraries and if not, creates new one by copying an existing appearance and editing it.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        design = app.activeProduct
        if not design:
            ui.messageBox('No active Fusion 360 design', 'No Design')
            return
        
        # get the body 
        ui.messageBox("Select a body you want to change", "Body selection")
        body = adsk.fusion.BRepBody.cast(ui.selectEntity('Select a body', 'Bodies').entity)

        # body appearance 
        BodyA = body.appearance; 
        ui.messageBox(BodyA.name, "Body Appearance")


        # Check to see if the "MyColor1" exists in the local appearances
        try:
            myColor = design.appearances.itemByName('MyColor1')
        except:
            myColor = None
            
        if myColor:
            body.appearance = myColor
        else:
            # Get the existing appearance.            
            AppearanceLibrary = app.materialLibraries.itemByName('Fusion Appearance Library')
            yellowColor = AppearanceLibrary.appearances.itemByName('Paint - Enamel Glossy (Yellow)')
        
            # Copy yellow color to the design, giving it a new name.
            newColor = design.appearances.addByCopy(yellowColor, 'MyColor1')
                        
            # Change the color property of the appearance to what you want.
            colorProperty = adsk.core.ColorProperty.cast(newColor.appearanceProperties.itemByName('Color'))
            colorProperty.value = adsk.core.Color.create(0, 204, 0, 0)
            # Assign it to the body.            
            body.appearance = newColor

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;hope this helps&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 07:02:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12632302#M1889</guid>
      <dc:creator>j4n.vokurka</dc:creator>
      <dc:date>2024-03-12T07:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: change the color of a body using the api with python</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12636480#M1890</link>
      <description>&lt;P&gt;Thank you for your prompt reply&lt;SPAN class=""&gt; &lt;A href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13214108" target="_self"&gt;&lt;SPAN class=""&gt;j4n&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/A&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;I'll apply it shortly.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Regards Andrew&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;P.S. a comment: I find the documentation difficult to search. Your code uses the the words color and appearance and these failed to guide me closer to methods I could follow.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 00:01:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12636480#M1890</guid>
      <dc:creator>andrew</dc:creator>
      <dc:date>2024-03-13T00:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: change the color of a body using the api with python</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12639703#M1891</link>
      <description>&lt;P&gt;Hello j4n &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you for the code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;bRepBody_var.appearance &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; propertyValue&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;shows no context hints in the Visual Studio environment and as per my last message I am unable to effectively search...so being a dummy i cannot use this.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The larger code example is great except I want the body to be programmatically selected.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In my case the body is Bodies:piece, ie the body i want to change color of is named "piece".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have user input functioning in other ways and I'd like the user input to cause "piece" to be colored:&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;hexx_red&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"Paint - Enamel Glossy (Red)"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;hexx_yellow&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"Paint - Enamel Glossy (Yellow)"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;hexx_green&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"Paint - Enamel Glossy (Green)"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;hexx_white&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"Paint - Enamel Glossy (white)"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To highlight my confusion:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;piece&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;design&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;findEntityByToken&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'piece'&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;returns null.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;P.S.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This effort is part of my project in making the world's most difficult jigsaw. see: hexx.au&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If you contact me by email with your address I'll send you a puzzle ( if that appeals )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 07:01:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12639703#M1891</guid>
      <dc:creator>andrew</dc:creator>
      <dc:date>2024-03-14T07:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: change the color of a body using the api with python</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12644484#M1892</link>
      <description>&lt;P&gt;Good afternoon 4jn &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have success.&lt;/P&gt;&lt;P&gt;I used chatgpt which provided the clue to finding the body by name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;# locate the body&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;bodies&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;root_comp&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;bRepBodies&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;selected_body&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;None&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;for&lt;/SPAN&gt; &lt;SPAN&gt;body&lt;/SPAN&gt; &lt;SPAN&gt;in&lt;/SPAN&gt; &lt;SPAN&gt;bodies&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt; &lt;SPAN&gt;body&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt; &lt;SPAN&gt;==&lt;/SPAN&gt; &lt;SPAN&gt;'piece'&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;#ui.messageBox(body.name, "Body Appearance")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;selected_body&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;body&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;break&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and setting the color:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;selected_body&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;appearance&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;AppearanceLibrary&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;appearances&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;itemByName&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Paint - Enamel Glossy (White)'&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Its always so exasperating to find the simple solution...&lt;/P&gt;&lt;P&gt;Chatgpt will make stuff up ( pseudo code ) but a clue is a clue &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards Andrew&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 03:38:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12644484#M1892</guid>
      <dc:creator>andrew</dc:creator>
      <dc:date>2024-03-16T03:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: change the color of a body using the api with python</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12645241#M1893</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I provided the previous sample so that you could test/debug how the actual appearance assignment works. To choose the correct object for the assignment is another task which mainly depends on how you have set your model structure to suit your purposes. Without knowing that it's hard to tailor the code to your need.&lt;BR /&gt;&lt;BR /&gt;You can of course select bodies via API. I don't know how familiar you are with the concept of component/occurrences, but based on your sample you try to work with bodies belonging to the root component. If that is always the case you can continue in the logic of your sample. If you however intend to work with bodies belonging to components on different levels in the model structure, this sample will be insufficient.&lt;BR /&gt;&lt;BR /&gt;Feel free to let me know, if you need further help with or clarification of any of the topics I mentioned. If the concept of components/occurrences is new to you in Fusion, take a look at&lt;FONT face="impact,chicago"&gt;&amp;nbsp;&lt;FONT face="verdana,geneva"&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A" target="_blank" rel="noopener"&gt;this&lt;/A&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;article.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jan&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 18:57:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12645241#M1893</guid>
      <dc:creator>j4n.vokurka</dc:creator>
      <dc:date>2024-03-16T18:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: change the color of a body using the api with python</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12645377#M1894</link>
      <description>&lt;P&gt;This should be the script you need:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        design = app.activeProduct
        if not design:
            ui.messageBox('No active Fusion 360 design', 'No Design')
            return
        
        root_comp = design.rootComponent

        # get the body 
        searchedBodyName: str = 'searchedBodyName'
        searchedBody: adsk.fusion.BRepBody = None

        bodies = root_comp.bRepBodies

        for body in bodies:
            if body.name == searchedBodyName:
                searchedBody = body
                break

        # body appearance 
        BodyAppearance = searchedBody.appearance; 
        # ui.messageBox(BodyA.name, "Body Appearance")

        # Check if the color that user chose i.e. hexx_red="Paint - Enamel Glossy (Red)" etc is loaded from the library, otherwise load it
        try:
            myColor = design.appearances.itemByName('MyColor1')
        except:
            myColor = None
            
        if myColor:
            body.appearance = myColor
        else:
            # Get the existing appearance.            
            AppearanceLibrary = app.materialLibraries.itemByName('Fusion Appearance Library')
            yellowColor = AppearanceLibrary.appearances.itemByName('Paint - Enamel Glossy (Yellow)')
        
            # Copy yellow color to the design, giving it a new name.
            newColor = design.appearances.addByCopy(yellowColor, 'MyColor1')
                        
            # Change the color property of the appearance to what you want.
            colorProperty = adsk.core.ColorProperty.cast(newColor.appearanceProperties.itemByName('Color'))
            colorProperty.value = adsk.core.Color.create(0, 204, 0, 0)
            # Assign it to the body.            
            body.appearance = newColor

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;This could of course be further adjusted so you don't have to manually rewrite the wanted color every time you want to use the script. For that I would advise you to create an add-in instead of a script. In this add-in you could create a dialog which lets you select the color you have just decided to work with and you could then edit multiple bodies without the need to run the script every time.&lt;BR /&gt;&lt;BR /&gt;Also a small recommendation, if you are just writing in python it is better to stick to using VS Code because Fusion is primarily configured to work with that IDE. Thread discussing this topic&amp;nbsp;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-743C88FB-CA3F-44B0-B0B9-FCC378D0D782" target="_blank" rel="noopener"&gt;here&lt;/A&gt;&amp;nbsp;.&amp;nbsp;Interesting project btw &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 21:48:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12645377#M1894</guid>
      <dc:creator>j4n.vokurka</dc:creator>
      <dc:date>2024-03-16T21:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: change the color of a body using the api with python</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12645617#M1895</link>
      <description>&lt;P&gt;Thanks j4n &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My code works as desired now &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My script receives information to set the color via user prompt.&lt;/P&gt;&lt;P&gt;I have been using the VS IDE&lt;/P&gt;&lt;P&gt;Regards Andrew&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2024 03:51:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/change-the-color-of-a-body-using-the-api-with-python/m-p/12645617#M1895</guid>
      <dc:creator>andrew</dc:creator>
      <dc:date>2024-03-17T03:51:42Z</dc:date>
    </item>
  </channel>
</rss>

