Variables - issue
-
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_componentend
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 -
@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 thatpf1p
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 [][/]
-
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 -
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. -
@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
(theTOPLEVEL_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
-
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............
-
@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
Advertisement