extrude code is not work ~~

extrude code is not work ~~

anycganycgJ8A6A
Advocate Advocate
1,866 Views
12 Replies
Message 1 of 13

extrude code is not work ~~

anycganycgJ8A6A
Advocate
Advocate

i made this code ~~

but not work  in many objects     

and that is not extruded

what problem ~~~

 

 

 

for o in selection do
(


max create mode


converttosplineshape o
oo=copy o

sx=random 0.2 0.5
sy=random 0.1 0.5
oo.pivot=oo.center
oo.scale.x=sx
oo.scale.y=sy
converttopoly oo
gg=7000
addmodifier oo (shell outeramount:gg inneramount:0 )
p=random o.max o.min
oo.pos=p
louban_mat oo
converttopoly oo
select oo
subobjectlevel=4
polyop.setfaceselection oo 1
oo.insetAmount = 200
oo.EditablePoly.buttonOp #Inset
oo.extrusionType = 0
oo.faceExtrudeHeight = -600
oo.EditablePoly.buttonOp #Extrude
subobjectlevel=0
clearselection()
redrawviews()

)

0 Likes
1,867 Views
12 Replies
Replies (12)
Message 2 of 13

blakestone
Collaborator
Collaborator

Your code works however only for Geometry objects - it's possibly failing when trying to perform a step on a Non-Geometry object or a Geometry object which has nothing in it i.e. no vertices, polygons etc.

The following adjustment will only allow the script to perform the steps on valid geometry objects.

(
    max create mode
    
    for o in selection where (superClassOf o == GeometryClass) do (
        --converttosplineshape o
        oo=copy o
        
    -------------------------------------------------------
    -- convert object to editable poly
        convertToPoly oo
        
    -- check if copied object has any vertices
    -- if not then delete copied object and skip to next selected object
        if (oo.verts.count == 0) then (
            delete oo
            continue
        )
    -------------------------------------------------------
        sx=random 0.2 0.5
        sy=random 0.1 0.5
        oo.pivot=oo.center
        oo.scale.x=sx
        oo.scale.y=sy
        converttopoly oo
        gg=7000
        addmodifier oo (shell outeramount:gg inneramount:0 )
        p=random o.max o.min
        oo.pos=p
        --louban_mat oo
        converttopoly oo
        select oo
        subobjectlevel=4
        polyop.setfaceselection oo 1
        oo.insetAmount = 200
        oo.EditablePoly.buttonOp #Inset
        oo.extrusionType = 0
        oo.faceExtrudeHeight = -600
        oo.EditablePoly.buttonOp #Extrude
        subobjectlevel=0
        clearselection()
        redrawviews()
    )
)
--------------------------------------------------------------------------------------
Technical 3D Graphic Artist
Autodesk 3dsMax 2015 - Service Pack 4
--------------------------------------------------------------------------------------
0 Likes
Message 3 of 13

anycganycgJ8A6A
Advocate
Advocate

i tested that code

but that is not work well

pls select  many object ~~~

only worked  1 object

and not extrude~~~

0 Likes
Message 4 of 13

blakestone
Collaborator
Collaborator

This script works in my scene - I would like to see your scene to know why this is not working for you.

Can you please send me your scene so I can see what is causing it to fail.

--------------------------------------------------------------------------------------
Technical 3D Graphic Artist
Autodesk 3dsMax 2015 - Service Pack 4
--------------------------------------------------------------------------------------
0 Likes
Message 5 of 13

anycganycgJ8A6A
Advocate
Advocate

i  test it  in other  computer

but same error

i use  max 2013

see attached max file~~

0 Likes
Message 6 of 13

blakestone
Collaborator
Collaborator

Ok, I have made a few modifications and it's now working with the scene you provided.

(
	with undo on (
		local list = for o in selection where (superClassOf o == GeometryClass) collect copy o
		max modify mode
		
		for o in list do (
			select o
			convertToPoly o
			
			if (o.verts.count == 0) then (
				delete o
				continue
			)

			o.pivot = o.center
			o.scale.x = random 0.2 0.5
			o.scale.y = random 0.1 0.5
			addmodifier o (shell outeramount:7000 inneramount:0)
			o.pos = random o.max o.min
			convertToPoly o
			subObjectLevel = 4
			polyop.setFaceSelection o 1
			o.insetAmount = 200
			o.EditablePoly.buttonOp #Inset
			o.extrusionType = 0
			o.faceExtrudeHeight = -600
			o.EditablePoly.buttonOp #Extrude
			subobjectlevel = 0
			update o
			clearSelection()
		)
		forceCompleteRedraw()
	)
)
--------------------------------------------------------------------------------------
Technical 3D Graphic Artist
Autodesk 3dsMax 2015 - Service Pack 4
--------------------------------------------------------------------------------------
0 Likes
Message 7 of 13

anycganycgJ8A6A
Advocate
Advocate

really  thank you  ~~~

but there is   2 problem ~~~

sorry my many ask ~~~

 

1.  if you see attched image .    object  random  z move 

     created object     will become  z.0

 

