0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

windows11で、sketchup6 その88

Posted at

概要

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

練習問題

線を引く、ツールを書け。

写真

image.png

サンプルコード

起動 Sketchup.active_model.select_tool LineTool.new



require 'sketchup.rb'



class LineTool
	CURSOR_PENCIL = 632
	def activate
		@mouse_ip = Sketchup::InputPoint.new
		@picked_first_ip = Sketchup::InputPoint.new
		update_ui
	end

	def deactivate(view)
		view.invalidate
	end

	def resume(view)
		update_ui
		view.invalidate
	end

	def suspend(view)
		view.invalidate
	end

	def onCancel(reason, view)
		reset_tool
		view.invalidate
	end

	def onMouseMove(flags, x, y, view)
		if picked_first_point?
			@mouse_ip.pick(view, x, y, @picked_first_ip)
		else
			@mouse_ip.pick(view, x, y)
		end
		view.tooltip = @mouse_ip.tooltip if @mouse_ip.valid?
		view.invalidate
	end

	def onLButtonDown(flags, x, y, view)
		if picked_first_point? && create_edge > 0
			reset_tool
		else
			@picked_first_ip.copy!(@mouse_ip)
		end
		update_ui
		view.invalidate
	end

	def onSetCursor
		UI.set_cursor(CURSOR_PENCIL)
	end

	def draw(view)
		draw_preview(view)
		@mouse_ip.draw(view) if @mouse_ip.display?
	end

	def getExtents
		bounds = Geom::BoundingBox.new
		bounds.add(picked_points)
		bounds
	end

	private

	def update_ui
		if picked_first_point?
			Sketchup.status_text = 'Select end point.'
		else
			Sketchup.status_text = 'Select start point.'
		end
	end

	def reset_tool
		@picked_first_ip.clear
		update_ui
	end

	def picked_first_point?
		@picked_first_ip.valid?
	end

	def picked_points
		points = []
		points << @picked_first_ip.position if picked_first_point?
		points << @mouse_ip.position if @mouse_ip.valid?
		points
	end

	def draw_preview(view)
		points = picked_points
		return unless points.size == 2
		view.set_color_from_line(*points)
		view.line_width = 1
		view.line_stipple = ''
		view.draw(GL_LINES, points)
	end

	def create_edge
		model = Sketchup.active_model
		#model.start_operation('Edge', true)
		edge = model.active_entities.add_line(picked_points)
		num_faces = edge.find_faces || 0
		#model.commit_operation
		num_faces
	end
end





以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?