Created
March 3, 2012 10:31
-
-
Save Tener/1965420 to your computer and use it in GitHub Desktop.
Plugin for sketch up - with a bug!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wtyczka: "P-ytkuj" | |
# Autor: Krzysztof Skrzŕtnicki | |
# Licencja: GPLv3 | |
# Wersja: 1.2 | |
# First we pull in the standard API hooks. | |
require 'sketchup.rb' | |
# Show the Ruby Console at startup so we can | |
# see any programming errors we may make. | |
Sketchup.send_action "showRubyPanel:" | |
# Add a menu item to launch our plugin. | |
UI.menu("PlugIns").add_item("Plytkuj") { | |
plytkuj | |
} | |
@defaults = ["10","10","40","25","0.2","0.2","1","2.54","0","tak"] | |
@paramlist = ["","","","","","","","","","tak|nie"] | |
def plytkuj | |
# Get handles to our model and the Entities collection it contains. | |
model = Sketchup.active_model | |
entities = model.entities | |
currmat = current = Sketchup.active_model.materials.current | |
if (currmat.nil?) | |
currmat_name = "BRAK" | |
else | |
currmat_name = currmat.display_name | |
end | |
# zapytaj o parametry | |
prompts = ["Liczba X", "Liczba Y", "Szerokosc X", "Wysokosc Y", "Przerwa X", "Przerwa Y", "Grubosc","Podzielnik","Kat obrotu","Aplikuj aktualny material (" + currmat_name + ")"] | |
input = UI.inputbox prompts, @defaults, @paramlist, "Podaj parametry kafelkow" | |
if (not input) | |
return; | |
end | |
@defaults = input | |
podzielnik = input[7].to_f | |
count_x = input[0].to_i | |
count_y = input[1].to_i | |
size_x = input[2].to_f / podzielnik | |
size_y = input[3].to_f / podzielnik | |
gap_x = input[4].to_f / podzielnik | |
gap_y = input[5].to_f / podzielnik | |
size_z = input[6].to_f / podzielnik | |
angle = input[8].to_f | |
angle_rad = angle / 1.radians | |
apply_mat = (input[9] == "tak") && (not currmat.nil?) | |
t = Geom::Transformation.rotation [0,0,0], [0,0,1], angle_rad | |
for step_x in 0..(count_x-1) | |
for step_y in 0..(count_y-1) | |
pt1 = [0.0, step_x * (size_x+gap_x), step_y * (size_y+gap_y)] | |
pt2 = [0.0, pt1[1], pt1[2] + size_y ] | |
pt3 = [0.0, pt1[1]+size_x, pt1[2] + size_y ] | |
pt4 = [0.0, pt1[1]+size_x, pt1[2]] | |
pt1 = t * pt1 | |
pt2 = t * pt2 | |
pt3 = t * pt3 | |
pt4 = t * pt4 | |
grp = entities.add_group | |
new_face = grp.entities.add_face pt1, pt2, pt3, pt4 | |
if (apply_mat) | |
# the bug is here: | |
grp.material = currmat | |
# this works differently and doesn't cause a bug: | |
# new_face.material = currmat | |
end | |
new_face.pushpull size_z | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment