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

    Model.import() always true?

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 4 Posters 257 Views
    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.
    • A Offline
      Aerilius
      last edited by Aerilius

      Hi,
      I'm trying to import collada files via the API. After importing, I want to apply some transformations to those files.
      According to the API, the Model.import method returns true/ false, but not the imported object.

      First Question: Is there a direct way to get the imported component instance? My current workaround is to get the last element of Model.entities:
      imported=@model.entities[@model.entities.length-1]
      ( @model.entities.last didn't work for me)
      This workaround makes only sense if the last element is actually the imported component instance and if the import was successful.

      The second problem is: When I import a corrupted collada file, the import should fail and return false, but for me it returns true. Is this a bug in the API, or does it depend how the import fails?

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        @aerilius said:

        First Question:

        cache = model.entities.to_a model.import( ... ) imported_instance = ( model.entities.to_a - cache ).first

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          Or...
          Do the import, then immediately
          defn=model.definitions.to_a[-1] instance=defn.instances[0]
          then use instance.transform!(tr)
          where 'tr' is the required transformation.
          Or it's it's easier for you to make a new transformation from scratch use
          instance.erase!
          followed by
          instance=model.active_entities.add_instance(defn, tr)
          where 'tr' is the required transformation...

          TIG

          1 Reply Last reply Reply Quote 0
          • A Offline
            Aerilius
            last edited by

            Thanks!

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

              @aerilius said:

              The second problem is: When I import a corrupted collada file, the import should fail and return false, but for me it returns true. Is this a bug in the API, or does it depend how the import fails?

              Do you have "Validate Collada File" checked in the Import Options dialog ??

              When the import "fails" does Sketchup raise any Ruby exception that can be trapped with a begin .. rescue .. end block?

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • A Offline
                Aerilius
                last edited by

                For yery corrupted collada files, there appears just a messagebox "import failed [OK]". The ruby console does not display any exception but just true``.

                For some collada files, SketchUp says there is a chance that the import could fail and asks if I want to continue [yes]/[no].
                If I click yes, it succeeds to import it anyways, if I click no, the same messagebox appears "import failed [Ok]. In all cases, the console says true. I tried it with begin ... rescue ... end without success.


                model.zip

                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