My code isn’t printing everything in the file & I can’t work out why. My underlying issue I am attempting to diagnose is that the code at the bottom of this file to add this function to a menu button isn’t being executed. Sketchup loads successfully & several other extensions I’ve made load successfully.
I’ve based this off of the tutorials folder, which I’ve noticed has this mute warnings function:
# Utility method to mute Ruby warnings for whatever is executed by the block.
def self.mute_warnings(&block)
old_verbose = $VERBOSE
$VERBOSE = nil
result = block.call
ensure
$VERBOSE = old_verbose
result
end
I’ve tried changing $VERBOSE to true & removing the resetting back to old_verbose but can’t get any errors.
I have this code:
p "RC3"
def self.rename_component
# SOME CODE
end
def self.Rename(path,name)
# SOME CODE
end
p "RC4"
def self.Rename_And_Reposition_Components
p "RC4.1"
# SOME CODE
end
p "RC5"
Which outputs this:
"RC3"
"RC4"
I can’t work out why neither “RC4.1” or “RC5” are being printed. Can anyone suggest what I can do to investigate what might be causing this?
For completeness, this is the entire file:
p "RC1"
# require 'sketchup.rb'
require_relative 'fileSearch.rb'
require 'csv'
p "RC2"
module BensCode
module Remake_Components
p "RC3"
def self.rename_component
# TODO- Remove the #N that appears at the end of the component name after we import it.
# Do thing
Rename(File.join(library_path,local_path),f_name)
# Then clear the model
Sketchup.active_model.entities.clear!
# And purge anything leftover
mod.definitions.purge_unused()
end
end
def self.Rename(path,name)
name = name[0..-5]
og_path = File.join(path,name)
# Somehow get the stats out of the model.
# https://forums.sketchup.com/t/can-i-get-model-info-statistics-via-the-api/246529/6
model = Sketchup.active_model
cdef_list = model.definitions
cdef = cdef_list[0]
# Get the name of the component
comp_name = cdef.name
# Compare the names of the file & the component
if comp_name == name
# If they are the same, return
p "Names are the same- skipping"
return
end
# If they aren't the same, we need to try & pick the best one.
# If the component name contains the word 'Component' or 'Group' & the file name doesn't, then use the file name.
if comp_name.downcase.include? "group" or comp_name.downcase.include? "component"
p "Keyword detected- picking file name"
new_name = name
else
# Otherwise, ask in console which to pick.
# gets doesn't work, so we use UI instead.
p "Comp name -> #{comp_name} " +"// #{name} <-File name"
response = UI.inputbox(["New component name"], [name],[comp_name+"|"+name+"|Skip"], "New component name")[0]
p response
if response == "Skip"
return
end
new_name = response
end
# Set the name component name
cdef.name = new_name
# Delete the old component
File.delete(og_path+".skp")
# Re-save the component
new_Path = File.join(path,new_name+".skp")
cdef.save_as(new_Path)
end
p "RC4"
def self.Rename_And_Reposition_Components()
p "RC4.1"
# Get a list of files in the components library
# Items in the array are of class:
# class DirTree
# attr_accessor :path, :f_name, :depth
library_path = 'C:\Users\Ben.Garcia\OneDrive - d&b solutions\Desktop\Projects\_Long Term\Sketchup Components Library Improvements\Copy_Of_Library'
files = file_search(library_path)
@new_folder = false
# p files
#
# Iterate through the files
c = 0
for x in files do
c = c + 1
local_path = x.path
f_name = x.f_name
path = File.join(library_path,local_path,f_name)
p File.join(local_path,f_name)
# Debug exit early
if local_path.include? 'BeMatrix'
break
end
if c < skip_first_n_files
next
end
p "Finished"
end
p "RC5"
p "Loaded remaking components"
unless file_loaded?(__FILE__)
$submenu_BensCode.add_item('Remake components') {
self.rename_components
}
file_loaded(__FILE__)
end
end # module Remake_Components
end # Module