Add dimensions


#1

Hi All,

I am able to add dimensions for height (x, z) and length (x, y), please check the image file and code,

for height:

def get_height
selection = Sketchup.active_model.selection
count = selection.length
if count != 0
#@arr_height = []
selection.each { |sel|
origin = sel.transformation.origin
x = origin[0]
y = origin[1]
z = origin[2]
if sel.class == Sketchup::Group
box = sel.local_bounds
elsif sel.class == Sketchup::ComponentInstance
box = sel.definition.bounds
end
mix = box.min.x.to_f
miy = 0
miz = box.min.z.to_f

		mx = box.max.x.to_f
		my = 0
		mz = box.max.z.to_f

		name = sel.definition.name
		#defn = sel.definition
		#bbox = defn.bounds
		#w = bbox.width.to_l.to_s
		#h = bbox.height.to_l.to_s
		#d = bbox.depth.to_f
		puts mix, miy, miz, mx, my, mz
		if name != "BASE HANDLE#1"
			#if !@arr_height.include?(mz)
				#@arr_height.push(mz)
				dim = sel.entities.add_dimension_linear([mix, miy, miz], [mx, my, mz], [25, 0, 0])
				dim.material = "aqua"
			#end
		end
	}
else
	UI.messagebox "No models are selected!", MB_OK
end

end

for length:
def get_length
selection = Sketchup.active_model.selection
count = selection.length
if count != 0
#@arr_length = []
selection.each { |sel|
origin = sel.transformation.origin
x = origin[0]
y = origin[1]
z = origin[2]
if sel.class == Sketchup::Group
box = sel.local_bounds
elsif sel.class == Sketchup::ComponentInstance
box = sel.definition.bounds
end
mix = box.min.x.to_f
miy = box.min.y.to_f
miz = 0

		mx = box.max.x.to_f
		my = box.max.y.to_f
		mz = 0

		name = sel.definition.name
		#defn = sel.definition
		#bbox = defn.bounds
		#w = bbox.width.to_l.to_s
		#h = bbox.height.to_l.to_s
		#d = bbox.depth.to_l.to_s
		#puts mix, miy, miz, mx, my, mz
		#puts "-------------------------------------------------"
		if name != "BASE HANDLE#1"
			#if !@arr_length.include?(my)
				#@arr_length.push(my)
				dim = sel.entities.add_dimension_linear([mix, miy, miz], [mx, my, mz], [25, 0, 0])
				dim.material = "chartreuse"
			#end
		end
	}
	#puts "---asa",@arr_length.to_a
else
	UI.messagebox "No models are selected!", MB_OK
end

end

Any idea for adding the dimension for another angle, Please check the image

Output:

Which I marked the dimensions?


#2