sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Material is deleted when cloning

    Scheduled Pinned Locked Moved Developers' Forum
    13 Posts 3 Posters 428 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      Marc477
      last edited by

      Can someone explains why this happens ?

      
      test = Sketchup.active_model.materials.current
      #<Sketchup;;Material;0x8a19480>
      test2 = test.clone
      #<Deleted Entity;0x8a19278>
      
      

      I'd like to store a material in a class variable to use it later, if I do not clone, and the selection change, test will not contain the previous material I want, but the new one selected.

      Thank you πŸ˜„

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        I just did the following in SU2014 and got a SPLAT!

        Choose a material that is not in the model.
        Open console.
        test = Sketchup.active_model.materials.current test.name
        Choose a material that IS in the model.
        test2 = Sketchup.active_model.materials.current test2.name
        Everything is fine.
        Now,.. try to get the name of the previous material.
        test.name
        -- > SPLAT

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          Anyway. save the name of the material, and perhaps also it's texture filepath, if it is not yet IN the model.

          Test any material reference for validity before using it. If there is no current material nil may be returned, which evaluates as false.

          if matl && matl.is_a?(Sketchup;;Material)
            # go ahead and use the matl reference in code
            matl_set = Sketchup.active_model.materials
            if matl_set.include?(matl)
              # do something
            end
          end
          

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            The Ruby methods clone and dup, do NOT yet work upon SketchUp API classes.

            We discussed this in previous topics:

            • Clone PolygonMesh
            • Face.clone
            • Re: Temporarility Changing Materials

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • M Offline
              Marc477
              last edited by

              Thank you, I fixed my problem by processing only materials used in the model:

              
              aMat = Sketchup.active_model.materials.current
              if aMat != nil and Sketchup.active_model.materials.include?(aMat)
                 ...
              end
              
              
              
              1 Reply Last reply Reply Quote 0
              • tt_suT Offline
                tt_su
                last edited by

                @dan rathbun said:

                The Ruby methods clone and dup, do NOT yet work upon SketchUp API classes.

                We should improve this. But they would not make sense for Entity based classes as instances are persistent and have to be created via entity.add_*.

                1 Reply Last reply Reply Quote 0
                • tt_suT Offline
                  tt_su
                  last edited by

                  @dan rathbun said:

                  I just did the following in SU2014 and got a SPLAT!

                  Choose a material that is not in the model.
                  Open console.
                  test = Sketchup.active_model.materials.current test.name
                  Choose a material that IS in the model.
                  test2 = Sketchup.active_model.materials.current test2.name
                  Everything is fine.
                  Now,.. try to get the name of the previous material.
                  test.name
                  -- > SPLAT

                  I cannot reproduce this. Did you submit the splat? Did you include any info I can use to look it up?
                  Do you see this consistently? (Can you do a video recording?)

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    I do think I sent in the Splat Report.

                    I do not have video capture software installed (unless it comes with Windows 7?)

                    This was 2 weeks ago... I haven't tried since.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • tt_suT Offline
                      tt_su
                      last edited by

                      Did you enter any details into the BugSplat? (So we can search for it.)

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        I entered the steps that caused the splat, and then copied from the splat dialog, into the above SCF report.

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • tt_suT Offline
                          tt_su
                          last edited by

                          SU2014 Win?

                          1 Reply Last reply Reply Quote 0
                          • tt_suT Offline
                            tt_su
                            last edited by

                            Ah! Found the crash report. And I realized I'd overlooked the last step in your instructions - accessing the name of the first material after it was not current any more. It's another bug where Ruby is allowed to get a handle to a transient material. I'm logging a new issue.

                            1 Reply Last reply Reply Quote 0
                            • Dan RathbunD Offline
                              Dan Rathbun
                              last edited by

                              @tt_su said:

                              Ah! Found the crash report. ... I'm logging a new issue.

                              πŸ‘

                              I'm not here much anymore.

                              1 Reply Last reply Reply Quote 0
                              • 1 / 1
                              • First post
                                Last post
                              Buy SketchPlus
                              Buy SUbD
                              Buy WrapR
                              Buy eBook
                              Buy Modelur
                              Buy Vertex Tools
                              Buy SketchCuisine
                              Buy FormFonts

                              Advertisement