Home Technical Talk

3ds Max instance identical geometry script

polycounter lvl 8
Offline / Send Message
danshewan polycounter lvl 8
So after a quick search, I found this script that (apparently) does what it claims to - makes identical geometry instanced based on user-defined selections.

http://www.scriptspot.com/3ds-max/scripts/instance-identical-geometry?page=1

However, I'm wondering if anyone else has tried to use this with no success?

Firstly, I installed the v.1 script, ran it, crashed Max. The objects weren't particularly dense, nor were there hundreds of them (there was about 20 or so objects of about 70 triangles or so). So, I tried v.2, which as the comments on scriptspot indicate, had syntax errors.

I figured v.2.1 would be my savior, but alas, it isn't. No syntax errors when I try running it, but nothing happens either. No dialog box, no warnings, nothing. This script supposedly works on any version of Max, so I doubt it's a compatibility issue, and I'm using Max 2009 32-bit on Vista.

The comments after the 2.1 release suggest that the syntax errors were fixed and that the script supposedly works, so I'm at a loss as to why this isn't doing anything at all? This script really would save me a buttload of work, so has anybody else experienced this issue and resolved it, or found another script that does the same thing?

Replies

  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    the script itself seems to be rather simple and not what I expected :(
    -- array of properties to be compared // you could expand it with more...
    srcData = #(
    	classOf obj, 
    	(getPolygonCount obj) as string, 
    	obj.scale
    )
    -- collect identical
    local identical = for i in geometry where \
    	not areNodesInstances obj i and \
    	classOf i == srcData[1] and \
    	(getPolygonCount i) as string == srcData[2] and \
    	i.scale == srcData[3] collect i
    )
    
    So in summary it just compares the polygon count and scale value of objects in order to make out their matching. I was actually hoping for some topology comparison and only of the topology would be close enough it would replace things.
  • PolyHertz
    Options
    Offline / Send Message
    PolyHertz polycount lvl 666
    renderhjs wrote: »
    I was actually hoping for some topology comparison and only of the topology would be close enough it would replace things.

    Probably obvious, but all you'd have to do is after making sure the meshes edge count was the same is compare the edges lengths (based on #). Object scale differences would trow it off, so you'd have to take that into account.
  • danshewan
    Options
    Offline / Send Message
    danshewan polycounter lvl 8
    Well, I ended up reverting to version 1 and it worked, so problem solved for now. Seems pretty unstable though (though that could be my machine), wouldn't fancy having to use it on hundreds of reasonably complex objects.
  • NuggetOG
    Options
    Offline / Send Message
    Just edited the script and it now works fine. I have just tested it with 100+ models with 170 polys each.
    I think that the problem with the script is when the script loads up it is defining the local variable as 0 so that when the script runs it thinks there is no objects selected. This is causing the button to be greyed out.
    So by copying this line:
    local objSet = for I in selection where (getPolygonCount i) as string != "#(0,0)" collect i
    
    Into the main body of the script the script, just after on execute do, when the button is pressed the script recognises how many objects are selected and can convert the objects to instances.
    Also the line
    on isEnabled return (objSet.count != 0)
    
    is disabled to stop the button greying out altogether.
    So the edited script looks like this:
    /*
        Instance Identical Geometry
        v.2.0 [2010-06-03] by Anubis [project3d.narod.ru]
        Edited by Ed&Woody [15/12/2010]
        v.2.2
        
        
        What's new in version 2.0 :
            
    [*] proccess multiple (selected) objects at once
            
    [*] rollout (with pick button) removed
            
    [*] the script rewritten as macros
        
        To be instanced nodes need to match this criterions:
            identical class, face/verts count, scale
        You could expand it with more... (see the notes in the code)
    */
    macroScript Instance_Identical_Geometry
        buttonText:"Instance Identical Geometry" 
        category:"Tools" 
        internalCategory:"Tools" 
        tooltip:"Instance Identical Geometry" 
    (
        -- filter selection & get all geometry objects
        local objSet = for i in selection where (getPolygonCount i) as string != "#(0,0)" collect i
        print objSet.count
        
        --on isEnabled return (objSet.count != 0)
        on execute do
        (    
            local objSet = for i in selection where (getPolygonCount i) as string != "#(0,0)" collect i
            print objSet.count
            setWaitCursor()
            with redraw off
            (
                while objSet.count > 0 do
                (
                    obj = objSet[1]
                    deleteItem objSet 1
                    -- array of properties to be compared // you could expand it with more...
                    srcData = #(
                        classOf obj, 
                        (getPolygonCount obj) as string, 
                        obj.scale
                    )
                    -- collect identical
                    local identical = for i in geometry where \
                        not areNodesInstances obj i and \
                        classOf i == srcData[1] and \
                        (getPolygonCount i) as string == srcData[2] and \
                        i.scale == srcData[3] collect i
                    -- clean up objSet
                    for i in identical do (
                        dub = findItem objSet i
                        if dub != 0 do deleteItem objSet dub
                    )
                    instanceReplace identical obj -- mapped
                )
            )
            redrawViews()
            setArrowCursor()
        )
    ) --//eof
    
    
Sign In or Register to comment.