Smart unwrap using script

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












I am stuck. I am trying to smart unwrap objects individually using script.



I tried this code but it fails. Any help is appreciated



import bpy
import time

for obj in bpy.data.objects:
if (obj.type == 'MESH'):
bpy.context.scene.objects.active = obj
print(obj.name)
bpy.ops.object.editmode_toggle()
bpy.context.object.data.uv_textures['LightMap'].active = True
bpy.ops.uv.smart_project(angle_limit=66, island_margin = 0.02)
bpy.ops.object.editmode_toggle()









share|improve this question









New contributor




Cgprojectsfx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    1
    down vote

    favorite












    I am stuck. I am trying to smart unwrap objects individually using script.



    I tried this code but it fails. Any help is appreciated



    import bpy
    import time

    for obj in bpy.data.objects:
    if (obj.type == 'MESH'):
    bpy.context.scene.objects.active = obj
    print(obj.name)
    bpy.ops.object.editmode_toggle()
    bpy.context.object.data.uv_textures['LightMap'].active = True
    bpy.ops.uv.smart_project(angle_limit=66, island_margin = 0.02)
    bpy.ops.object.editmode_toggle()









    share|improve this question









    New contributor




    Cgprojectsfx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am stuck. I am trying to smart unwrap objects individually using script.



      I tried this code but it fails. Any help is appreciated



      import bpy
      import time

      for obj in bpy.data.objects:
      if (obj.type == 'MESH'):
      bpy.context.scene.objects.active = obj
      print(obj.name)
      bpy.ops.object.editmode_toggle()
      bpy.context.object.data.uv_textures['LightMap'].active = True
      bpy.ops.uv.smart_project(angle_limit=66, island_margin = 0.02)
      bpy.ops.object.editmode_toggle()









      share|improve this question









      New contributor




      Cgprojectsfx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am stuck. I am trying to smart unwrap objects individually using script.



      I tried this code but it fails. Any help is appreciated



      import bpy
      import time

      for obj in bpy.data.objects:
      if (obj.type == 'MESH'):
      bpy.context.scene.objects.active = obj
      print(obj.name)
      bpy.ops.object.editmode_toggle()
      bpy.context.object.data.uv_textures['LightMap'].active = True
      bpy.ops.uv.smart_project(angle_limit=66, island_margin = 0.02)
      bpy.ops.object.editmode_toggle()






      python






      share|improve this question









      New contributor




      Cgprojectsfx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Cgprojectsfx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 2 hours ago









      batFINGER

      20.6k42261




      20.6k42261






      New contributor




      Cgprojectsfx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 hours ago









      Cgprojectsfx

      62




      62




      New contributor




      Cgprojectsfx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Cgprojectsfx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Cgprojectsfx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          Some Edits



          • The collection bpy.data.objects is all objects in a blend file,
            whether linked to context scene, another scene or no scene. If not in
            the context scene cannot be the context object. Use scene.objects

          • I put the "convenience variable" context in test scripts, so I can
            paste later into panel or operator code where it is passed as a
            parameter to most methods, in which case better not to use path addressing from bpy IMO it gets tedious reading bpy.context.object.data.uv_foo.bar.blah

          • Add a UV map named "LightMap" if the mesh doesn't already have one.

          • Blender uses radians not degrees as the native unit of rotation.

          Script



          import bpy
          from math import radians

          context = bpy.context
          scene = context.scene

          for obj in scene.objects:
          if (obj.type == 'MESH'):
          scene.objects.active = obj
          obj.select = True
          print(obj.name)
          lm = obj.data.uv_textures.get("LightMap")
          if not lm:
          lm = obj.data.uv_textures.new("LightMap")
          lm.active = True
          bpy.ops.object.editmode_toggle()
          bpy.ops.uv.smart_project(angle_limit=radians(66), island_margin = 0.02)
          bpy.ops.object.editmode_toggle()


          enter image description hereResultant UVMap "LightMap" on Suzanne






          share|improve this answer






















            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "502"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );






            Cgprojectsfx is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fblender.stackexchange.com%2fquestions%2f120805%2fsmart-unwrap-using-script%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote













            Some Edits



            • The collection bpy.data.objects is all objects in a blend file,
              whether linked to context scene, another scene or no scene. If not in
              the context scene cannot be the context object. Use scene.objects

            • I put the "convenience variable" context in test scripts, so I can
              paste later into panel or operator code where it is passed as a
              parameter to most methods, in which case better not to use path addressing from bpy IMO it gets tedious reading bpy.context.object.data.uv_foo.bar.blah

            • Add a UV map named "LightMap" if the mesh doesn't already have one.

            • Blender uses radians not degrees as the native unit of rotation.

            Script



            import bpy
            from math import radians

            context = bpy.context
            scene = context.scene

            for obj in scene.objects:
            if (obj.type == 'MESH'):
            scene.objects.active = obj
            obj.select = True
            print(obj.name)
            lm = obj.data.uv_textures.get("LightMap")
            if not lm:
            lm = obj.data.uv_textures.new("LightMap")
            lm.active = True
            bpy.ops.object.editmode_toggle()
            bpy.ops.uv.smart_project(angle_limit=radians(66), island_margin = 0.02)
            bpy.ops.object.editmode_toggle()


            enter image description hereResultant UVMap "LightMap" on Suzanne






            share|improve this answer


























              up vote
              2
              down vote













              Some Edits



              • The collection bpy.data.objects is all objects in a blend file,
                whether linked to context scene, another scene or no scene. If not in
                the context scene cannot be the context object. Use scene.objects

              • I put the "convenience variable" context in test scripts, so I can
                paste later into panel or operator code where it is passed as a
                parameter to most methods, in which case better not to use path addressing from bpy IMO it gets tedious reading bpy.context.object.data.uv_foo.bar.blah

              • Add a UV map named "LightMap" if the mesh doesn't already have one.

              • Blender uses radians not degrees as the native unit of rotation.

              Script



              import bpy
              from math import radians

              context = bpy.context
              scene = context.scene

              for obj in scene.objects:
              if (obj.type == 'MESH'):
              scene.objects.active = obj
              obj.select = True
              print(obj.name)
              lm = obj.data.uv_textures.get("LightMap")
              if not lm:
              lm = obj.data.uv_textures.new("LightMap")
              lm.active = True
              bpy.ops.object.editmode_toggle()
              bpy.ops.uv.smart_project(angle_limit=radians(66), island_margin = 0.02)
              bpy.ops.object.editmode_toggle()


              enter image description hereResultant UVMap "LightMap" on Suzanne






              share|improve this answer
























                up vote
                2
                down vote










                up vote
                2
                down vote









                Some Edits



                • The collection bpy.data.objects is all objects in a blend file,
                  whether linked to context scene, another scene or no scene. If not in
                  the context scene cannot be the context object. Use scene.objects

                • I put the "convenience variable" context in test scripts, so I can
                  paste later into panel or operator code where it is passed as a
                  parameter to most methods, in which case better not to use path addressing from bpy IMO it gets tedious reading bpy.context.object.data.uv_foo.bar.blah

                • Add a UV map named "LightMap" if the mesh doesn't already have one.

                • Blender uses radians not degrees as the native unit of rotation.

                Script



                import bpy
                from math import radians

                context = bpy.context
                scene = context.scene

                for obj in scene.objects:
                if (obj.type == 'MESH'):
                scene.objects.active = obj
                obj.select = True
                print(obj.name)
                lm = obj.data.uv_textures.get("LightMap")
                if not lm:
                lm = obj.data.uv_textures.new("LightMap")
                lm.active = True
                bpy.ops.object.editmode_toggle()
                bpy.ops.uv.smart_project(angle_limit=radians(66), island_margin = 0.02)
                bpy.ops.object.editmode_toggle()


                enter image description hereResultant UVMap "LightMap" on Suzanne






                share|improve this answer














                Some Edits



                • The collection bpy.data.objects is all objects in a blend file,
                  whether linked to context scene, another scene or no scene. If not in
                  the context scene cannot be the context object. Use scene.objects

                • I put the "convenience variable" context in test scripts, so I can
                  paste later into panel or operator code where it is passed as a
                  parameter to most methods, in which case better not to use path addressing from bpy IMO it gets tedious reading bpy.context.object.data.uv_foo.bar.blah

                • Add a UV map named "LightMap" if the mesh doesn't already have one.

                • Blender uses radians not degrees as the native unit of rotation.

                Script



                import bpy
                from math import radians

                context = bpy.context
                scene = context.scene

                for obj in scene.objects:
                if (obj.type == 'MESH'):
                scene.objects.active = obj
                obj.select = True
                print(obj.name)
                lm = obj.data.uv_textures.get("LightMap")
                if not lm:
                lm = obj.data.uv_textures.new("LightMap")
                lm.active = True
                bpy.ops.object.editmode_toggle()
                bpy.ops.uv.smart_project(angle_limit=radians(66), island_margin = 0.02)
                bpy.ops.object.editmode_toggle()


                enter image description hereResultant UVMap "LightMap" on Suzanne







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 2 hours ago

























                answered 2 hours ago









                batFINGER

                20.6k42261




                20.6k42261




















                    Cgprojectsfx is a new contributor. Be nice, and check out our Code of Conduct.









                     

                    draft saved


                    draft discarded


















                    Cgprojectsfx is a new contributor. Be nice, and check out our Code of Conduct.












                    Cgprojectsfx is a new contributor. Be nice, and check out our Code of Conduct.











                    Cgprojectsfx is a new contributor. Be nice, and check out our Code of Conduct.













                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fblender.stackexchange.com%2fquestions%2f120805%2fsmart-unwrap-using-script%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

                    Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                    Confectionery