• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

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 23 Mar 2009, 05:02

    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
    • T Offline
      thomthom
      last edited by 23 Mar 2009, 07:11

      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 23 Mar 2009, 12:08

        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
        • C Offline
          Chris Fullmer
          last edited by 23 Mar 2009, 16:02

          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
          1 / 1
          • First post
            1/4
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement