dialog.add_action_callback("Oke") { |action_context, param1|
data=param1
#>tujuan tuk modif objek
array_beda = []
array_ganti = []
if data! = $konten_awal
data.each_index{|index|
if data[index] != $konten_awal[index];
array_beda << $konten_awal[index]
array_ganti << data[index]
end
}
end
array_beda.each_index{|index|
nama = array_beda[index]
item = array_ganti[index]
konten = item.split "|"
if konten[0] == "pondasi"
group_definitions = Sketchup.active_model.definitions.find_all{|e| e.group? }
groups = []; group_definitions.each {|e| groups.concat(e.instances) }
array1 = groups.find_all{|e|e.attribute_dictionary ('sklik_rab')}
array = array1.find_all{|e|(e.attribute_dictionary ('sklik_rab')).keys[0] == nama}
#Buat Pondasi Baru..............................................
lx_kolom = konten[9]; ly_kolom = konten[10]; p_kolom = konten[11]
kolom = [lx_kolom,ly_kolom,p_kolom]
lx_tapak = konten[1]; ly_tapak = konten[2]; h1_tapak = konten[3]; h2_tapak = konten[4]
tapak = [lx_tapak,ly_tapak,h1_tapak,h2_tapak]
spasi_lantai = konten[18]; h_lantai = konten[16]
lantai = [spasi_lantai,h_lantai]
h_pasir = konten[17]
pasir = [h_pasir]
status = konten[19]
if status == "pakai"
jml_ceru = konten[20]
p_ceru = konten[21]
dia_ceru = konten[22]
else
jml_ceru = 0
p_ceru = 0
dia_ceru = 0
end
cerucuk = [dia_ceru, p_ceru, jml_ceru]
nama = array_ganti[index]
array.each{|grp|
Sketchup.active_model.start_operation('Modify Property', true)#??????????????????????????????????????????????????????????????????????????????
#Buat Group sebelum delete konten, agar tak error
ents = grp.entities
grop_bantu = ents.add_group;
face = grop_bantu.entities.add_face [0,0,0], [6,0,0], [6,8,0], [0,8,0]
# Kosongkan Group
entities = grp.entities
entities.each { | entity| entities.erase_entities entity }
# Update Isi Group
container = grp.entities
posisi = [0,0,0]
buat_pondasi_tapak container, posisi, kolom, tapak, lantai, pasir, cerucuk, nama
grp.explode
}
end
}
Sketchup.active_model.commit_operation#?????????????????????????????????????????????????????????????????????????????????????????????????????????????
model.set_attribute("ahmadyani", "data_list_html", data)
view = Sketchup.active_model.active_view
view.refresh
$konten_awal=nil
dialog.close
}
(1) Do NOT use global variables !
(2) [How to] Post correctly formatted and colorized code on the forum?
(3) Use 2 space indentation, not tabs.
(4) Use a space before and after operators.
(5) Ruby is an English programming language and this forum is an English forum.
If you use English comments within your code, we can better understand what the code is trying to do.
(6) The API asks you to use view.invalidate
, not view.refresh
.
(7) There is a method call buat_pondasi_tapak()
that we do not know what it does.
(8) The following is a very poor coding pattern:
entities.each { |entity| entities.erase_entities entity }
… when you can use …
entities.erase_entities(entities.to_a)
… or even simply …
entities.clear!
point (1) why??
point (2) ok
point (3) ok
point (4) ok
point (5) ok
point (6) glad to know it
point (7) that is from other module, to remake entities group
point (8) glad to know it
point (9) my problem is Sketchup.active_model.start_operation(‘Modify Property’, true) and Sketchup.active_model.commit_operation. it make sketchup crash
(a) Because SketchUp’s environment is a shared space with many other extensions.
(b) Because you do not need them as all of your code must be within an extension submodule (which must be within your unique namespace module.) So use either a @@module_var
or an @instance_var
.
You also have the option of subclassing the UI::HtmlDialog
class and adding some custom @instance_vars
to your subclass. You can set the values using setter methods or override the constructor to take extra arguments.
Thank you @DanRathbun very clearly…thank you so much
You have …
Sketchup.active_model.start_operation('Modify Property', true)
inside a loop (so it starts a new operation each iteration.)
The model.commit_operation
call is outside of that loop.
Still Crash…
dialog.add_action_callback("Oke") { |action_context, param1|
data=param1
#>tujuan tuk modif objek
array_beda = []
array_ganti = []
if data! = $konten_awal
data.each_index{|index|
if data[index] != $konten_awal[index];
array_beda << $konten_awal[index]
array_ganti << data[index]
end
}
end
Sketchup.active_model.start_operation('Modify Property', true)#??????????????????????????????????????????????????????????????????????????????
array_beda.each_index{|index|
nama = array_beda[index]
item = array_ganti[index]
konten = item.split "|"
if konten[0] == "pondasi"
group_definitions = Sketchup.active_model.definitions.find_all{|e| e.group? }
groups = []; group_definitions.each {|e| groups.concat(e.instances) }
array1 = groups.find_all{|e|e.attribute_dictionary ('sklik_rab')}
array = array1.find_all{|e|(e.attribute_dictionary ('sklik_rab')).keys[0] == nama}
#Buat Pondasi Baru..............................................
lx_kolom = konten[9]; ly_kolom = konten[10]; p_kolom = konten[11]
kolom = [lx_kolom,ly_kolom,p_kolom]
lx_tapak = konten[1]; ly_tapak = konten[2]; h1_tapak = konten[3]; h2_tapak = konten[4]
tapak = [lx_tapak,ly_tapak,h1_tapak,h2_tapak]
spasi_lantai = konten[18]; h_lantai = konten[16]
lantai = [spasi_lantai,h_lantai]
h_pasir = konten[17]
pasir = [h_pasir]
status = konten[19]
if status == "pakai"
jml_ceru = konten[20]
p_ceru = konten[21]
dia_ceru = konten[22]
else
jml_ceru = 0
p_ceru = 0
dia_ceru = 0
end
cerucuk = [dia_ceru, p_ceru, jml_ceru]
nama = array_ganti[index]
array.each{|grp|
#Buat Group sebelum delete konten, agar tak error
ents = grp.entities
grop_bantu = ents.add_group;
face = grop_bantu.entities.add_face [0,0,0], [6,0,0], [6,8,0], [0,8,0]
# Kosongkan Group
entities = grp.entities
entities.each { | entity| entities.erase_entities entity }
# Update Isi Group
container = grp.entities
posisi = [0,0,0]
buat_pondasi_tapak container, posisi, kolom, tapak, lantai, pasir, cerucuk, nama
grp.explode
}
end
}
Sketchup.active_model.commit_operation#?????????????????????????????????????????????????????????????????????????????????????????????????????????????
model.set_attribute("ahmadyani", "data_list_html", data)
view = Sketchup.active_model.active_view
view.refresh
$konten_awal=nil
dialog.close
}
I do not fully understand. You have searched for groups that have the corresponding attribute.
Then you are adding an inner group to each group, and then create a face in the inner group. Then you are erasing all the entities of that group (including a just added inside group with face).
Then, you are referring to that entities what have been previously erased.
Then, you are doing some secret method using the referred container, then you are exploding that container.
So, the code is somewhat chaotic, not easy to follow what you want to achieve.
Besade that, as Dan mentioned the syntax is not usaul, and the format make more complicated to read. E.g.: I really do not understand why do you need 79 quiestion marks in one row?
hai master @dezmo …thank you for your respond.
may be this can explain what i want
module Ahmadyani
def self.buat_atribute
# Create the group and set attributes
ents = Sketchup.active_model.entities
car_group = ents.add_group
main_face = car_group.entities.add_face [-0.5.m,-0.5.m,0], [0.5.m,-0.5.m,0], [0.5.m,0.5.m,0], [-0.5.m,0.5.m,0]
main_face.reverse!
main_face.pushpull 5
car_group.set_attribute "sklik_rab", "group_key_one", "pondasi"
ents = Sketchup.active_model.entities
car_group = ents.add_group
main_face = car_group.entities.add_face [0,0,0], [6,0,0], [6,8,0], [0,8,0]
main_face.reverse!
main_face.pushpull 10
car_group.set_attribute "sklik_rab", "group_key_two", "pondasi"
end
def self.ubah_atribute
#get attributes and Change entities
group = Sketchup.active_model.entities.grep(Sketchup::Group)
group = Sketchup.active_model.entities.grep(Sketchup::Group).find_all{|e|
e.attribute_dictionary ('sklik_rab')
}
group = group.find_all{|e|
(e.attribute_dictionary ('sklik_rab')).keys[0]=="group_key_two"
}
group.each {|e|
#Cretate something before erase entities, so that there are no error
ents = e.entities
grop_bantu = ents.add_group
face = grop_bantu.entities.add_face [0,0,0], [6,0,0], [6,8,0], [0,8,0]
# Empty the entities Group
entities = e.entities
entities.clear!
# Update New Entities to Group
main_face = e.entities.add_face [0,0,0], [6,0,0], [6,10,0], [0,10,0]
main_face.reverse!
main_face.pushpull 50
}
end
unless file_loaded?(__FILE__)
toolbar=UI::Toolbar.new "Sklik_RAB"
cmd=UI::Command.new ("buat atribute"){self.buat_atribute}
cmd.tooltip=("buat atribute")
cmd.status_bar_text = ("Create Group dan Set Atribute")
toolbar.add_item cmd
cmd=UI::Command.new ("ubah atribute"){self.ubah_atribute}
cmd.tooltip=("ubah atribute")
cmd.status_bar_text = ("Select Group dengan Atibutenya")
toolbar.add_item cmd
toolbar.add_separator
end
end #module
if we don’t do this, After we create group then copy the group with move tool…we get error when click “ubah atribute”
#Cretate something before erase entities, so that there are no error
ents = e.entities
grop_bantu = ents.add_group
face = grop_bantu.entities.add_face [0,0,0], [6,0,0], [6,8,0], [0,8,0]
in my cultur 79 quiestion that is mean BIG QUESTION. sorry about that. again sorry about that