ArchiCAD GDLを学習 〜椅子④〜

2024年8月23日金曜日

GDL if ブールパラメータ 椅子

t f B! P L

ArchiCAD GDLで椅子をつくてみる④

前回までに作成したものを、下記のコードにまとめて示します。少し長くなりますが、このような感じです。
GDLパラメータ
パラメータリスト
unid = 1
material mat

gosub "desk"

hotspot 0, 		chair_pos[2], chair_height, unid, chair_pos[1], 1+128	:unid = unid+1
hotspot chair_pos[1], 	chair_pos[2], chair_height, unid, chair_pos[1], 2	:unid = unid+1
hotspot -1, 		chair_pos[2], chair_height, unid, chair_pos[1], 3	:unid = unid+1

hotspot chair_pos[1], 	0	  , chair_height, unid, chair_pos[2], 1+128	:unid = unid+1
hotspot chair_pos[1], 	chair_pos[2], chair_height, unid, chair_pos[2], 2	:unid = unid+1
hotspot chair_pos[1], 	-1	  , chair_height, unid, chair_pos[2], 3	:unid = unid+1

add	chair_pos[1], chair_pos[2], 0

gosub "chair"

end 

"desk":
	!脚1
	block leg_size, leg_size, height - thin

	!脚2
	add width - leg_size, 0, 0
	block leg_size, leg_size, height - thin
	del 1

	!脚3
	add width - leg_size, depth - leg_size, 0
	block leg_size, leg_size, height - thin
	del 1

	!脚4
	add 0, depth - leg_size, 0
	block leg_size, leg_size, height - thin
	del 1

	!天板
	add 0, 0, height - thin
	block width, depth, thin
	del 1

	!ホットスポット
	hotspot 0, 0, 0
	hotspot width, 0, 0
	hotspot 0, depth, 0
	hotspot width, depth, 0

	!ピンクのホットスポット
	hotspot 0, 	depth/2, height, unid, width, 1+128	:unid = unid+1
	hotspot width, 	depth/2, height, unid, width, 2		:unid = unid+1
	hotspot -1, 	depth/2, height, unid, width, 3		:unid = unid+1

	hotspot width/2, 0, 	height, unid, depth, 1+128	:unid = unid+1
	hotspot width/2, depth, height, unid, depth, 2		:unid = unid+1
	hotspot width/2, -1, 	height, unid, depth, 3		:unid = unid+1

return

"chair":
	pipe_size = 0.01
	pipe_pos = chair_size/2 + 0.03
	pipe_height = chair_height - 0.03
	
	material chair_pipe_mat

	rotz 45
	gosub "chair_pipe"
	rotz 90
	gosub "chair_pipe"
	rotz 90
	gosub "chair_pipe"
	rotz 90
	gosub "chair_pipe"
	del 4


	material chair_mat
	add 0, 0, chair_height - 0.03/2
	cylind 0.03/2, chair_size/2
	del 1

	end
return

"chair_pipe":
	d = pipe_size*4

	tube 2, 4, 1+2+16+32+64,
		0, 0, 900,
		pipe_size, 360, 4000,
		pipe_pos, 0, -1, 0,
		pipe_pos, 0, 0, 0,
		pipe_pos, 0, pipe_height - d, 0,
		pipe_pos, 0, pipe_height, 0
	
	tube 2, 4, 1+2+16+32+64,
		0, 0, 900,
		pipe_size, 360, 4000,
		pipe_pos, 0, pipe_height, 0,
		pipe_pos - d, 0, pipe_height, 0,
		0, 0, pipe_height, 0,
		-1, 0, pipe_height, 0

		add pipe_pos - d, 0, pipe_height - d
		gosub "chair_pipe_corner"
		del 1
return

"chair_pipe_corner":
	div = 8
	put d, 0, -1, 0
	for i = 0 to div
		put d*cos(90*(i/div)), 0, d*sin(90*(i/div)),0
	next i
	put -1, 0 , d, 0

	tube 2, div + 3, 1+2+16+32+64,
		0, 0, 900,
		pipe_size, 360, 4000,
		get((div+3)*4)
return

ブールパラメータ

最後に、椅子の表示・非表示の切り替えを追加して、このセクションを終えたいと思います。まず、新しいパラメータを追加し、パラメータタイプをブールに設定します。今回は "dis_chair" というパラメータを作成しました。これを3Dスクリプトで if 文を用いて以下のように記述することで、表示・非表示の制御ができるようになります。
unid = 1
material mat

gosub "desk"

if dis_chair then
	hotspot 0, 	      chair_pos[2], chair_height, unid, chair_pos[1], 1+128	:unid = unid+1
	hotspot chair_pos[1], chair_pos[2], chair_height, unid, chair_pos[1], 2		:unid = unid+1
	hotspot -1, 	      chair_pos[2], chair_height, unid, chair_pos[1], 3		:unid = unid+1

	hotspot chair_pos[1], 	0	    , chair_height, unid, chair_pos[2], 1+128	:unid = unid+1
	hotspot chair_pos[1], 	chair_pos[2], chair_height, unid, chair_pos[2], 2	:unid = unid+1
	hotspot chair_pos[1], 	-1	    , chair_height, unid, chair_pos[2], 3	:unid = unid+1

	add	chair_pos[1], chair_pos[2], 0

	gosub "chair"
endif

GDLブールパラメータ
ブールタイプのパラメータ

椅子の3D形状は "chair" ラベルで定義しているため、"chair" ラベルとその上のホットスポットの部分を if 文で囲めばよいです。こうすることで、"dis_chair" パラメータのオンオフにより、表示・非表示を切り替えることが可能となります。
オブジェクトの設定画面


なお、基本的なGDLの学習はこちらの教材がおすすめです!
GDLリファレンスがgraphisoftが用意していますが、初見では理解しづらいので、
簡単にまとめられたやさしく学ぶArchiCAD GDLプログラミングという本で基礎をしっかり学びましょう!

また、ココナラでのサポートサービスも始めましたので、
ご活用いただければと思います。
1日GDL作成やArchiCAD関連の相談のります 自分でGDLを作成している方へ


【お知らせ】
Xのアカウントを作成しましたので、ぜひフォロー頂けると嬉しいです。
アカウントはこちらから⇨https://x.com/BIM_arekore

世界の建設業従事者、BIM推進者と繋がりたいです。よろしくお願いします。

検索

GDLオブジェクト

UI (4) ユニーク (1) ラベル (2) 仮囲い (6) 多角形 (3) 小ネタ (4) (7) 椅子 (4) 法規 (1) 無償DL (4) 足場 (15) 足場計画 (4)

ブログ アーカイブ

自己紹介

自分の写真
GDL作成などBIM活用のお仕事の相談お待ちしております。 #中堅ゼネコン出身 #施工管理職 #生産設計部 #BIM開発部門
ArchiCADのGDLをコスパよく作成します ArchiCADユーザーでGDL作成を外部委託されている方へ

QooQ