Can you explain to me how I can create those windows within this reply to show you the code and possibly the screen prints. That would allow you to have the same view as I have.
From the console this is the version of Sketchup
Sketchup.version
18.0.16975
Sketchup.version_number
1800016975
Here’s the actual code:
(Note: I use the first line to test the method from the console by first creating the variables that need to be passed.)
#SJN::MyGroupUtilities.importFile(x_file, x_sortkey)
def self.importFile(x_file, x_sortKey)
puts "FileName: #{x_file}"
UI.messagebox("FileName: #{x_file}")
UI.messagebox("SortKey : #{x_sortKey}")
objModel = Sketchup.active_model
objModel.definitions.purge_unused
puts "purged unused definitions..."
UI.messagebox("purged unused definitions...")
objImportedDef = objModel.definitions.load(x_file)
puts "Loaded selected file to definition..."
UI.messagebox("Loaded selected file to definition...")
objNewInstance = objModel.active_entities.add_instance(objImportedDef, [0,0,0])
puts "added objNewInstance #{objNewInstance.definition.name}"
UI.messagebox("added objNewInstance #{objNewInstance.definition.name}")
objSelection.add objNewInstance
puts "Selected New Instance..."
UI.messagebox("Selected New Instance...")
objWrapper = objModel.active_entities.add_group(objNewInstance).to_component
puts "Created WrapperComponent..."
UI.messagebox("Created WrapperComponent...")
objSelection.add objWrapper
puts "Selected WrapperComponent..."
UI.messagebox("Selected WrapperComponent...")
objSelection[0].explode
puts "Exploded Selected object..."
UI.messagebox("Exploded Selected object...")
objSelection.clear
objSelection.add objModel.active_entities[-1]
puts "Selected last created object instance..."
UI.messagebox("Selected last created object instance...")
objSelection[0].name = x_sortKey
puts "Applied Sort Key to Imported Component..."
UI.messagebox("Applied Sort Key to Imported Component...")
end
When I run the program here’s the response from the console.
myJSLink: htmlCmd => Exe:Import
myJSLink: htmlSource => D:/aa SJN Service Enterprise/Business Projects/aa SketchupUtilities/aa ProjectComponents/810 Lumber/03 CustomCuts/01 Ply3_4x4in/002 EndRollerInnerSupportDisc|ci.810.03.01.
myJSLink: htmlTag => *
myJSLink: calling process_jsRequests...
SJN::MyHTMLUtilities: htmlCmd = Exe:Import
SJN::MyHTMLUtilities: htmlSource = D:/aa SJN Service Enterprise/Business Projects/aa SketchupUtilities/aa ProjectComponents/810 Lumber/03 CustomCuts/01 Ply3_4x4in/002 EndRollerInnerSupportDisc|ci.810.03.01.
SJN::MyHTMLUtilities: htmlTag: *
Exe:Import: D:/aa SJN Service Enterprise/Business Projects/aa SketchupUtilities/aa ProjectComponents/810 Lumber/03 CustomCuts/01 Ply3_4x4in/002 EndRollerInnerSupportDisc|ci.810.03.01.
FileName: D:/aa SJN Service Enterprise/Business Projects/aa SketchupUtilities/aa ProjectComponents/810 Lumber/03 CustomCuts/01 Ply3_4x4in/002 EndRollerInnerSupportDisc
purged unused definitions...
Error: #<IOError: Invalid component file>
D:/aa SJN Service Enterprise/Business Projects/aa SketchupUtilities/aa ProjectScriptsLib/sjnUI_GroupUtilities.rb:163:in `load'
D:/aa SJN Service Enterprise/Business Projects/aa SketchupUtilities/aa ProjectScriptsLib/sjnUI_GroupUtilities.rb:163:in `importFile'
D:/aa SJN Service Enterprise/Business Projects/aa SketchupUtilities/aa ProjectScriptsLib/sjnUIUtils.rb:318:in `cmdExe'
D:/aa SJN Service Enterprise/Business Projects/aa SketchupUtilities/aa ProjectScriptsLib/sjnUIUtils.rb:55:in `process_jsRequests'
D:/aa SJN Service Enterprise/Business Projects/aa SketchupUtilities/aa ProjectScriptsLib/sjnUIUtils.rb:966:in `block in show_dialog'
SketchUp:1:in `call'
As you can see it fails on the .load (4th command down)
But copying and pasting the same lines of code from the method and using the console, this is the response
objModel = Sketchup.active_model
#<Sketchup::Model:0x00026f3d8f4810>
objModel.definitions.purge_unused
#<Sketchup::DefinitionList:0x00026f3d830b68>
objImportedDef = objModel.definitions.load(x_file)
#<Sketchup::ComponentDefinition:0x00026f3e209ce8>
objNewInstance = objModel.active_entities.add_instance(objImportedDef, [0,0,0])
#<Sketchup::ComponentInstance:0x00026f3e209338>
objSelection.add objNewInstance
1
objWrapper = objModel.active_entities.add_group(objNewInstance).to_component
#<Sketchup::ComponentInstance:0x00026f3e1fbeb8>
objSelection.add objWrapper
1
objSelection[0].explode
[#<Sketchup::AttributeDictionary:0x00026f3e1fb760>, #<Sketchup::ComponentInstance:0x00026f3e1fb738>, #<Sketchup::AttributeDictionaries:0x00026f3e1fb710>]
objSelection.clear
objSelection.add objModel.active_entities[-1]
1
objSelection[0].name = x_sortKey
SortKey 000
Everything goes through without a hitch. It took me a week to perfect this automated process and from the console it works perfectly. The only other option I have is to split the process into 3 sections and require the user (me) to manually use the cursor on the import and place it anywhere on the model, and then apply the sort key to component name. That becomes a 3 step process.
Thanks for you interest and response. This has been really frustrating to get so close and then have things not function properly when I can prove that the code works.
Scott.