• Login
sketchucation logo sketchucation
  • Login
βŒ› Sale Ending | 30% Off Profile Builder 4 ends 30th September

Variables - issue

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 4 Posters 318 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.
  • A Offline
    artmusicstudio
    last edited by 16 Oct 2013, 19:51

    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
    • T Offline
      TIG Moderator
      last edited by 16 Oct 2013, 21:47

      πŸ˜’
      @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
      • A Offline
        artmusicstudio
        last edited by 17 Oct 2013, 13:04

        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
        • M Offline
          massimo Moderator
          last edited by 17 Oct 2013, 14:25

          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
          • D Offline
            Dan Rathbun
            last edited by 17 Oct 2013, 16:54

            @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
            • T Offline
              TIG Moderator
              last edited by 17 Oct 2013, 18:08

              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
              • A Offline
                artmusicstudio
                last edited by 18 Oct 2013, 10:33

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

                Advertisement