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

    Variables - issue

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 4 Posters 304 Views 4 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.
    • artmusicstudioA Offline
      artmusicstudio
      last edited by

      hi,
      i just studied the different variables (@, $), but i cannot find out, why my definition does not work:

      i define certain variables in loop 1:


      for pfosten in 0..2
      pfostenname=[]
      pfostenname[0] = "masterpfostenl"
      pfostenname[1] = "masterpfostenr"
      pfostenname[2] = "mittelpfostenm"

         ..........          
      

      else

      .........

      end
      puts "creating component"
      puts pfostenname[pfosten]
      pfostenname[pfosten] = group.to_component

      end


      after this, the 3 components are created (master elements for further transformation). OK

      BUT

      in the following loop (later in the ruby)


      if (step) / il == podestnr #some conditions

          	componentinstance =
      	entities.add_instance(masterpfostenl.definition, pf1p) # copy to point pf1p
      	    		 		
      		elsif   
      

      ..................

                  elsif
      

      ....................
      end


      the add instance function reports:

      Error: #<NameError: undefined local variable or method `masterpfostenl' for main:Object>

      why does this happen?

      the component with the name "masterpfostenl" exists and is placed on the screen

      so why does the transfer-function not find it?

      thank you a lot. i just ry to understand, how the variable-instances work...
      stan

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

        πŸ˜’
        @unknownuser said:

        the component with the name " masterpfostenl" exists
        BUT that's a ' string' NOT a reference...
        SO using it as a reference is not going to work!
        BUT:
        compo = Sketchup.active_model.definitions["masterpfostenl"]
        sets up a proper reference to the component's definition [assuming there is an existing definition named " masterpfostenl"]...
        SO NOW:
        componentinstance = entities.add_instance(compo, pf1p)
        will work... provided that pf1p is a valid transformation... which you have not fully explained...

        As I said before... please put extracts of code in a 'code' BBCs tag [][/], shorter bits can be unformatted in a 'ruby' tag [][/]

        TIG

        1 Reply Last reply Reply Quote 0
        • artmusicstudioA Offline
          artmusicstudio
          last edited by

          hi tig,
          sorry, is this
          "As I said before... please put extracts of code in a 'code' BBCs tag [][/], shorter bits can be unformatted in a 'ruby' tag [][/]"
          ment for the forum syntax? if so, is there a guide? please excuse, when i missed it so far.

          for the ruby:
          what ever i do, i cannot manage it within the loop (weven hith your tips). placing one element after each other works perfect. so i have to go a step back and need some days to study the basic principles of variables and instances (but the ruby grows!!!).
          thanx a lot , i keep on trying...
          stan

          1 Reply Last reply Reply Quote 0
          • massimoM Offline
            massimo Moderator
            last edited by

            Moved to developers forum.

            Hi Stan, would you mind to post such threads in developers section of the forum? Usually the newbie section is about SU's usage.
            Thanks.

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

              @artmusicstudio said:

              
              > Error; #<NameError; undefined local variable or method `masterpfostenl' for main;Object>
              > 
              

              The error also shows that you are executing your code within main:Object (the TOPLEVEL_BINDING.)

              You should execute your code within YOUR namespace.

              Example:

              module AMS #<--<< namespace module for ArtMusicStudio
                module ThisPluginName
              
                  # code here - use  @ or @@ vars
              
                end # plugin sub-module
              end # namespace module for ArtMusicStudio
              

              πŸ’­

              I'm not here much anymore.

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

                Thanks Dan πŸ˜„
                What you say is VERY important...
                BUT the OP has so many issues with his understanding of Ruby coding that I felt it would confuse issues too much if he had 'too many balls to juggle' πŸ˜‰

                But I expect a separate thread on this now............

                TIG

                1 Reply Last reply Reply Quote 0
                • artmusicstudioA Offline
                  artmusicstudio
                  last edited by

                  @massimo said:

                  Moved to developers forum.

                  Hi Stan, would you mind to post such threads in developers section of the forum? Usually the newbie section is about SU's usage.
                  Thanks.

                  hi massimo,
                  sorry, of course, didn't think about that , i'll be carefull in the future!
                  stan

                  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