by Pixero » Sat May 04, 2019 4:10 pm
I need to make a dialog with three dropdown menus where the user can choose from the scenes materials and one input where the default value would be say 1000 mm. I have looked at other scripts and tried to create it but I've messed up somewhere as I haven't done my menus in the exact same way as the examples. Could someone please guide me to a working solution? Here is the Dialog part of the script: - Code: Select all
@@first_mat = nil @@second_mat = nil @@third_mat = nil @@distance = nil
model = Sketchup.active_model mats = model.materials ent = model.entities sel = model.selection matNames=[] matNstmp=[] mats.each{|m|matNstmp.push(m.display_name)} matNstmp.sort! matNames=matNames+matNstmp matList=matNames.join('|') @@first_mat = matList unless @@first_mat @@second_mat = matList unless @@second_mat @@third_mat = matList unless @@third_mat @@distance = 1000.mm unless @@distance # dialogs info = [matList] prompts = ["Material 1: ", "Material 2: ", "Material 3: ", "Distance: "] results = inputbox(prompts,["", "", "", 1000.mm], [matList, matList, matList, nil],"Settings") results = nil if results and results[0] == ""
-

Pixero
-
- Posts: 2609
- Joined: Thu May 24, 2018 12:49 pm
- Location: Halmstad, Sweden
- Name: Pixero
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by TIG » Sat May 04, 2019 4:58 pm
Use this: @@first_mat = matNames[0] unless @@first_mat @@second_mat = matNames[0] unless @@second_mat @@third_mat = matNames[0] unless @@third_mat @@distance = 1000.mm unless @@distance
Then use those in your inputbox's default values etc... prompts = ["Material 1: ", "Material 2: ", "Material 3: ", "Distance: "] defaults = [@@first_mat, @@second_mat, @@third_mat, @@distance] pops = [matList, matList, matList, ""] title = "Settings" results = inputbox(prompts, defaults, pops, title)
After a successful 'result' is returned you need to reset the remembered 'values', thus: @@first_mat, @@second_mat, @@third_mat, @@distance = results ###if results
TIG
-

TIG
- Global Moderator
-
- Posts: 19914
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2018
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by Pixero » Sat May 04, 2019 7:03 pm
Thank you!
-

Pixero
-
- Posts: 2609
- Joined: Thu May 24, 2018 12:49 pm
- Location: Halmstad, Sweden
- Name: Pixero
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by Pixero » Wed May 29, 2019 1:08 pm
And another one: See how the dropdown menu looks in the attached image. I have used drop down menus in scripts before without problem but can't find whats wrong here. - Code: Select all
@@axis = "Y" unless @@axis prompts = ["Axis: "] drops = ["X" '|' "-X" '|' "Y" '|' "-Y" '|' "Z" '|' "-Z"] title = "Settings" defaults = @@axis results = inputbox(prompts, drops, title, defaults)
settings.jpg
-

Pixero
-
- Posts: 2609
- Joined: Thu May 24, 2018 12:49 pm
- Location: Halmstad, Sweden
- Name: Pixero
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by TIG » Wed May 29, 2019 1:20 pm
It should be results = inputbox(prompts, defaults, drops, title) You have the wrong order... 'defaults' comes second in the list that is passed to the inputbox, AND it must be made as an array - so use defaults = [@@axis] assuming that @@axis is a string- e.g. "X" etc...
TIG
-

TIG
- Global Moderator
-
- Posts: 19914
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2018
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by Pixero » Wed May 29, 2019 2:45 pm
Thanks. That worked.
-

Pixero
-
- Posts: 2609
- Joined: Thu May 24, 2018 12:49 pm
- Location: Halmstad, Sweden
- Name: Pixero
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|