[Maxscript] Creating Objects on Relative Position

polycounter lvl 4
Offline / Send Message
silver_hoodlum polycounter lvl 4
Hi guys,

I just started learning Maxscript and some of you might find my problems quite dummy.

What I'm trying to achieve is to get the boxes I create (purple) snapped to the faces of an existing object (green one). I guess there is various ways of doing this.

Snap_Face_to_Face_Problem.jpg

Snap_Face_to_Face_Problem_2.jpg
I created a script which sets up the pivot points and moves it at the end of the existing object position, but is a very ineffective way of doing it.

I've seen online people suggest using rayintersect or coordsys.

Any recommendations to get this?

Thanks in advance

Replies

  • monster
    Online / Send Message
    monster Polycount Sponsor
    You should post the code that is not working, with a comment on where you think there is a problem.

    Also, how is this different from Object Painter in the Ribbon? Or maybe Normal Align?
  • Joost
  • silver_hoodlum
    Offline / Send Message
    silver_hoodlum polycounter lvl 4
    @monster you can see down my current code. This tool works perfectly but I want this to snapped to a face of an existing box. I know how to script the pivot point but dont know how can place it exactly snaped with a face :( at the moment. Any idea?

    @joost ill check if it can be used

    rollout Boxtool "Box Creator"
    (
    spinner count "Number:" type:#integer range: [1,100,10]
    spinner size "Box Size:" range: [1,100,8]
    spinner distance "Distance Inbetween:" range: [1,200,25]
    button create "Create Boxes"

    on create pressed do
    for i in 1 to count.value do
    box length: (10) width: (size.value) height: (10) position:[i*distance.value,0,0]
    )

    MainFloater = NewRolloutFloater "Box Creator" 250 150
    addRollout Boxtool MainFloater
  • monster
    Online / Send Message
    monster Polycount Sponsor
    The tool needs to be much more complex to handle what you want to do. Here's a quick example below.
    (
    	rollout Boxtool "Box Creator"
    	(
    		spinner count "Number:" type:#integer range: [1,100,10]
    		spinner size "Box Size:" range: [1,100,8]
    		spinner distance "Distance Inbetween:" range: [1,200,25]
    		pickbutton create "Create Boxes" width:120
    		
    		--GET AN OBJECT TO CREATE OTHER OBJECTS ON
    		on create picked obj do
    		(
    			if isValidNode obj do
    			(
    				--GET THE MOUSE RAY FROM THE USER CLICK
    				intRay = intersectRay obj (mapScreenToWorldRay mouse.pos)
    				
    				--CREATE A TRANSFORM FROM THE RAY INTERSECT WITH SURFACE
    				creationTransform = matrixFromNormal intRay.dir * transMatrix intRay.pos
    				
    				--CREATE BOXES IN THE NEW TRANSFORM
    				in coordsys creationTransform
    				(
    					for i in 1 to count.value do
    					(
    						b = box length: (10) width: (size.value) height: (10)
    						
    						--ROTATE AND PLACE THE BOX
    						b.transform = creationTransform
    						b.pos = [(i-1)*distance.value,0,0]
    					)
    				)
    			)
    		)
    
    	)
    
    	MainFloater = NewRolloutFloater "Box Creator" 250 150
    	addRollout Boxtool MainFloater
    )
    
  • silver_hoodlum
    Offline / Send Message
    silver_hoodlum polycounter lvl 4
    @monster thanks for this monster, i will analyse it and get back. This is definitely the kind of stuff pushed me into learning scripting and technical stuff. Is such a pity there are only a few basic tutorials of maxscript online, find it hard sometimes to get a starting point.
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 7
    @monster thanks for this monster, i will analyse it and get back. This is definitely the kind of stuff pushed me into learning scripting and technical stuff. Is such a pity there are only a few basic tutorials of maxscript online, find it hard sometimes to get a starting point.

    CgSociety, Maxscript documentation and analyzing other peoples scripts is pretty much the way I learned Maxscript. Though thats also how I learn other languages so might be different per person.
Sign In or Register to comment.