ScriptSpot

Forum topic · Scripts Wanted

Script similar to Fill mode in Object Paint

By myland · 2019-05-13

Description

Hello everyone,

As always I am struggling with a scripted I wish to make.
I need to make something that act pretty much as the Fill mode (edgeloop selectio) in the Object Paint since it seems impossible to access this option via maxscript.

So I tried to do it by myself with no success unfortunately (the code below is the closer one I got).
Actually my code it's far to be perfect but pretty ok when I duplicate my instances along an edge longer than the distance I set (5 in this case but should be modifiable). When the edge length is shorter than 5 I don't get what I want whatever I tried.

I guess the solution should be to set every edge's length to 5 by moving or creating vertex but I don't know if that's possible.

Could you help me?


Clearlistener()

-- "To test it well your edgeloop selection should have some edge's length shorter thant 5"

Inst = Pyramid width: 5.0 height: 5.0 depth: 5.0 pos:[0,0,0]

for obj in selection do
(
C = [0,0,0]
D = [0,0,0]
H = 0
M = 0
vert = #()
j = 1
tot = 0

A = polyop.getedgeselection obj
for i in A do
(
B = polyop.getEdgeVerts obj i
append vert B

)

while j <= (vert.count) do
(
C = polyop.getVert obj vert[j][1]
D = polyop.getVert obj vert[j][2]
H = distance C D

if H < 5 then
(
while H < 5 do
(

H = distance C D
M += 1
tot = M + j
if tot > vert.count then
(exit)
D = polyop.getVert obj vert[tot][2]
print tot
)
H = distance C D
j = tot
M = 0
)
else if H >= 5 then
(
j = j+1
M = 0
)

H = distance C D
G = (H / 5) as integer
for i = 1 to G do
(
ofS = [0,0,5 * (i - 1)]
P = (instance Inst)
P.pos = C
P.dir = (D - C)
P.objectOffsetPos = ofS
)

)

)

Comments (3)

Nobody has advices?

myland · 2019-06-08

Hi there,
Since I don't see any responses, I wonder if I was clear enough when I tried to explain my case with my pretty poor English?

Even if you don't know the solution I will be glad to have your opinion about where I should focus my research for example? I mean any idea will be considered ^^

Thanks again

.

jahman · 2019-06-10

After a week you won't be able to understand so poorly written code.
Variables with meaningless names are evil, unless you're trying to obfuscate the code :)

You can check this example, it isn't maxscript, but the algorithm is pretty simple.


// javascript
// noprotect
// divide loop of edges by step

// edge lengths array
var edges = [ 1.5, 0.5, 0.5, 0.5, 1.5, 5 ];

// expected:
// 1th edge is divided 1 time
// 2nd edge 0 times
// 3rd edge 0 times
// 4th edge 1 time
// 5th edge 1 time
// 6th edge 3 times

var step = 1.5;

var i = 0;
var remainder = 0.0;

if ( step > 0 )
{
do {
        
    var count = ((edges[i] + remainder) / step) | 0;      
    
    for ( var j=1; j <= count; j++)
      {        
        var fraction = (step * j - remainder) / edges[i];
          
        if ( fraction >= 0.0 )
        {
            console.log( "edge index:" + i + "    fraction:" + parseFloat(fraction).toFixed(2) );          
            
        }
        
      }
        
    // make sure that the count is an integer
    remainder = (edges[i] + remainder) - count * step;
  
    i++;
    
    
 }
while( i < edges.length );
}

.

myland · 2019-06-12

Hi jahman,

you are right, my variable's names are very bad, I really need to do an effort for it :)

Thansk for your reply by the way.