Notifications
Clear all

[Closed] help whit my new script

hi all I’m verry new to maxscript and need some help.

I want to make a script that do the same as this
1.Select an Edge or 5 or more
2. then I Hold down Shift and select Vertexmode (all verts of the edges are selected now)
3.Select again Edgemode (nothing to hold, just click to edgesmode, all previous edges are selected now)
4.Remove the edge whit backspace
5.Select Vertex (just click at Vertex, same vertex than before are selected now)
6.Remove the vertexts that where selected

hope you can help me out
the buttons and labels I can do allready

hope you can help me

5 Replies
2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

do you really need a script for this? Pressing “Remove” edges with CTRL removes both edges and their extra verts.

from max help:
To delete the associated vertices when you remove edges, press and hold Ctrl while executing a Remove operation, either by mouse or with the Backspace key. This option, called Clean Remove, ensures that the remaining polygons are planar.

(@justspeeding)
Joined: 11 months ago

Posts: 0

yes sorry after reading more abaut the remove edge and verts thoghether.
I found that faster way also now I don’t need it any more but thx for the reply

the easiest way will be to use bitarrays, which use the form of #{}

for your steps:

  1. make a bitarray with the edges you want. For example :
 firstEdges = #{1,4..8,15}

note that the above array includes 5, 6, and 7

  1. You will need to use the polyOp methods. For example (with an editable poly object stored as the variable named ‘obj’):
newVerts = polyOp.getVertsUsingEdge obj firstEdges

this will return another bitarray

  1. you still have your original edges stored in ‘firstEdges’

  2. to do this you will need to actually select the edges

polyop.setEdgeSelection obj firstEdges
 obj.Remove selLevel:#Edge
  1. and 6) make sure to select the vertices BEFORE you remove the edges, but the code is very similar:
polyop.setVertSelection obj newVerts
 obj.Remove selLevel:#Vertex

hope that helps!

he
I need some help again whit my script I wanne add icons that i made to the buttons off this script

