ScriptSpot home

Forum topic · General Scripting

script doesn't work properly on the first try

By luiz henrique de camargo · 2013-07-11

Downloads
Description

im new to scripting, this is my first script for 3dsmax.
and i keep having this problem, everytime that i close and reopen the 3dsMax and reload the script doesn't work on the first try he create a stretch object, if i keep pushing the button he start to create the object properly.

the script is attach to the post.

any ideas of what im doing wrong?

Comments (4)
luiz henrique de camargo

now its working perfect, ty all for the help :D

miauu

Branko, your code still produces streched popcorns. :)
The problems is in ScaleSelected operations. Replace it with this and everything will be fine:

[code
cornMod.SetOperation #Transform
cornMod.ScaleSelection [1.5031,1.5031,1.5031] parent:(transMatrix corn.pos) axis:(transMatrix corn.pos)

[/code]

Reply to miauu
Branko Živković

Thanks Kostadin
Streching is not only problem here but also face-overlaping
I corrected below code as you suggested.

Branko Živković

try this one
I added random position to each popcorn to produce differend form

try(destroyDialog ::popcorn_button)catch()
rollout popcorn_button "Popcorn"
(
button btn_one "Popcorn"
tooltip: "Press this button to create a popcorn" \
spinner count "Number"type:#integer range:[1,100,1]
checkbox ckbx1 "low poly" checked:false

on btn_one pressed do
(
-- material
local m1 = standardmaterial diffuse:(color 255 132 0) specularLevel:100 glossiness:50 name:"popcorn_yellow"
local m2 = standardmaterial diffuse:(color 255 255 255) name:"popcorn_white"
local mm = multimaterial numsubs:2 name:"popcorn_material" materialList:#(m1,m2)
messagebox"Wait, while the script work."
for i=1 to count.value do
(
-- geosphere
corn = GeoSphere pos:[random -10 10,random -10 10,random -10 10] radius:(random 3 4) name:(uniquename "Popcorn") material:mm isSelected:on
cornMod = Edit_Poly name:"PopcornDeform"
addmodifier corn cornMod ui:on
max modify mode ; subobjectLevel = 4
cornMod.SetSelection #Face #{1..(corn.numfaces)}
PolyToolsTopology.tatter 2 1 1
-- extrude
cornMod.SetOperation #ExtrudeFace
cornMod.extrudeFaceHeight = random 1 2
cornMod.Commit()
-- tessellate
cornMod.SetOperation #Tessellate
cornMod.tessellateByFace = 1
cornMod.Commit()
subobjectLevel = 0
-- smoth
cornMod.SetOperation #MeshSmooth
cornMod.Commit()
subobjectLevel = 4
cornMod.ScaleSelection [1.2,1.2,1.2] parent:(transMatrix corn.pos) axis:(transMatrix corn.pos)
cornMod.SetSelection #Face #{1..(corn.numfaces)}
-- polytools
PolyToolsTopology.tatter 2 1 1
PolyToolsSelect.NumericFace 18 3 true
cornMod.SetOperation #Bevel
cornMod.bevelHeight = -2
cornMod.bevelOutline = -0.5
cornMod.Commit ()
cornMod.SetOperation #SetMaterial
cornMod.materialIDToSet = 0
cornMod.Commit ()
macros.run "PolyTools" "NonQuad"
-- tessellate
cornMod.SetOperation #Tessellate
cornMod.Commit ()
subobjectLevel = 0
--smoth
cornMod.ButtonOp #MeshSmooth
cornMod.ButtonOp #MeshSmooth
cornMod.SetSelection #Face #{}
subobjectLevel = 0
addmodifier corn (Smooth name:"PopcornSmooth" autosmooth:on)
-- checkbox
if ckbx1.checked do (addmodifier corn (optimize name:"PopcornOptimize" facethreshold1:15))
)
messagebox"Done."
)
)
createDialog popcorn_button 120 70