Help Need to Rotate Hexagon 30 Degrees when it creates

Hello Everyone,

I am Writing a script to snap hexagons in six directions, so i wrote it correctly, but finally it must rotate 30 degree so someone can please help me how to automatically rotate it 30 degrees when it creates...

and also if some one can help me to create a option to pop up to add radius of the hexagon and other copies in same size and automatically scale and rotate
------------------------------------------------------------------------------

this is the script that i already wrote
------------------------------------------------------------------------------

fn Stretcher arg = 
(
addModifier arg (stretch stretch:0.0)
)
 
 
FirstDialog = newRolloutFloater "Hexa Grid Snapper" 150 280
rollout FirstRollout "Hexa Grid Snapper:"
(
    button btn_one "Create Hexagon" \
        tooltip: "Press this button to create a Hexagon" \
	on btn_one pressed do
        (
        s = cylinder radius:10  height:2.5 sides: 6 recenter:true  
        btn_one.enabled = true
        )
 
	pickbutton btn_seven "Pick Hexagon to Snap N" \
        tooltip: "Press this button to Snap N" \
        enabled:true \
        on btn_seven picked obj do
        (
 
new_obj = copy obj
        $.pos.y += 17.32
 
		        btn_seven.text = "Pick again to Snap N"
        btn_seven.enabled = true
        )
 
 
 
 
		 pickbutton btn_four "Pick Hexagon to Snap NE" \
        tooltip: "Press this button to Snap NE" \
        enabled:true \
 
    on btn_four picked obj do
        (
 
new_obj = copy obj
        $.pos.x += 15	
			 $.pos.y += 8.66
		        btn_four.text = "Pick again to Snap NE"
        btn_four.enabled = true
        )
 
 
 
 
 
    pickbutton btn_two "Pick Hexagon to Snap SE" \
        tooltip: "Press this button to Snap SE" \
        enabled:true \
 
    on btn_two picked obj do
        (
 
new_obj = copy obj
 
        $.pos.x += 15
			 $.pos.y -=8.66
 
		        btn_two.text = "Pick again to Snap SE"
        btn_two.enabled = true
        )
 
 
 
			 pickbutton btn_six "Pick Hexagon to Snap S" \
        tooltip: "Press this button to Snap S" \
        enabled:true \
        on btn_six picked obj do
        (
 
new_obj = copy obj
        $.pos.y -= 17.32
 
		        btn_six.text = "Pick again to Snap S"
        btn_six.enabled = true
        )
 
 
 
 
    pickbutton btn_three "Pick Hexagon to Snap SW" \
        tooltip: "Press this button to Snap SW" \
        enabled:true \
 
    on btn_three picked obj do
        (
 
new_obj = copy obj
        $.pos.x -= 15	
			 $.pos.y -= 8.66
		        btn_three.text = "Pick again TO Snap SW"
        btn_three.enabled = true
        )
 
 
 
 
 
 
		 pickbutton btn_five "Pick Hexagon to Snap NW" \
        tooltip: "Press this button to Snap NW" \
        enabled:true \
 
    on btn_five picked obj do
        (
 
new_obj = copy obj
        $.pos.x -= 15
			 $.pos.y += 8.66
		        btn_five.text = "Pick again to Snap NW"
        btn_five.enabled = true
        )
 
 
 
 
 
 
 
 
)
rollout SecondRollout "Close Me:"
(
    button go_away "Close"
        tooltip: "close me" \
    on go_away pressed do
        (
        closeRolloutFloater FirstDialog
        )
)
addrollout FirstRollout FirstDialog
addrollout SecondRollout FirstDialog

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
le1setreter's picture

changed little the usability of your script

maybe you wanna try this one:

