function not able to run on all array ellements!

Hello! i'm new on maxscript. Thanx a lot for the time you'll spend to help me. sorry for my english it's not my native language... At Least I'm sorry if it's not the good section to post my trouble.

I'm working on a script able to create an orthogonal projection of the object as a simplify shape.

Actualy i try to auto weld all the knots of the differents shapes i creat.
And i don't understand why it's only work on one shape (the last of the list exactly).

fn AutoWeld theShape =
(
	-- function which select all knots from a shape and weld them.
	select theShape
-- select the shape for work on.
	subobjectLevel = 1
-- switch on vertex selection mode.
	for s = 1 to (numSplines theShape) do
-- initiate a for loop in the shape.
	(
		kArray = #{1..(numKnots theShape s)} as array
-- initiate an array for store the Knot selection. And fill it with all the knots.
		setKnotSelection theShape s kArray keep:true
-- Select all the knots from the array.
        )
	splineOps.weld $
-- Weld the selection of knots.
	updateshape theShape
-- update the shape to make true the weld.
)
 
 
for ind = 1 to obj_projection.count do AutoWeld obj_projection[ind]
-- call auto weld on each shape.

In a second intention i try to convert back the knots as #corner.
I meet exactly the same trouble.

fn ConvertToCorner theShape =
(
	-- function who convert all knots to corner knots.
	for s = 1 to (numSplines theshape) do
-- initiate a loop on the lines.
	(
		kArray = #{1..(numKnots theShape s)} as array
-- refile the kArray with the knots welded (1/2 of the previous array).
		for k = 1 to kArray.count do setKnotType theShape s kArray[k] #corner
-- convert all knots as #corner.
	)
	updateshape theShape
-- update the shape to make true the conversion.
)
 
for ind = 1 to obj_projection.count do ConvertToCorner obj_projection[ind]
-- call convert to corner on each shape.

For being honest i try to implement those during the drawning shape part but there is no result. And when i call the borh in the same loop i have no visual effect too... (maybe cause only the convert to corner is effective?)
The both function are working if i run them separatly (and manualy) on each shape, I mean i select the shape and run one script with AutoWeld then an other with ConvertToCorner, but when the both are in the same script called independently or together nothing append.
like :

AutoWeld $
ConvertToCorner $
 
or
AutoWeld $ (with auto weld calling convert to corner)

Soo if any one could see some solution??

And for information My array is fill with shape path creat by : shape = execute ("$'"+$.name+"'") and work perfectly with my linker loop and my layer repartition.

Thanx a lott for all the help you'll give to me!

Comments

Comment viewing options

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

THX to Miauu for this fast

THX to Miauu for this fast Answer, i put it there if people have some trouble like mine.

Hi!

Your script welds the knots of the last spline because this is a bug in the splineOps method that 3dsmax uses. The only proper way that I know is not to use the splineOps, but to press the WELD button in the modify pannel using few lines of code. This way the script will weld the knots of all splines. Here is the code:

(
    function AutoWeld theShape =
    (
        convertToSplineShape theShape
        select theShape
        subobjectLevel = 1
        max select all
        df = #max 
        for child in (windows.getChildrenHWND dF) where child[4] == "#32770" do
        (
            for classN in (windows.getChildrenHWND child[1]) where (classN[4] == "ModifyTask") do
            (
                for btn in (windows.getChildrenHWND classN[1]) where (btn[5] == "Weld") do
                (
                    UIAccessor.PressButton btn[1]
                )
            )
        )
        subobjectLevel = 0 
        updateshape theShape
    )
 
    function ConvertKnotsTo curObj type: =
    (
        if classOf curObj == splineShape or classof curObj == Line do
        (
            convertToSplineShape curObj
            subSplines = numSplines curObj
            for ss = 1 to subSplines do
            (
                knotBA = #{1..(numKnots curObj ss)}            
                for i in knotBA do setKnotType curObj ss i type
                updateshape curObj
            )
        )
    )
 
    max modify mode
    obj_projection = selection as array
    for ind = 1 to obj_projection.count do
    (
        AutoWeld obj_projection[ind]
        ConvertKnotsTo obj_projection[ind] type:#corner
    )
)

The modyfi panel must be active, so don't remove the max modify mode line.

Best Regards!
miauuMaxScript
:)

Thanx a Lot Miauu for your time and help!

miauu's picture

.

You're welcome. :)

Comment viewing options

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