windows11で、sketchup6 その32

# 概要
windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
練習問題、やってみた。

# 練習問題
entitieテストを書け。

# 写真


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/fdf15139-e624-465d-8610-f5f37db4afaa.png)

# サンプルコード

```


require 'sketchup.rb'

def getEntitiesTest
	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
	entity1 = entities[1]
	if (entity1)
		UI.messagebox entity1
	else
		UI.messagebox "Failure"
	end
end

def addArcEntitiesTest
	centerpoint = Geom::Point3d.new
	vector = Geom::Vector3d.new 0, 0, 1
	vector2 = Geom::Vector3d.new 1, 0, 0
	vector3 = vector.normalize!
	model = Sketchup.active_model
	entities = model.active_entities
	arccurve = entities.add_arc centerpoint, vector2, vector3, 10, 15, 35
	UI.messagebox arccurve
end

def addCircleEntitiesTest
	centerpoint = Geom::Point3d.new
	vector = Geom::Vector3d.new 0, 0, 1
	vector2 = vector.normalize!
	model = Sketchup.active_model
	entities = model.active_entities
	edges = entities.add_circle centerpoint, vector2, 10
end

def addClineEntitiesTest
	model = Sketchup.active_model
	entities = model.active_entities
	point1 = Geom::Point3d.new (0, 0, 0)
	point2 = Geom::Point3d.new (20, 20, 20)
	constline = entities.add_cline point1, point2
	if (constline)
		UI.messagebox constline
	else
		UI.messagebox "Failure"
	end
end

def addCPointEntitiesTest
	model = Sketchup.active_model
	entities = model.active_entities
	point1 = Geom::Point3d.new (100, 200, 300)
	constpoint = entities.add_cpoint point1
	if (constpoint)
		UI.messagebox constpoint
	else
		UI.messagebox "Failure"
	end
end

def addEdgesEntitiesTest
	model = Sketchup.active_model
	entities = model.active_entities
	point1 = Geom::Point3d.new (0, 0, 0)
	point2 = Geom::Point3d.new (20, 20, 20)
	edges = entities.add_edges point1, point2
	if (edges)
		UI.messagebox edges
	else
		UI.messagebox "Failure"
	end
end

def addFaceEntitiesTest
	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
	if (face)
		UI.messagebox face
	else
		UI.messagebox "Failure"
	end
end

def addFacesFromMeshEntitiesTest
	model = Sketchup.active_model
	entities = model.active_entities
	mesh = Geom::PolygonMesh.new
	faces = entities.add_faces_from_mesh mesh
	if (faces)
		UI.messagebox faces
	else
		UI.messagebox "Failure"
	end
end

def addGroupEntitiesTest
	model = Sketchup.active_model
	entities = model.active_entities
	group = entities.add_group
	if (group)
		UI.Messagebox group
	else
		UI.Messagebox "Failure"
	end
end

def addImageEntitiesTest
	model = Sketchup.active_model
	path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
	pt = Geom::Point3d.new
	entities = model.active_entities
	begin
		image = entities.add_image path, pt, 300
	rescue
		UI.messagebox $!.message
	end
	if (image)
		UI.messagebox image
	else
		UI.messagebox "Failure"
	end
end

def addInstanceEntitiesTest
	point = Geom::Point3d.new 10, 20, 30
	transform = Geom::Transformation.new point
	model = Sketchup.active_model
	entities = model.active_entities
	path = Sketchup.find_support_file "BedTraditional.skp" ,"Components/Furniture/"
	definitions = model.definitions
	componentdefinition = definitions.load path
	instance = entities.add_instance componentdefinition, transform
	if (instance)
		UI.messagebox instance
	else
		UI.messagebox "Failure"
	end
end

def addLineEntitiesTest
	model = Sketchup.active_model
	entities = model.active_entities
	point1 = Geom::Point3d.new (0, 0, 0)
	point2 = Geom::Point3d.new (20, 20, 20)
	line = entities.add_line point1, point2
	if (line)
		UI.messagebox line
	else
		UI.messagebox "Failure"
	end
end

def addTextEntitiesTest
	coordinates = [10, 10, 10]
	model = Sketchup.active_model
	entities = model.entities
	point = Geom::Point3d.new coordinates
	text = entities.add_text "This is a Test", point
	if (text)
		UI.messagebox text
	else
		UI.messagebox "Failure"
	end
end

def clearEntitiesTest
	coordinates = [10, 10, 10]
	model = Sketchup.active_model
	entities = model.entities
	point = Geom::Point3d.new coordinates
	text = entities.add_text "This is a Test", point
	UI.messagebox "Clearing All"
	status = entities.clear!
	if (status)
		UI.messagebox status
	else
		UI.messagebox status
	end
end

def eachEntitiesTest
	coordinates = [10, 10, 10]
	model = Sketchup.active_model
	entities = model.entities
	point = Geom::Point3d.new coordinates
	text = entities.add_text "This is a Test", point
	entities.each { |entity| 
		UI.messagebox entity 
	}
end

def eraseEntitiesEntitiesTest
	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
	UI.messagebox entities
	entities.erase_entities entities[1]
	UI.messagebox entities
end

def lengthEntitiesTest
	coordinates = [10, 10, 10]
	model = Sketchup.active_model
	entities = model.entities
	point = Geom::Point3d.new coordinates
	text = entities.add_text "This is a Test", point
	length = entities.length
	if (length)
		UI.messagebox length
	else
		UI.messagebox "Failure"
	end
end

def modelEntitiesTest
	coordinates = [10, 10, 10]
	model = Sketchup.active_model
	entities = model.entities
	point = Geom::Point3d.new coordinates
	text = entities.add_text "This is a Test", point
	model = entities.model
	if (model)
		UI.messagebox model
	else
		UI.messagebox "Failure"
	end
end

def parentEntitiesTest
	coordinates = [10, 10, 10]
	model = Sketchup.active_model
	entities = model.entities
	point = Geom::Point3d.new coordinates
	text = entities.add_text "This is a Test", point
	parent = entities.parent
	if (parent)
		UI.messagebox parent
	else
		UI.messagebox "Failure"
	end
end

def transformEntitiesTest
	model = Sketchup.active_model
	entities = model.active_entities
	point1 = Geom::Point3d.new (0, 0, 0)
	point2 = Geom::Point3d.new (20, 20, 20)
	t = Geom::Transformation.new
	line = entities.add_line point1, point2
	begin
		status = entities.transform_entities t, line
	rescue
		UI.messagebox $!.message
	end
	if (status)
		UI.messagebox status
	else
		UI.messagebox status
	end
end





```

以上。