I checked the link you gave me … the documentation is slanted toward webservers which I find misleading and requires me to first download the Microsoft Web Platform Installer … however, in only a few minutes, I was able to download one of the binaries from “PHP For Windows: Binaries and sources Releases” and edit the system PATH and PATHEXT variables to get the CLI to work. Not terribly difficult to do, but it seems like a lot of work to add an import function to SketchUp. Normally, I advise against potentially invasive installs on a workstation to accomplish a single task (as a work-around, in this case). However, that said, the files are only about 42MB in size, require no registry edits, and now gives me a way to run PHP on my computer if I should ever need to do so. It’s a lot less invasive than installing Perl on my computer
I like this approach much better than having to install PHP to create the PNG files and zip them. Once again, @john_drivenupthewall, you’ve gone way over the top
When I get back from vacation next year, I’ll add your code to my computer. My little netbook for-the-road only has SketchUp 8 so I can’t do it on here (but now it has PHP when I need it).
@john_drivenupthewall - it worked great John! the only issue was Sketchup got very cranky and unstable loading all 4000+ colors. I ended up separating the materials libraries into smaller chunks (1500 per library) and that made everyone happy. Thanks again for your help - it’s safe to say I wouldn’t have made the deadline without it
I used the php version. The unstable part was after restarting with loading 4000 materials folder. I used SU 2015 since 2016 had warnings about backwards compatibility so I’m not sure if it would’ve worked better with 2016.
@john_drivenupthewall Hi! You were so kind as to create the awesome PHP script in this thread for me back at the end of 2015. I have to perform the same task again and have completely forgotten how to use the PHP script. Would it be possible for you to refresh my memory? ~ lori
version = Sketchup.version.to_i
osx = Sketchup.platform == :platform_osx
# select a colour list
file = UI.openpanel(
'Select CSV File',
osx ? '~' : ENV['HOME'],
osx ? '*.csv' : 'CSV Files|*.csv||'
)
if version >= 17
# extract folder name
dir = File.basename(file, '.csv')
# create array of name and hex value
require 'csv.rb'
csv_data = CSV.foreach(file, headers: true).map do |row|
h = row.to_h
n = h['Name'].split(' ').map(&:capitalize).join(' ').rstrip
c = [ h['R'].to_i, h['G'].to_i, h['B'].to_i ]
[n,c]
end
#create new material
# Get a handle to all the materials in the current model.
model = Sketchup.active_model
mats = model.materials
path = Sketchup.find_support_file('Materials')
main = File.join(path, dir)
Dir.mkdir(main) unless Dir.exist?(main)
# process data
mats.purge_unused
@mat = mats.add('placeholder')
csv_data.each do |name,colour|
filename = File.join(main, name + '.skm')
@mat.name = name
@mat.color = Sketchup::Color.new(colour.entries)
@mat.save_as(filename)
end
end
I’ll update the code as I normally do similar to Dan’s suggestion for UI.openpanel…
the reference was there for some mac SU version testing…
totally useless on a windows PC…
if osx & (version != 20)
%x[
osascript -e 'tell application "System Events" to key code 124 using control down'
sleep 1
osascript -e 'tell application "System Events" to key code 123 using control down'
]
end