Announcement

Collapse
No announcement yet.

Maxscript help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Maxscript help

    ..again!

    I'm trying to alter a script from a fellow called Chris Harvey, that detaches elements to objects. It centers the pivots on each object, but I also want to align the pivot to the normal of the single polygon that that new object will contain. I'm dealing with single poly faces (as leaves) so I know they will only ever contain the single polygon.

    Here's the original script with some crap I put in (in red) there to try and do this, but it's not working. I'm getting this:

    >> MAXScript MacroScript Error Exception: -- Runtime error: EPoly operation on non-Editable Poly: OK <<

    Code:
    macroScript DetachElements category:"HacksawTOOLS" tooltip:"Split elements into seperate objects" ButtonText:"DetachElements"
    (
    on isEnabled return
    (selection.count >=1)
    
    on execute do
    (--start execute loop
    
    --***********************************************************************************************************   FUNCTION DEFINITIONS START	
    	local DetachPolyElements_fn, DetachSplineElements_fn, DetachMeshElements_fn
    	
    	FN DetachPolyElements_fn SourceOBJ =
    	(--start function for detaching elements from an editable poly object
    		MasterObj = SourceOBJ 
    		faceCount = MasterObj.getnumfaces()
    		
    		FaceTest = ((MasterObj.getnumfaces()) != 0)
    		
    		for ii in 1 to faceCount while FaceTest do	--ends loop when there are no faces left to select
    		(--start element detach loop
    			newName = (uniquename (MasterObj.name as string))
    			
    			MasterObj.EditablePoly.SetSelection #Face #{1}
    			MasterObj.selectElement()
    			TargetElement = polyop.getFaceSelection MasterObj
    			polyop.detachFaces MasterObj TargetElement asNode:true name:newName
    			
    			NewObj = getnodebyname newName
    			resetXForm NewObj 
    			convertTo NewObj (Editable_Poly)
    			ResetTransform NewObj 
    			ResetScale NewObj
    			ResetPivot NewObj 
    			centerpivot NewObj
    			[color=red]
    			selecto = NewObj.EditablePoly.SetSelection #Face #{1}
    			Rotation polyNorm = polyop.getFaceNormal selecto #{1}
    			NewObj.pivot.rotation = polyNorm
    			[/color]
    			FaceTest = ((MasterObj.getnumfaces()) != 0)
    		)--end element detach loop
    		delete MasterObj	
    	)--end function for detaching elements from an editable poly object
    	
    	FN DetachSplineElements_fn SourceOBJ =
    	(--start function for detaching from editable splines
    		MasterSpline = SourceOBJ 
    		ns = numsplines MasterSpline 	
    	
    		for i in 1 to ns do    -- for each element in the spline it re-orders the elements
    		(
    			tempMaster = copy MasterSpline 
    			tempMaster.name = (MasterSpline.name + "_Element_" + (i as string))
    			select tempMaster 
    			setFirstSpline tempMaster i
    			
    			for ii = ns to 2 by -1 do    -- deletes all of the elements except the first one
    			(
    				deleteSpline tempMaster ii
    			)
    			select MasterSpline
    		)
    		delete MasterSpline	
    	)--end function for detaching from editable splines
    	
    	FN DetachMeshElements_fn SourceOBJ =
    	(--start function for detaching elements from an editable Mesh object
    		MasterObj = SourceOBJ
    		convertTo MasterObj (Editable_Poly) 
    		faceCount = MasterObj.getnumfaces()
    		
    		FaceTest = ((MasterObj.getnumfaces()) != 0)
    		
    		for ii in 1 to faceCount while FaceTest do	--ends loop when there are no faces left to select
    		(--start element detach loop
    			newName = (uniquename (MasterObj.name as string))
    			
    			MasterObj.EditablePoly.SetSelection #Face #{1}
    			MasterObj.selectElement()
    			TargetElement = polyop.getFaceSelection MasterObj
    			polyop.detachFaces MasterObj TargetElement asNode:true name:newName
    			
    			NewObj = getnodebyname newName
    			resetXForm NewObj 
    			convertTo NewObj (Editable_Mesh)
    			ResetTransform NewObj 
    			ResetScale NewObj 
    			ResetPivot NewObj 
    			centerpivot NewObj
    			FaceTest = ((MasterObj.getnumfaces()) != 0)
    		)--end element detach loop
    		delete MasterObj	
    	)--end function for detaching elements from an editable Mesh object
    --***********************************************************************************************************   FUNCTION DEFINITIONS END	
    	
    	max create mode
    	ObjsSource = getCurrentSelection()	--create array of all selected objects
    	if ObjsSource[1] == undefined then messagebox "Nothing is selected!"    -- checks to see something is selected
    			
    	else for obj in 1 to ObjsSource.count do with redraw off
    	(--start Object loop
    		SourceOBJ = ObjsSource[obj]
    		if (classof SourceOBJ  == editable_poly) then (DetachPolyElements_fn SourceOBJ)			-- operates only on those objects that are editable polys
    		else if (classOf SourceOBJ == SplineShape or classOf SourceOBJ == line) then (DetachSplineElements_fn SourceOBJ)    -- operates only on those objects that are splines
    		else if (classOf SourceOBJ == Editable_Mesh) then (DetachMeshElements_fn SourceOBJ)		-- operates only on those objects that are editable meshes
    	)--end Object loop
    	max views redraw
    )--end execute loop
    )

  • #2
    Here's another one i'll cram in here:

    fileName = maxFileName
    returns test.max

    trimmedFileName = trimRight fileName ".max"
    returns test

    However, if the file is called, say, aaaa.max, the trimmed argument returns nothing!

    So, how do i say trimRight EXACT STRING ".max" ?

    Comment


    • #3
      George,

      Let me take a look around...i remember i asked Bobo awhile back on cgtalk if there was a way to select single polys in a scene (leaves). I have the script around somewhere....though give a check in the maxscript section of cgtalk. I'll post it if i find it.
      -----Dwayne D. Ellis-----

      Comment


      • #4
        look at the help page for getfilenamefile theres a few options there for filenames, also the pathconfig struct is helpful
        Dave Buchhofer. // Vsaiwrk

        Comment

        Working...
        X