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

    Create component with a subroutine question

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 233 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.
    • S Offline
      shirazbj
      last edited by

      Hi,

      What I want to do is to create a component like a table. I use one same subroutine to create the four legs and the top.

      I declared a component definition in the Main like this:

      $new_comp_def=Sketchup.active_model.definitions.add("MyComp")

      then try to add some face entitites in a subroutine to it like this:

      points ...
      face=$new_comp_def.entities.add_face(points)
      face.pushpull(height)

      The error I got is some nil faces which can't be pushpulled. It seems the global virable $new_comp_def has no efect. I can't save the entities into it. Sometimes the error message says I was referencing a deleted entity.

      Are these faces deleted when the subroutine finished?

      Thanks

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

        Could you post the exact error?

        I'm wondering though, if the points you feed .add_face doesn't make up a face. Do a check if the value face has after .add_face, if it's nil, then the method failed, which leads .pushpull to fail because you are trying to pushpull a nil value.

        Btw, I'd recommend that you don't use global variables. It could interfere with other scripts. Encapsulate your script in a Module or Class and use Module/Class variables instead.

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

        1 Reply Last reply Reply Quote 0
        • S Offline
          shirazbj
          last edited by

          Made some changes and works now.

          It seems I have to declare one definition,add entities and place the component. After that, declare anonther component definition,....

          If I declare a few definitions at the same time, when the subroutine is called for the second component, it will report the entities has been deleted.

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            If you are creating them all like this:

            $bad_global_variable_new_group = entities.add_group $bad_global_variable_new_group = entities.add_group $bad_global_variable_new_group = entities.add_group $bad_global_variable_new_group = entities.add_group
            The variable only points to the last one. The first 3 will be lost.

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

            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