here is the Grist vs Original (what i actually pasted into Grist)
I want to be able to copy the text directly to use in a coding console. how would i remove the extra quotes?
here is the Grist vs Original (what i actually pasted into Grist)
I want to be able to copy the text directly to use in a coding console. how would i remove the extra quotes?
Turns out the custom widget “Copy to Clipboard” does copy the exact text and gives me a button to do so, which is nice but it takes up so much space. I’d call this a solution but it would be nicer to have a small button without the text window.
new issue: the next step is to use the value of my column named “Path” to substitute in the script. When i do so my resulting text seems to have leading spaces: (4 spaces on each line)
# Check if SketchUp is running
unless defined? Sketchup
require 'sketchup.rb'
end
# Define the path to the component file (SKP file)
component_file_path = 'G:\My Drive\Sketchup\##COMPONENTS\Library-Sconce1.skp'
# Check if the file exists
unless File.exist?(component_file_path)
puts "Component file not found: \#G:\My Drive\Sketchup\##COMPONENTS\Library-Sconce1.skp"
UI.messagebox("Component file not found: \#G:\My Drive\Sketchup\##COMPONENTS\Library-Sconce1.skp")
return
end
# Open the component file
model = Sketchup.active_model
component_definition = model.definitions.load(component_file_path)
# Check if the component was loaded successfully
unless component_definition
puts "Failed to load the component: \#G:\My Drive\Sketchup\##COMPONENTS\Library-Sconce1.skp"
UI.messagebox("Failed to load the component: \#G:\My Drive\Sketchup\##COMPONENTS\Library-Sconce1.skp")
return
end
# Create an instance of the component in the model
instance = model.entities.add_instance(component_definition, Geom::Transformation.new)
# Select the imported component (optional)
model.selection.add(instance)
# Zoom to the imported component (optional)
model.active_view.zoom(instance)
# Display a success message
puts "Component imported successfully: \#G:\My Drive\Sketchup\##COMPONENTS\Library-Sconce1.skp"
UI.messagebox("Component imported successfully: \#G:\My Drive\Sketchup\##COMPONENTS\Library-Sconce1.skp")
which i believe is causing an issue running in Ruby.
here is the function im using to generate the variable substitution:
# Define the component file path as a variable
component_file_path = $Path
ruby_script = f"""\
# Check if SketchUp is running
unless defined? Sketchup
require 'sketchup.rb'
end
# Define the path to the component file (SKP file)
component_file_path = '{component_file_path}'
# Check if the file exists
unless File.exist?(component_file_path)
puts "Component file not found: \#{component_file_path}"
UI.messagebox("Component file not found: \#{component_file_path}")
return
end
# Open the component file
model = Sketchup.active_model
component_definition = model.definitions.load(component_file_path)
# Check if the component was loaded successfully
unless component_definition
puts "Failed to load the component: \#{component_file_path}"
UI.messagebox("Failed to load the component: \#{component_file_path}")
return
end
# Create an instance of the component in the model
instance = model.entities.add_instance(component_definition, Geom::Transformation.new)
# Select the imported component (optional)
model.selection.add(instance)
# Zoom to the imported component (optional)
model.active_view.zoom(instance)
# Display a success message
puts "Component imported successfully: \#{component_file_path}"
UI.messagebox("Component imported successfully: \#{component_file_path}")
"""
ruby_script
any ideas?
For the 4-spaces problem, I’ve used this workaround:
import textwrap
ruby_script = textwrap.dedent(f"""\
...
""")
return ruby_script
Awesome, thanks so much.
So, do you know why its adding these spaces? if i copy the code and paste it into a python ide i dont get those spaces. Has this been submitted as a bug?
If you look at the “Code View” page (in the left panel, described here), you’ll see how each formula gets indented to be turned into the body of a Python method. For multiline strings, that indentation is kind of wrong.
It might be fixable, so feel free to submit as a bug report: Issues · gristlabs/grist-core · GitHub is probably the best place for it.