Solid ops and subroutines

Home Forums Problems and solutions in GDL 3D modelling Solid ops and subroutines

This topic contains 3 replies, has 3 voices, and was last updated by  Nader Belal 5 months, 3 weeks ago.

  • Author
    Posts
  • #3709

    James Murray
    Participant

    I’m getting inconsistent results depending on whether ADDGROUP is used in a subroutine or in the main script. Example:

    Version 1, add groups in main script, works:

    GROUP ‘things’
    	etc
    ENDGROUP
    
    GOSUB 100
    
    foobar_ = ADDGROUP(‘foo’, ’bar’) !! NB, in main
    final_ = SUBGROUP(foobar_, ‘things’) !! this works
    PLACEGROUP final_
    
    END
    
    100:
    
    GROUP ‘foo’
    	stuff
    ENDGROUP
    
    GROUP ‘bar’
    	more stuff
    ENDGROUP
    
    RETURN

    Version 2, add groups in subroutine, doesn’t work:

    GROUP ‘things’
    	etc
    ENDGROUP
    
    GOSUB 100
    
    final_ = SUBGROUP(foobar_, ‘things’) !! this gives error that foobar_ isn’t group name
    PLACEGROUP final_
    
    END
    
    100:
    
    GROUP ‘foo’
    	stuff
    ENDGROUP
    
    GROUP ‘bar’
    	more stuff
    ENDGROUP
    
    foobar_ = ADDGROUP(‘foo’, ’bar’) !! NB, in subroutine
    
    RETURN

    James M

  • #3710

    James Murray
    Participant

    Wow that formatting looks great. Never mind. If you want to use an ADDGROUP result in a subsequent SUBGROUP operation, you can’t do the ADDGROUP in a subroutine. It would be nice to know why.

    James M

  • #3711

    Péter Baksa
    Participant

    Hi James,

    the GDL interpreter runs some checks before executing the script. This check is done line-by line, not in execution order. In version 2 when it first comes to foobar_, that is an uninitialized variable, but it would expect string or group type. Sadly we can’t easily initialize a variable to be group type.
    A solution:
    – move the subgroup and placegroup commands to another subroutine, placed after subroutine 100
    Less elegant solution if the above doesn’t work for your code structure:
    – initialize group type variable: create an empty group and add it to itself, creating a group type variable

    group “dummy”
    endgroup
    foobar_ = ADDGROUP(“dummy”, “dummy”)
    killgroup “dummy”

    GOSUB 100

    Péter Baksa
    Software Engineer, Library Team
    GRAPHISOFT SE

  • #4782

    Nader Belal
    Participant

    My 2 cents,

    This group structure is neither nice, nor clean, and it may cause a lot of confusion when the times arrives for code maintenance, all because the followed structure.

    My solution

    
    gosub 100
    
    bla ... bla ... bla
    
    end
    
    100:
    
    GROUP ‘things’
    	etc
    ENDGROUP
    
    if something then
    	GROUP ‘foo’
    		etc
    	ENDGROUP
    
    	GROUP ‘bar’
    		etc
    	ENDGROUP
    end
    
    ! -- Group placements --------------- 
    
    if nothing then
    	placegroup ‘things’
    
    	killgroup ‘things’
    end
    
    if something then
    	placegroup subgroup (addgroup (‘foo’, ’bar’), ‘things’)
    
    	killgroup ‘things’
    	killgroup ‘foo’
    	killgroup ‘bar’
    end
    
    return
    

You must be logged in to reply to this topic.