2. if i  100 numbers object select , that  very slow

pls     can you  modify   that  that is not created in modify mode ~~

0 Likes
Message 8 of 13

blakestone
Collaborator
Collaborator

The following script will be dramatically faster - it took about 10 seconds to do 1000+ objects on my little laptop. This method is performing the steps on all valid objects as once, in addition to this I have disabled "undo" which also greatly assists with speeding up scripts.

 

(
    with undo off (
        local sel = for o in selection where (superClassOf o == GeometryClass) collect convertToPoly(copy o)
        local list = for o in sel where (o.verts.count > 0) collect o
        
        max modify mode
        
        clearSelection()
        select list
        
        for o in selection do (
            o.pivot = o.center
            o.scale.x = random 0.2 0.5
            o.scale.y = random 0.1 0.5
            addmodifier o (shell outeramount:7000 inneramount:0)
            o.pos = random o.max o.min
            convertToPoly o
            subObjectLevel = 4
            polyop.setFaceSelection o 1
            o.insetAmount = 200
            o.EditablePoly.buttonOp #Inset
            o.extrusionType = 0
            o.faceExtrudeHeight = -600
            o.EditablePoly.buttonOp #Extrude
            subobjectlevel = 0
        )
        clearSelection()
        forceCompleteRedraw()
    )
)

Regarding problem #1 - are you wanting the Z coordinates to be 0 or a random number?

 

 example.gif

--------------------------------------------------------------------------------------
Technical 3D Graphic Artist
Autodesk 3dsMax 2015 - Service Pack 4
--------------------------------------------------------------------------------------
0 Likes
Message 9 of 13

anycganycgJ8A6A
Advocate
Advocate

yes~~

i want z 0

i attached my wanted image

0 Likes
Message 10 of 13

blakestone
Collaborator
Collaborator

This will set Z to zero.

 

(
	with undo off (
		local sel = for o in selection where (superClassOf o == GeometryClass) collect convertToPoly(copy o)
		local list = for o in sel where (o.verts.count > 0) collect o
		local rand
		
		max modify mode
		
		clearSelection()
		select list
		
		for o in selection do (
			o.pivot = o.center
			o.scale.x = random 0.2 0.5
			o.scale.y = random 0.1 0.5
			addmodifier o (shell outeramount:7000 inneramount:0)
			rand = random o.max o.min
			rand.z = 0
			o.pos = rand
			convertToPoly o
			subObjectLevel = 4
			polyop.setFaceSelection o 1
			o.insetAmount = 200
			o.EditablePoly.buttonOp #Inset
			o.extrusionType = 0
			o.faceExtrudeHeight = -600
			o.EditablePoly.buttonOp #Extrude
			subobjectlevel = 0
		)
		clearSelection()
		forceCompleteRedraw()
	)
)
--------------------------------------------------------------------------------------
Technical 3D Graphic Artist
Autodesk 3dsMax 2015 - Service Pack 4
--------------------------------------------------------------------------------------
0 Likes
Message 11 of 13

anycganycgJ8A6A
Advocate
Advocate

work well

but inset not apply ~~~

sorry sorry  and thank you kindly reply~~~~

pls see my attached image

0 Likes
Message 12 of 13

blakestone
Collaborator
Collaborator

Yes the 'inset' is not working because these steps and simulated button presses can not be performed on a selection of objects they need to be done one-by-one. Splitting up the code like I have below allows you to perform these steps on the selection and one-by-one. This is still quite a slow process and for 1000+ objects will take several minutes.

If time is a real issue here then I would suggest approaching this differently, instead of constructing these objects via script - build a modular template and simply use script to postion, scale it etc.
 

(
	with undo off (
		local sel = for o in selection where (superClassOf o == GeometryClass) collect convertToPoly(copy o)
		local list = for o in sel where (o.verts.count > 0) collect o
		local rand
		
		max modify mode
		
		clearSelection()
		select list
		
		for o in selection do (
			o.pivot = o.center
			o.scale.x = random 0.2 0.5
			o.scale.y = random 0.1 0.5
			addmodifier o (shell outeramount:7000 inneramount:0)
			rand = random o.max o.min
			rand.z = 0
			o.pos = rand
			convertToPoly o
		)
		
		for o in list do (
			clearSelection()
			select o
			subObjectLevel = 4
			polyop.setFaceSelection o 1
			o.insetAmount = 200
			o.EditablePoly.buttonOp #Inset
			o.extrusionType = 0
			o.faceExtrudeHeight = -600
			o.EditablePoly.buttonOp #Extrude
			subobjectlevel = 0
		)
		clearSelection()
		forceCompleteRedraw()
	)
)
--------------------------------------------------------------------------------------
Technical 3D Graphic Artist
Autodesk 3dsMax 2015 - Service Pack 4
--------------------------------------------------------------------------------------
0 Likes
Message 13 of 13

anycganycgJ8A6A
Advocate
Advocate

wow good ~~~~

rellay really thank you 

if that is slow , like you said  i will think other aprroach~

really really thank you ~~

again  rellay really thank you ~~~

0 Likes