windows11で、sketchup6 その4

# 概要
windows11に、sketchup6を入れてみた。
rubyやってみた。

# 練習問題
Model testを書け。

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/2dde4cd4-79e5-4737-857d-6e4a899fb317.png)


# サンプルコード

```

require 'sketchup.rb'

def abortOperationTest
	model = Sketchup.active_model
	UI.messagebox "Starting Operation"
	model.start_operation "Create Box"
	UI.messagebox "Aborting Operation"
	status = model.abort_operation
	UI.messagebox status
end
def activeEntitiesTest
	width = 6
	height = 5
	depth = 4
	model = Sketchup.active_model
	entities = model.active_entities
	UI.messagebox entities
	entity = entities[0]
	if (!entity)
		UI.messagebox "No Entities in Model"
	else
		begin
			name = entity.typename
			UI.messagebox name
		rescue
			UI.messagebox $!.message
		end
	end	
	entities.add_group
	entity = entities[0]
	name = entity.typename
	UI.messagebox name
end
def activeLayerTest
	model = Sketchup.active_model
	layer = model.active_layer
	if (!layer)
		UI.messagebox "Failure: No Layers"
	else
		name = layer.name
		UI.messagebox name
	end
end
def activeLayerEqualsTest
	model = Sketchup.active_model
	layers = model.layers
	layers.add "My Layer"
	status = model.active_layer = layers[1]
	UI.messagebox status
	layer = model.active_layer
	name = layer.name
	if (name != "My Layer")
		UI.messagebox "Failure: Wrong Layer is Active"
	else
		UI.messagebox name
	end
end
def activeViewTest
	model = Sketchup.active_model
	view = model.active_view
	UI.messagebox view
	height = view.vpheight
	if (height)
		UI.messagebox height
	else
		UI.messagebox "Failure"
	end
end
def addNoteTest
	model = Sketchup.active_model
	begin
		note = model.add_note "Test Note", 0.1
	rescue
		UI.messagebox $!.message
	end
	if (note)
		UI.messagebox "Success"
		UI.messagebox note
	else
		UI.messagebox "Failure"
		UI.messagebox note
	end
end
def attributeDictionariesTest
	model = Sketchup.active_model
	create = true
	begin
		attdict = model.attribute_dictionary "My Dictionary" "true"
	rescue
		UI.messagebox $!.message
	end
	if (attdict)
		attdicts = model.attribute_dictionaries
		name = attdicts[0]
		UI.messagebox name
	else
		UI.messagebox "Failure: No Dictionaries"
	end
end
def attributeDictionaryTest
	model = Sketchup.active_model
	attdict = model.attribute_dictionary "My Dictionary" "true"
	if (attdict)
		attdicts = model.attribute_dictionaries
		name = attdicts[0]
		UI.messagebox name
	else
		UI.messagebox "Failure: No Dictionaries"
	end
end
def boundsTest
	model = Sketchup.active_model
	boundingBox = model.bounds
	if (boundingBox)
		length = boundingBox.diagonal
		UI.messagebox "Success."
		UI.messagebox length
	else
		UI.messagebox "Failure: No Bounding Box in Model"
	end
end
def commitOperationTest
	model = Sketchup.active_model
	model.start_operation "Create Box"
	model.commit_operation
end
def definitionsTest
	model = Sketchup.active_model
	definitions = model.definitions
	if (definitions)
		length = definitions.length
		UI.messagebox "Success."
		UI.messagebox length
	else
		UI.messagebox "Failure: No Component Definitions"
	end
end
def descriptionTest
	model = Sketchup.active_model
	description = model.description
	if (description)
		UI.messagebox description
	else
		UI.messagebox "Failure: No Description"
	end
end
def descriptionEqualsTest
	model = Sketchup.active_model
	description = model.description
	UI.messagebox description
	description = model.description
	if (description)
		UI.messagebox description
	else
		UI.messagebox "Failure: No Description"
	end
end
def entitiesTest
	model = Sketchup.active_model
	begin
		entities = model.entities
	rescue
		UI.messagebox $!.message
	end
	if (entities)
		UI.messagebox entities
		entity = entities[0]
		name = entity.typename
		UI.messagebox name
	else
		UI.messagebox "Failure: No Entities"
	end
end
def getAttributeTest
	model = Sketchup.active_model
	attrdict = model.attribute_dictionary "My Dictionary" "true"
	status = attrdict[mykey] = 7
	attr = attrdict.get_attribute "My Dictionary" "mykey"
	if (attr)
		UI.messagebox attr
	else
		UI.messagebox "Failure: no attribute"
	end
end
def getDatumTest
	model = Sketchup.active_model
	datum = model.get_datum
	if (datum)
		UI.messagebox datum
	else
		UI.messagebox "Failure: No Datums"
	end
end
def guidTest
	model = Sketchup.active_model
	guid = model.guid
	if (guid)
		UI.messagebox guid
	else
		UI.messagebox "Failure: No Global Unique Identifier"
	end
end
def latlongToPointTest
	latitude = [40.01700, 105.28300]
	model = Sketchup.active_model
	begin
		latlong = Geom::LatLong.new(latitude)
	rescue
		UI.messagebox $!.message
	end
	point = model.latlong_to_point(latlong)
	if (point)
		pointvalue = point.inspect
		UI.messagebox pointvalue
	else
		UI.messagebox "Failure"
	end
end
def layersTest
	model = Sketchup.active_model
	layers = model.layers
	length = layers.length
	if (length)
		UI.messagebox length
	else
		UI.messagebox "Failure: No Layers"
	end
end
def listDatumsTest
	model = Sketchup.active_model
	datums = model.list_datums
	if (datums)
		UI.messagebox datums
	else
		UI.messagebox "Failure: No Datums"
	end
end
def materialsTest
	model = Sketchup.active_model
	materials = model.materials
	if (materials)
		count = materials.count
		UI.messagebox count
	else
		UI.messagebox "Failure"
	end
end
def modifiedTest
	model = Sketchup.active_model
	entities = model.active_entities
	entities.add_group
	result = model.modified?
	if (result)
		UI.messagebox "Success: Time to Save"
	else
		UI.messagebox "Failure: No Changes to Save"
	end
end
def optionsTest
	model = Sketchup.active_model
	options = model.options
	if (options)
		size = options.size
		UI.messagebox size
		x = 0
		for option in options
			option = options[x]
			name = option.name
			UI.messagebox name
			x = x + 1
		end
	else
		UI.messagebox "Failure"
	end
end
def pagesTest
	model = Sketchup.active_model
	pages = model.pages
	UI.messagebox pages
	size = pages.size
	if (size)
		UI.messagebox size
		page = pages.add
		UI.messagebox page
		UI.messagebox "Lets add a page"
		size = pages.size
		UI.messagebox size
	else
		UI.messsagebox "Failure"
	end
end
def pathTest
	model = Sketchup.active_model
	path = model.path
	if (path)
		UI.messagebox path
	else
		UI.messagebox "Failure"
	end
end
def pointToLatlongTest
	coordinates = [10, 10, 10]
	model = Sketchup.active_model
	begin
		point = Geom::Point3d.new(coordinates)
	rescue
		UI.messagebox $!.message
	end
	latlong = model.point_to_latlong(point)
	if (latlong)
		latlongvalue = latlong.to_s
		UI.messagebox latlongvalue
	else
		UI.messagebox "Failure"
	end
end
def pointToUTMTest
	coordinates = [10, 10, 10]
	model = Sketchup.active_model
	begin
		point = Geom::Point3d.new(coordinates)
	rescue
		UI.messagebox $!.message
	end
	utm = model.point_to_utm(point)
	if (utm)
		utmvalue = utm.to_s
		UI.messagebox utmvalue
	else
		UI.messagebox "Failure"
	end
end
def renderingOptionsTest
	model = Sketchup.active_model
	begin
		renderingoptions = model.rendering_options
	rescue
		UI.messagebox $!.message
	end
	if (renderingoptions)
		option = renderingoptions[0]
		UI.messagebox option
	else
		UI.messagebox "Failure"
	end
end
def saveThumbnailTest
	depth = 100
	width = 100
	model = Sketchup.active_model
	entities = model.active_entities
	pts = []
	pts[0] = [0, 0, 0]
	pts[1] = [width, 0, 0]
	pts[2] = [width, depth, 0]
	pts[3] = [0, depth, 0]
	face = entities.add_face pts
	status = model.save_thumbnail "testthumbnail2.jpg"
	UI.messagebox status
end
def saveTest
	model = Sketchup.active_model
	status = model.save "test.skp"
	if (status)
		UI.messagebox "Success"
		UI.messagebox status
	else
		UI.messagebox "Failure"
	end
end
def selectToolTest
	model = Sketchup.active_model
	begin
		tool = model.select_tool nil
	rescue
		UI.messagebox $!.message
	end
	if (tool)
		UI.messagebox "Success"
		UI.messagebox tool
	else
		UI.messagebox "Failure"
	end
end
def selectionTest
	model = Sketchup.active_model
	selection = model.selection
	if (selection)
		count = selection.count
		UI.messagebox count
	else
		UI.messagebox "Failure"
	end
end
def setAttributeTest
	model = Sketchup.active_model
	value = model.set_attribute "testictionary", "test", 115
	if (value)
		UI.messagebox value
	else
		UI.messagebox "Failure"
	end
end
def setDatumTest
	model = Sketchup.active_model
	value = model.set_datum "Adindan"
	if (value)
		UI.messagebox value
		value = model.get_datum
		UI.messagebox value
		value = model.set_datum "WGS 84"
	else
		UI.messagebox "Failure"
	end
end
def shadowInfoTest
	model = Sketchup.active_model
	shadowinfo = model.shadow_info
	if (shadowinfo)
		UI.messagebox "Success"
	else
		UI.messagebox "Failure"
	end
end
def startOperationTest
	model = Sketchup.active_model
	model.start_operation "Create Box"
end
def titleTest
	model = Sketchup.active_model
	title = model.title
	if (title)
		UI.messagebox title
	else
		UI.messagebox "Failure"
	end
end
def utmToPointTest
	point = [10, 10, 10]
	model = Sketchup.active_model
	begin
		point = Geom::Point3d.new(point)
	rescue
		UI.messagebox $!.message
	end
	utm = model.point_to_utm point
	UI.messagebox utm
	point = model.utm_to_point utm
	if (point)
		pointvalue = point.to_s
		UI.messagebox pointvalue
	else
		UI.messagebox "Failure"
	end
end
def validTest
	model = Sketchup.active_model
	valid = model.valid?
	if (valid)
		UI.messagebox valid
	else
		UI.messagebox "Failure"
	end
end

def modeltest
	puts "abortOperationTest"
	puts "activeEntitiesTest"
	puts "activeLayerTest"
	puts "activeLayerEqualsTest"
	puts "activeViewTest"
	puts "addNoteTest"
	puts "attributeDictionariesTest"
	puts "attributeDictionaryTest"
	puts "boundsTest"
	puts "commitOperationTest"
	puts "definitionsTest"
	puts "descriptionTest"
	puts "descriptionEqualsTest"
	puts "entitiesTest"
	puts "getAttributeTest"
	puts "getDatumTest"
	puts "guidTest"
	puts "latlongToPointTest"
	puts "layersTest"
	puts "listDatumsTest"
	puts "materialsTest"
	puts "modifiedTest"
	puts "optionsTest"
	puts "pagesTest"
	puts "pathTest"
	puts "pointToLatlongTest"
	puts "pointToUTMTest"
	puts "renderingOptionsTest"
	puts "saveTest"
	puts "saveThumbnailTest"
	puts "selectToolTest"
	puts "selectionTest"
	puts "setAttributeTest"
	puts "setDatumTest"
	puts "shadowInfoTest"
	puts "startOperationTest"
	puts "titleTest"
	puts "utmToPointTest"
	puts "validTest"
end




```

以上。