I have a project of 350 odd groups.
I’m trying to find the odd group(s) that has a strange length.
I can only use instance to name the group to find the strange length.
Is there an extension to batch rename all groups instances?
Like 1,2,3,4…
Just want a quick n dirty .rd to batch rename all group instances.
Something like this?
However it is not an .rb, just a snippet.
Copy paste the code snippet below to Ruby console and hit enter:
All groups, including nested will be renamed.
You can Undo it!
No warranties! Use your own risk!
module Dezmo
module GroupRenamer
extend self
def recur_group_rename(ents)
ents.each{|e|
case e
when Sketchup::Group
@num += 1
e.make_unique
e.name = @num.to_s
recur_group_rename(e.definition.entities)
when Sketchup::ComponentInstance
if !@defs.include?(e.definition)
recur_group_rename(e.definition.entities)
@defs<<e.definition
end
end
}
end
def grouprename
model = Sketchup.active_model
ents = model.entities
@num = 0
@defs = []
model.start_operation("Rename groups to numbers", true)
recur_group_rename(ents)
model.commit_operation
"#{@num} Groups renamed"
end
end
end
Dezmo::GroupRenamer.grouprename
module Dezmo
module GroupRenamerB
extend self
def recur_group_rename(ents)
ents.each{|e|
case e
when Sketchup::Group
if e.name == ""
@num += 1
e.make_unique
e.name = @num.to_s
end
recur_group_rename(e.definition.entities)
when Sketchup::ComponentInstance
if !@defs.include?(e.definition)
recur_group_rename(e.definition.entities)
@defs<<e.definition
end
end
}
end
def grouprename
model = Sketchup.active_model
ents = model.entities
@num = 0
@defs = []
model.start_operation("Rename groups to numbers if no name", true)
recur_group_rename(ents)
model.commit_operation
"#{@num} Groups renamed"
end
end
end
Dezmo::GroupRenamerB.grouprename
You can decide how many digits will be used by the number part of the name.
The dimensions are formatted according to the Model Info unit settings.
See the animation.
Does not really tested. No warranties! Use your own risk.
module Dezmo
module GroupRenamerC
extend self
def add_zeros(name)
name = "0" + name until name.size >= @digits
name
end
def h_w_d(group)
bb = group.bounds
" H:#{bb.height.to_s} W:#{bb.width.to_s} D:#{bb.depth.to_s}"
end
def recur_group_rename(ents)
ents.each{|e|
case e
when Sketchup::Group
if e.name == ""
@num += 1
e.make_unique
e.name = add_zeros(@num.to_s) + h_w_d(e)
end
recur_group_rename(e.definition.entities)
when Sketchup::ComponentInstance
if !@defs.include?(e.definition)
recur_group_rename(e.definition.entities)
@defs<<e.definition
end
end
}
end
def grouprename(digits)
model = Sketchup.active_model
ents = model.entities
@digits = digits
@num = 0
@defs = []
model.start_operation("Rename groups to numbers + measurements if no name", true)
recur_group_rename(ents)
model.commit_operation
"#{@num} Groups renamed"
end
end
end
Dezmo::GroupRenamerC.grouprename(2)
Your previous code would rename no matter what.
This one does not.
Any chance of that again?
No prob if not.
module Dezmo
module GroupRenamer
extend self
def recur_group_rename(ents)
ents.each{|e|
case e
when Sketchup::Group
@num += 1
e.make_unique
e.name = @num.to_s
recur_group_rename(e.definition.entities)
when Sketchup::ComponentInstance
if !@defs.include?(e.definition)
recur_group_rename(e.definition.entities)
@defs<<e.definition
end
end
}
end
def grouprename
model = Sketchup.active_model
ents = model.entities
@num = 0
@defs = []
model.start_operation("Rename groups to numbers", true)
recur_group_rename(ents)
model.commit_operation
"#{@num} Groups renamed"
end
end
end
Dezmo::GroupRenamer.grouprename
Yes. Here it is.
Again. Does not really tested. No warranties! Use your own risk.
module Dezmo
module GroupRenamerD
extend self
def add_zeros(name)
name = "0" + name until name.size >= @digits
name
end
def h_w_d(group)
bb = group.bounds
" H:#{bb.height.to_s} W:#{bb.width.to_s} D:#{bb.depth.to_s}"
end
def recur_group_rename(ents)
ents.each{|e|
case e
when Sketchup::Group
#if e.name == ""
@num += 1
e.make_unique
e.name = add_zeros(@num.to_s) + h_w_d(e)
#end
recur_group_rename(e.definition.entities)
when Sketchup::ComponentInstance
if !@defs.include?(e.definition)
recur_group_rename(e.definition.entities)
@defs<<e.definition
end
end
}
end
def grouprename(digits)
model = Sketchup.active_model
ents = model.entities
@digits = digits
@num = 0
@defs = []
model.start_operation("Rename groups to numbers + measurements", true)
recur_group_rename(ents)
model.commit_operation
"#{@num} Groups renamed"
end
end
end
Dezmo::GroupRenamerD.grouprename(2)
Thank you very much, dezmo, I found something like this, I would appreciate it if you could evaluate the code, you can exist.
# add_DC_function.rb
# extends DCs functions
require('sketchup')
require('dynamiccomponents.rb')
if defined?($dc_observers)
# Open SketchUp's Dynamic Component Functions (V1) class.
# BUT only if DC extension is active...
class DCFunctionsV1
protected
# DC Function Usage: =volume()
# returns the instance's volume [cu"]
if not DCFunctionsV1.method_defined?(:volume)
def volume(a)
return @source_entity.volume
end
end
end#class
end#if