rollout HGI "Hexa Grid Instancer"  width:204 height:244 (
 
 
	local baseObj
	local currentObj
 
	local cylRadius = 10
	local cylHeight = 2.5
 
 
 
 
	-- create basic object/cylinder
	fn fnCreateCyl = (
		startCyl = cylinder radius:cylRadius height:cylHeight sides:6 recenter:true
 
		currentObj = startCyl
		baseObj = startCyl
		select currentObj
	)
 
	-- rotate selection(cylinder)
	fn fnRotCyl = (
		if $ != undefined do (
			undo on (
				$.rotation.z_rotation += 30
			)
		)	
	)
 
 
	-- instance selection(cylinder) and move according to direction
	fn fnInsCyl cylDirection = (
 
		if $ != undefined do (
 
			undo on (
 
				newCyl = instance $											
				newCyl.name = uniquename (newCyl.name+"_Instance") 					
 
 
				dirN = [newCyl.pos[1],newCyl.pos[2]+(newCyl.radius/2*sqrt 3)*2,newCyl.pos[3]]
				dirNE = [newCyl.pos[1]+(newCyl.radius/2*3), newCyl.pos[2]+(newCyl.radius/2*sqrt 3), newCyl.pos[3]]
				dirSE = [newCyl.pos[1]+(newCyl.radius/2*3), newCyl.pos[2]-(newCyl.radius/2*sqrt 3), newCyl.pos[3]]
 
				dirS = [newCyl.pos[1],newCyl.pos[2]+((newCyl.radius/2*sqrt 3)*2)*-1,newCyl.pos[3]]
				dirSW = [newCyl.pos[1]-(newCyl.radius/2*3), newCyl.pos[2]-(newCyl.radius/2*sqrt 3), newCyl.pos[3]]
				dirNW = [newCyl.pos[1]-(newCyl.radius/2*3), newCyl.pos[2]+(newCyl.radius/2*sqrt 3), newCyl.pos[3]]
 
 
				case of (
 
					(cylDirection == "N"): currentDir=dirN
					(cylDirection == "NE"): currentDir=dirNE
					(cylDirection == "SE"): currentDir=dirSE
 
					(cylDirection == "S"): currentDir=dirS
					(cylDirection == "NW"): currentDir=dirNW
					(cylDirection == "SW"): currentDir=dirSW
 
				)
 
				newCyl.pos  = currentDir
				select newCyl
 
			)	
		)
	)
 
 
	spinner spnCylRadius "radius:"  pos:[18,6] width:80 height:16 range:[0.01,1000,cylRadius] type:#float tooltip:"change radius of ojects" enabled:true
	spinner spnCylHeight "height:"  pos:[120,6] width:80 height:16 range:[0.01,1000,cylHeight] type:#float tooltip:"change height of ojects" enabled:true
 
 
	button btnCreateNewCyl "Create Hexagon" tooltip: "Press this button to create a Hexagon" width:194 pos:[6,30]
 
 
 
	button btnCreateInsN "N" tooltip: "Press this button to create a Hexagon" width:30 pos:[86,68]
	button btnCreateInsNE "NE" tooltip: "Press this button to create a Hexagon" width:30 pos:[126,94]
	button btnCreateInsSE "SE" tooltip: "Press this button to create a Hexagon" width:30 pos:[126,124]
 
	button btnRotateIns "ROT" tooltip: "Press this button to create a Hexagon" width:30 pos:[86,112]
 
	button btnCreateInsS "S" tooltip: "Press this button to create a Hexagon" width:30 pos:[86,152]
	button btnCreateInsNW "NW" tooltip: "Press this button to create a Hexagon" width:30 pos:[46,94]
	button btnCreateInsSW "SW" tooltip: "Press this button to create a Hexagon" width:30 pos:[46,124]
 
 
	button btnUndo "UNDO" tooltip: "Undo last Step" width:194 pos:[6,190]
 
 
	spinner spnInsRadius "radius:"  pos:[18,220] width:80 height:16 range:[0.01,1000,cylRadius] type:#float tooltip:"change radius of ojects" enabled:false
	spinner spnInsHeight "height:"  pos:[120,220] width:80 height:16 range:[0.01,1000,cylHeight] type:#float tooltip:"change height of ojects" enabled:false
 
 
 
 
	on btnCreateNewCyl pressed do (
		fnCreateCyl()
		btnCreateNewCyl.enabled = false
		spnCylRadius.enabled = false
		spnCylHeight.enabled = false
 
		spnInsRadius.enabled = true
		spnInsHeight.enabled = true
 
	)
 
 
	on btnCreateInsN pressed do (
		fnInsCyl("N")
	)
 
	on btnCreateInsNE pressed do (
		fnInsCyl("NE")
	)
 
	on btnCreateInsSE pressed do (
		fnInsCyl("SE")
	)
 
	on btnCreateInsS pressed do (
		fnInsCyl("S")
	)
 
	on btnCreateInsNW pressed do (
		fnInsCyl("NW")
	)
 
	on btnCreateInsSW pressed do (
		fnInsCyl("SW")
	)
 
	on btnRotateIns pressed do (
		fnRotCyl()
	)
 
	on btnUNDO pressed do (
		max undo
	)
 
	on spnInsRadius changed val do (
		baseObj.radius = val
	)
 
	on spnInsHeight changed val do (
		baseObj.height = val
 
	)
 
	on spnCylRadius changed val do (
		cylRadius= val
		spnInsRadius.value = val
	)
 
	on spnCylHeight changed val do (
		cylHeight = val
		spnInsheight.value = val
	)
 
 
)	
createdialog HGI
miauu's picture

Rotate 30 deg:  on btn_one

Rotate 30 deg:

on btn_one pressed do
(
s = cylinder radius:10 height:2.5 sides: 6 recenter:true
in coordsys local (rotate s (eulerAngles 0 0 30)) -- rotate 30 deg along Z axis btn_one.enabled = true
 ) 

This is not very clear to me:

and also if some one can help me to create a option to pop up to add radius of the hexagon and other copies in same size and automatically scale and rotate

You can add spinners for radius, height, segments etc. in your rollout. The user will set the desired value and then will press the Create Hexagon button. If you want to change the radius, height, segments etc after the hexagon is created - add spinners, select your hexagon and use :

on spn_radius changed val do 
(
selection[1].radius = val
 )

or select all hexagons(or store them in array when you create them) and use

on spn_radius changed val do
(
for o in selection do o.radius = val
)
djarunagamage's picture

Please chk the image to get

Please chk the image to get the idea

so plz help me to solve it

AttachmentSize
help.jpg 113.85 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.