Notifications
Clear all

[Closed] Unable to convert: undefined to type: Integer

can anyone helps me with my code pls? this is my first attempt writing a script n i m not very good at it… need help desperately !!! ^^

i run these code:
rollout unnamedRollout “Untitled” width:162 height:300
(
spinner spn1 “Slicing thickness (section)”
button btn1 “OK”

on spn1 changed step do
(
    s = #()                
    a = $.min.z            
    b = $.max.z            
    c = abs (b - a)            
    d = int (c/step)            
    for i=1 to d do
    (
        s[i] = section pos:[0,0,a] isSelected:on    
        a = a + step
    )    
)

on btn1 pressed do
(
    for i=1 to d do
    (
        ConvertToSplineShape s[i]            
        s[i].renderable = true 
    )        
)        

)

createDialog unnamedRollout 300 300

in the listener, i get error:
Rollout:unnamedRollout
true
OK
– Error occurred in btn1.pressed()
– Frame:
– d: undefined
>> MAXScript Rollout Handler Exception: – Unable to convert: undefined to type: Integer <<

any helps or hints for this?

6 Replies

How is this general discussion?

Maxscripting forum:

http://forums.cgsociety.org/forumdisplay.php?f=98

I don’t have max installed, but I’m guessing that ‘d’ is not global you probably need to put a line like ‘var d = 0’ outside both of the functions (my max-scripting is a little rusty so the syntax could be a little out, but this is a fairly common problem when you’re not paying attention to ownership of variables).

Just trying to help, maybe you havent declared the variables d and step? . I might be wrong if step is a predefined variable/function.

The problem is both c and step are 0. If you try to divide anything by 0 it will return the value “undefined”.

replacing

d = int (c/step)

with d = int (c/(step+1))

fixed it

If step is a varible of the spinner object, then you might be able to set the range on the spinner to 0.001 +

thank you for all your replies…
regarding the script you wrote, i did actually make number for each section shape created at the same level
but then do you think it is possible to make numbers inside the boundaries (between outer boundary and inner boundary) on the 2d shape created?
i suppose it would involve finding the boundaries on the 2d shape, adjusting the size and position of the text…
ignore me if you find me rather annoying ^.^
i appreciate all the works u made for me anyway…

If I understand you correctly, you want to find out the number of shapes in each slice which could range from 1 to N, N being the max number of shapes.

 Right now as it stands there is an issue, the section tool converts everything it intersects with into one shape, that can have any number of segments to create a spline.  The segments might look like a complete  spline but they are not, open one of them up and you will find the splines inside the shapes are a collection of disconnected segments whose start and end points overlap.

 You would need to find a way to collapse those overlapping segment start and end points into one long spline, sometimes they will connect with one another other times they will not.

 Next step would be to find a way to separate those long splines from one another into individual splineshapes,  once you have them as individual splineshapes its just a matter of collecting them and applying a number to the center of those splineshapes.

The best way I can think of to do this is to:

[ol]
[li]Take one slice that was created and to go through and collapse all the overlapping vertices[/li][li]Separate the splines that are created by collapsing the vertices from one another into there own splineshapes[/li][li]Find the center of the each splineshape that was extracted[/li][li]Place a number in the center of the splineshap[/li][li]Merge the splineshape and number text together.[/li][/ol]
Remember the “holder_ary” variable that is created in the button handler? Well that is a collection of your slices that were created in variable form. Simply create a ‘for loop’ that runs those 5 process above for each item in the “holder_ary” collection.

 At the moment I do not have the time to build an example of code but this is the architecture for the process I would follow to develop the code.