rollout tmscript "TrackmaniaScript"
	(
	
	label tmscript "Made by Just Speeding" pos:[10,250] width:150 height:15
	button MaxBox "MaxBox" pos:[2,30] width:75 height:20
	button ProjShad "ProjShad" pos:[2,60] width:75 height:20
	button LightFProj "LightFProj" pos:[2,90] width:75 height:20
	button resxform "Reset Xform" pos:[2,120] width:75 height:20 
	button projshadrender "ProjShad Render" pos:[2,150] width:75 height:20
	button lights "Lights" pos:[2,180] width:75 height:20
	button export "QuickExport" pos:[2,210] width:75 height:20
	button prelightpreview "PrelightPreview" pos:[80,30] width:75 height:20
	button prelightrender "PrelightRender" pos:[80,60] width:75 height:20
	button wirerender "Wireframe" pos:[80,90] width:75 height:20
	------------------------------------------------------------------------------------------------
	on MaxBox pressed do
	if $MaxBox != undefined 

 then

(messageBox "MaxBox already created!")
else
	(Box lengthsegs:1 widthsegs:1 heightsegs:1 length:6 width:3 height:2.7 pos:[0,0,-0.2] wirecolor:red name:"MaxBox" 
	)
	
------------------------------------------------------------------------------------------------
	on ProjShad pressed do
	
if $projshad != undefined 
then
(messageBox "ProjShad already created!")

else
	(p = Plane lengthsegs:1 widthsegs:1 Pos:[0,0,-0.03] Length:6 Width:4 wirecolor:white name:"ProjShad"
	fn DumpXForms obj =

( -- output node transform properties
format "%:	%
" "transform" obj.transform
format "%:	%
" "position " obj.pos
format "%:	%
" "rotation " obj.rotation
-- output node's pivot point location
format "%:	%
" "pivot " obj.pivot
-- output object offsets
format "%:	%
" "objectoffsetpos " obj.objectoffsetpos
format "%:	%
" "objectoffsetrot " obj.objectoffsetrot
format "%:	%
" "objectoffsetscale" obj.objectoffsetscale
-- output object transform
format "%:	%
" "objecttransform " obj.objecttransform
-- output vertex position in local and world coordinates
format "%:	%
" "vert 1 (local) " (in coordsys local getvert obj 1)
format "%:	%
" "vert 1 (world1) " (in coordsys world getvert obj 1)
-- calculate and output vertex position in world coordinates
local v_pos=(in coordsys local getvert obj 1)* obj.objecttransform
format "%:	%
" "vert 1 (world2) " v_pos
)

-- define function for rotating only the pivot point 
fn RotatePivotOnly obj rotation= ( local rotValInv=inverse (rotation as quat)
animate off in coordsys local obj.rotation*=RotValInv
obj.objectoffsetrot*=RotValInv
obj.objectoffsetpos*=RotValInv
)


	p.pivot=[0,0,0]
	RotatePivotOnly p (Eulerangles 90 0 0)
	
	)
------------------------------------------------------------------------------------------------
	on resxform  pressed do 
		(AddMod XForm  
	)
------------------------------------------------------------------------------------------------
	on lights pressed do
	
	if $LightRR != undefined 
then
(messageBox "Lights already created!")
else
	
	(rr = Plane lengthsegs:1 widthsegs:1 length:0.1 width:0.1 pos:[-0.7,2.14,0.8] wirecolor:yellow name:"LightRR"
	rot_rr = eulerangles -90 0 0
	rotate rr rot_rr 
		fn DumpXForms obj =

(
format "%:	%
" "transform" obj.transform
format "%:	%
" "position " obj.pos
format "%:	%
" "rotation " obj.rotation
format "%:	%
" "pivot " obj.pivot
format "%:	%
" "objectoffsetpos " obj.objectoffsetpos
format "%:	%
" "objectoffsetrot " obj.objectoffsetrot
format "%:	%
" "objectoffsetscale" obj.objectoffsetscale
format "%:	%
" "objecttransform " obj.objecttransform
format "%:	%
" "vert 1 (local) " (in coordsys local getvert obj 1)
format "%:	%
" "vert 1 (world1) " (in coordsys world getvert obj 1)
local v_pos=(in coordsys local getvert obj 1)* obj.objecttransform
format "%:	%
" "vert 1 (world2) " v_pos
)
fn RotatePivotOnly obj rotation= ( local rotValInv=inverse (rotation as quat)
animate off in coordsys local obj.rotation*=RotValInv
obj.objectoffsetrot*=RotValInv
obj.objectoffsetpos*=RotValInv
)

	RotatePivotOnly rr (Eulerangles -90 0 0)
	
	rl = Plane lengthsegs:1 widthsegs:1 length:0.1 width:0.1 pos:[0.7,2.14,0.8] wirecolor:yellow name:"LightRL"
	rot_rl = eulerangles -90 0 0
	rotate rl rot_rl 
	fn DumpXForms obj =

(
format "%:	%
" "transform" obj.transform
format "%:	%
" "position " obj.pos
format "%:	%
" "rotation " obj.rotation
format "%:	%
" "pivot " obj.pivot
format "%:	%
" "objectoffsetpos " obj.objectoffsetpos
format "%:	%
" "objectoffsetrot " obj.objectoffsetrot
format "%:	%
" "objectoffsetscale" obj.objectoffsetscale
format "%:	%
" "objecttransform " obj.objecttransform
format "%:	%
" "vert 1 (local) " (in coordsys local getvert obj 1)
format "%:	%
" "vert 1 (world1) " (in coordsys world getvert obj 1)
local v_pos=(in coordsys local getvert obj 1)* obj.objecttransform
format "%:	%
" "vert 1 (world2) " v_pos
)
fn RotatePivotOnly obj rotation= ( local rotValInv=inverse (rotation as quat)
animate off in coordsys local obj.rotation*=RotValInv
obj.objectoffsetrot*=RotValInv
obj.objectoffsetpos*=RotValInv
)

	RotatePivotOnly rl (Eulerangles -90 0 0)
	
	fr1 = Plane lengthsegs:1 widthsegs:1 length:0.1 width:0.1 pos:[-0.78,-1.95,0.58] wirecolor:yellow name:"LightFR1"
	
rot_fr1 = eulerangles 90 0 0
	rotate fr1 rot_fr1 
	fn DumpXForms obj =

(
format "%:	%
" "transform" obj.transform
format "%:	%
" "position " obj.pos
format "%:	%
" "rotation " obj.rotation
format "%:	%
" "pivot " obj.pivot
format "%:	%
" "objectoffsetpos " obj.objectoffsetpos
format "%:	%
" "objectoffsetrot " obj.objectoffsetrot
format "%:	%
" "objectoffsetscale" obj.objectoffsetscale
format "%:	%
" "objecttransform " obj.objecttransform
format "%:	%
" "vert 1 (local) " (in coordsys local getvert obj 1)
format "%:	%
" "vert 1 (world1) " (in coordsys world getvert obj 1)
local v_pos=(in coordsys local getvert obj 1)* obj.objecttransform
format "%:	%
" "vert 1 (world2) " v_pos
)
fn RotatePivotOnly obj rotation= ( local rotValInv=inverse (rotation as quat)
animate off in coordsys local obj.rotation*=RotValInv
obj.objectoffsetrot*=RotValInv
obj.objectoffsetpos*=RotValInv
)

	RotatePivotOnly fr1 (Eulerangles -90 0 0)	
		
	fr2 = Plane lengthsegs:1 widthsegs:1 length:0.1 width:0.1 pos:[-0.68,-1.95,0.516] wirecolor:yellow name:"LightFR2"
rot_fr2 = eulerangles 90 0 0
	rotate fr2 rot_fr2 
	fn DumpXForms obj =

(
format "%:	%
" "transform" obj.transform
format "%:	%
" "position " obj.pos
format "%:	%
" "rotation " obj.rotation
format "%:	%
" "pivot " obj.pivot
format "%:	%
" "objectoffsetpos " obj.objectoffsetpos
format "%:	%
" "objectoffsetrot " obj.objectoffsetrot
format "%:	%
" "objectoffsetscale" obj.objectoffsetscale
format "%:	%
" "objecttransform " obj.objecttransform
format "%:	%
" "vert 1 (local) " (in coordsys local getvert obj 1)
format "%:	%
" "vert 1 (world1) " (in coordsys world getvert obj 1)
local v_pos=(in coordsys local getvert obj 1)* obj.objecttransform
format "%:	%
" "vert 1 (world2) " v_pos
)
fn RotatePivotOnly obj rotation= ( local rotValInv=inverse (rotation as quat)
animate off in coordsys local obj.rotation*=RotValInv
obj.objectoffsetrot*=RotValInv
obj.objectoffsetpos*=RotValInv
)

	RotatePivotOnly fr2 (Eulerangles -90 0 0)	

	fr3 = Plane lengthsegs:1 widthsegs:1 length:0.1 width:0.1 pos:[-0.57,-1.95,0.452] wirecolor:yellow name:"LightFR3"
rot_fr3 = eulerangles 90 0 0
	rotate fr3 rot_fr3 
	fn DumpXForms obj =

(
format "%:	%
" "transform" obj.transform
format "%:	%
" "position " obj.pos
format "%:	%
" "rotation " obj.rotation
format "%:	%
" "pivot " obj.pivot
format "%:	%
" "objectoffsetpos " obj.objectoffsetpos
format "%:	%
" "objectoffsetrot " obj.objectoffsetrot
format "%:	%
" "objectoffsetscale" obj.objectoffsetscale
format "%:	%
" "objecttransform " obj.objecttransform
format "%:	%
" "vert 1 (local) " (in coordsys local getvert obj 1)
format "%:	%
" "vert 1 (world1) " (in coordsys world getvert obj 1)
local v_pos=(in coordsys local getvert obj 1)* obj.objecttransform
format "%:	%
" "vert 1 (world2) " v_pos
)
fn RotatePivotOnly obj rotation= ( local rotValInv=inverse (rotation as quat)
animate off in coordsys local obj.rotation*=RotValInv
obj.objectoffsetrot*=RotValInv
obj.objectoffsetpos*=RotValInv
)

	RotatePivotOnly fr3 (Eulerangles -90 0 0)	

	fl1 = Plane lengthsegs:1 widthsegs:1 length:0.1 width:0.1 pos:[0.78,-1.95,0.58] wirecolor:yellow name:"LightFL1"
	
	rot_fl1 = eulerangles 90 0 0
	rotate fl1 rot_fl1 
	fn DumpXForms obj =

(
format "%:	%
" "transform" obj.transform
format "%:	%
" "position " obj.pos
format "%:	%
" "rotation " obj.rotation
format "%:	%
" "pivot " obj.pivot
format "%:	%
" "objectoffsetpos " obj.objectoffsetpos
format "%:	%
" "objectoffsetrot " obj.objectoffsetrot
format "%:	%
" "objectoffsetscale" obj.objectoffsetscale
format "%:	%
" "objecttransform " obj.objecttransform
format "%:	%
" "vert 1 (local) " (in coordsys local getvert obj 1)
format "%:	%
" "vert 1 (world1) " (in coordsys world getvert obj 1)
local v_pos=(in coordsys local getvert obj 1)* obj.objecttransform
format "%:	%
" "vert 1 (world2) " v_pos
)
fn RotatePivotOnly obj rotation= ( local rotValInv=inverse (rotation as quat)
animate off in coordsys local obj.rotation*=RotValInv
obj.objectoffsetrot*=RotValInv
obj.objectoffsetpos*=RotValInv
)

	RotatePivotOnly fl1 (Eulerangles -90 0 0)	

	
	fl2 = Plane lengthsegs:1 widthsegs:1 length:0.1 width:0.1 pos:[0.68,-1.95,0.516] wirecolor:yellow name:"LightFL2"

	rot_fl2 = eulerangles 90 0 0
	rotate fl2 rot_fl2 
	fn DumpXForms obj =

(
format "%:	%
" "transform" obj.transform
format "%:	%
" "position " obj.pos
format "%:	%
" "rotation " obj.rotation
format "%:	%
" "pivot " obj.pivot
format "%:	%
" "objectoffsetpos " obj.objectoffsetpos
format "%:	%
" "objectoffsetrot " obj.objectoffsetrot
format "%:	%
" "objectoffsetscale" obj.objectoffsetscale
format "%:	%
" "objecttransform " obj.objecttransform
format "%:	%
" "vert 1 (local) " (in coordsys local getvert obj 1)
format "%:	%
" "vert 1 (world1) " (in coordsys world getvert obj 1)
local v_pos=(in coordsys local getvert obj 1)* obj.objecttransform
format "%:	%
" "vert 1 (world2) " v_pos
)
fn RotatePivotOnly obj rotation= ( local rotValInv=inverse (rotation as quat)
animate off in coordsys local obj.rotation*=RotValInv
obj.objectoffsetrot*=RotValInv
obj.objectoffsetpos*=RotValInv
)

	RotatePivotOnly fl2 (Eulerangles -90 0 0)

	fl3 = Plane lengthsegs:1 widthsegs:1 length:0.1 width:0.1 pos:[0.57,-1.95,0.452] wirecolor:yellow name:"LightFL3"
	
	rot_fl3 = eulerangles 90 0 0
	rotate fl3 rot_fl3 
	fn DumpXForms obj =

(
format "%:	%
" "transform" obj.transform
format "%:	%
" "position " obj.pos
format "%:	%
" "rotation " obj.rotation
format "%:	%
" "pivot " obj.pivot
format "%:	%
" "objectoffsetpos " obj.objectoffsetpos
format "%:	%
" "objectoffsetrot " obj.objectoffsetrot
format "%:	%
" "objectoffsetscale" obj.objectoffsetscale
format "%:	%
" "objecttransform " obj.objecttransform
format "%:	%
" "vert 1 (local) " (in coordsys local getvert obj 1)
format "%:	%
" "vert 1 (world1) " (in coordsys world getvert obj 1)
local v_pos=(in coordsys local getvert obj 1)* obj.objecttransform
format "%:	%
" "vert 1 (world2) " v_pos
)
fn RotatePivotOnly obj rotation= ( local rotValInv=inverse (rotation as quat)
animate off in coordsys local obj.rotation*=RotValInv
obj.objectoffsetrot*=RotValInv
obj.objectoffsetpos*=RotValInv
)

	RotatePivotOnly fl3 (Eulerangles -90 0 0)
	
)

---------------------------------------------------------------------------------------


on LightFProj pressed do

if $LightFProj != undefined 
then
(messageBox "LightFProj already created!")
else

(lp = Plane lengthsegs:1 widthsegs:1 length:0.1 width:0.1 pos:[0,-2.2,0.58] wirecolor:yellow name:"LightFProj"
		rot_lp = eulerangles 90 0 0
	rotate lp rot_lp 
		fn DumpXForms obj =

(
format "%:	%
" "transform" obj.transform
format "%:	%
" "position " obj.pos
format "%:	%
" "rotation " obj.rotation
format "%:	%
" "pivot " obj.pivot
format "%:	%
" "objectoffsetpos " obj.objectoffsetpos
format "%:	%
" "objectoffsetrot " obj.objectoffsetrot
format "%:	%
" "objectoffsetscale" obj.objectoffsetscale
format "%:	%
" "objecttransform " obj.objecttransform
format "%:	%
" "vert 1 (local) " (in coordsys local getvert obj 1)
format "%:	%
" "vert 1 (world1) " (in coordsys world getvert obj 1)
local v_pos=(in coordsys local getvert obj 1)* obj.objecttransform
format "%:	%
" "vert 1 (world2) " v_pos
)
fn RotatePivotOnly obj rotation= ( local rotValInv=inverse (rotation as quat)
animate off in coordsys local obj.rotation*=RotValInv
obj.objectoffsetrot*=RotValInv
obj.objectoffsetpos*=RotValInv
)

	RotatePivotOnly lp (Eulerangles -90 0 0)
)
------------------------------------------------------------------------------------------------
	on export pressed do
(
a = maxfilepath 
exportFile (a + "MainBodyHigh.3ds" ) )
------------------------------------------------------------------------------------------------
on prelightpreview pressed do
	(
	
	Plane lengthsegs:1 widthsegs:1 length:10 width:10 pos:[0,0,-5] wirecolor:gray name:"prelightplane"
	skylight pos:[0,0,0] multiplier:1.1615 castShadows:on name:"prelight_preview_light"
	select $sBody	
	fn renderLightmap obj currentMapType Xsize Ysize channel fullFileName =
(
fPath=getFilenamePath fullFileName
fName=getFilenameFile fullFileName
fType=getFilenameType fullFileName
bi = obj.INodeBakeProperties
currentMapType.outputSzX=Xsize
currentMapType.outputSzY=Ysize
currentMapType.filename=fName
currentMapType.fileType=fType
bi.addBakeElement currentMapType
bi.bakeChannel=channel
bi.bakeEnabled = true
bi.nDilations = 8
render rendertype:#bakeSelected outputwidth:Xsize outputheight:Ysize outputfile:(fPath+fName+fType)
bi.removeAllBakeElements()
bi.bakeEnabled = false

format "rendering node:% channel:%
" obj.name bi.bakeChannel
)

obj=selection[1]
alightMap=LightingMap()

renderLightmap obj alightMap 512 512 1 (maxfilepath + "prelight_preview.tga")
delete $prelightplane
delete $prelight_preview_light
	)
------------------------------------------------------------------------------------------------
	
	on prelightrender pressed do
	(
	
	Plane lengthsegs:1 widthsegs:1 length:10 width:10 pos:[0,0,-5] wirecolor:gray
	skylight pos:[0,0,0] multiplier:1.1615 castShadows:on name:"prelight_light"
	select $sBody	
	fn renderLightmap obj currentMapType Xsize Ysize channel fullFileName =
(
fPath=getFilenamePath fullFileName
fName=getFilenameFile fullFileName
fType=getFilenameType fullFileName
bi = obj.INodeBakeProperties
currentMapType.outputSzX=Xsize
currentMapType.outputSzY=Ysize
currentMapType.filename=fName
currentMapType.fileType=fType
bi.addBakeElement currentMapType
bi.bakeChannel=channel
bi.bakeEnabled = true
bi.nDilations = 8
render rendertype:#bakeSelected outputwidth:Xsize outputheight:Ysize outputfile:(fPath+fName+fType)
bi.removeAllBakeElements()
bi.bakeEnabled = false

format "rendering node:% channel:%
" obj.name bi.bakeChannel
)

obj=selection[1]
alightMap=LightingMap()
renderLightmap obj alightMap 2048 2048 1 (maxfilepath + "prelight.tga")
delete $prelightplane
delete $prelight_light

	)
---------------------------------------------------------
on wirerender pressed do
(
select $sBody
modPanel.addModToSelection (Unwrap_UVW())

_size = 2048;
$.modifiers[#unwrap_uvw].renderuv_width =  _size;
$.modifiers[#unwrap_uvw].renderuv_height = _size;
$.modifiers[#unwrap_uvw].renderuv_fillmode = 0;--solid
$.modifiers[#unwrap_uvw].renderuv_seamColor = color 255 255 255;
$.modifiers[#unwrap_uvw].renderuv_showframebuffer = true;

theFileName = (maxfilepath + "Wireframe.bmp" )
$.modifiers[#unwrap_uvw].unwrap5.renderUV theFileName;
convertToMesh $sBody
)
------------------------------------------------------------------------------------------------
	on projshadrender pressed do 
	(
	
	skylight pos:[0,0,0] multiplier:1.2 castShadows:off name:"projshad_light"
	select $ProjShad	
fn renderLightmap obj currentMapType Xsize Ysize channel fullFileName =
(
fPath=getFilenamePath fullFileName
fName=getFilenameFile fullFileName
fType=getFilenameType fullFileName
sceneRadiosity.radiosity = Light_Tracer()
sceneRadiosity.radiosity.bounces = 2
sceneRadiosity.radiosity.rays = 250
bi = obj.INodeBakeProperties
currentMapType.outputSzX=Xsize
currentMapType.outputSzY=Ysize
currentMapType.filename=fName
currentMapType.fileType=fType
bi.addBakeElement currentMapType
bi.bakeChannel=channel
bi.bakeEnabled = true
bi.nDilations = 8
render rendertype:#bakeSelected outputwidth:Xsize outputheight:Ysize outputfile:(fPath+fName+fType)
bi.removeAllBakeElements()
bi.bakeEnabled = false

format "rendering node:% channel:%
" obj.name bi.bakeChannel
)

obj=selection[1]
alightMap=LightingMap()

renderLightmap obj alightMap 1024 1024 1 (maxfilepath + "projshad.bmp")
sceneradiosity.radiosity = undefined
delete $projshad_light
	)

------------------------------------------------------------------------------------------------		
		)

	createdialog tmscript

To use your icons for buttons first you need to create them.
Draw two bmp files. One will contain the image, second will be aplha channel (white-opacity, black-solid).
I using 16×15 pixels images for 20×20 sized buttons.

If you have the icons created you need to load them into memory. Add this code on begining of your script:

-- load buttons images
My_buttons_count = 1 -- how many single images contains the files (placed verticaly)

if( My_buttons != undefined ) then close My_buttons
My_buttons = openBitmap ((GetDir #scripts)+"\\My_Buttons.bmp")

if( My_buttons_a != undefined ) then close My_buttons_a
My_buttons_a = openBitmap ((GetDir #scripts)+"\\My_ButtonsA.bmp")

Now you can create button with icon:

button test_btn width:20 height:20 images:#( My_buttons, My_buttons_a, My_buttons_count, 1, 1, 1, 1 )

Check maxscript help to get know what means numbers in images:#( )