Community
3ds Max Modeling
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max modeling topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can I make detatched geometry generate its own pivot?

27 REPLIES 27
SOLVED
Reply
Message 1 of 28
Ryawy
1531 Views, 27 Replies

Can I make detatched geometry generate its own pivot?

I'm working with a base mesh and my project involves breaking smaller pieces off of it for lofting. When I use "Create Shape From Selection", the new shape inherits the pivot point of the shape it originated. This is irritating because I'm going to be doing a lot of lofting and, and needing to use "Center to Object" on the pivot points manually is going to slow me down a lot. Is there a setting or script that automatically assigns a new shape's pivot point to its center upon being created?

Tags (1)
27 REPLIES 27
Message 2 of 28
RobH2
in reply to: Ryawy

There might be a script but I don't know of one off hand.

 

If you've broken it up and now have a bunch of separate shapes, select them all and go to 'Hierarchy/Pivot' and select 'Affect Pivot Only' and then under 'Alignment' click 'Center to Object.' The pivot should now be moved to the center of each separate shape's invisible bounding box. 


Rob Holmes

EESignature

------------------------------------------------------------------------------------------------------------------------------------------
3ds Max (2023-2025), V-Ray 6.2, Ryzen 9 3950-X Processor, DDR 4 128MB, Gigabyte Aorus X570 Master motherboard, Sabrent Rocket NVMe 4.0 M.2 drives, NVidia RTX 4090, Space Pilot Pro, Windows 11 Pro x64, Tri-Monitor, Cintiq 13HD, Windows 11 x64
------------------------------------------------------------------------------------------------------------------------------------------
Message 3 of 28
Ryawy
in reply to: RobH2

I suppose I'm looking for a script, then. The thing I'm looking for is something that automatically performs the "Hierarchy/Pivot>Affect Pivot Only>Center To Object" when I separate the smaller shape from the whole.

Message 4 of 28
RobH2
in reply to: Ryawy

Unless someone else has a good way to do it you might consider posting this on the '3ds Max Programming' forum. I'm not a coder so I can't help there but there are some really talented users there. If it's a script you need, I'd bet someone there can assist you. 

 


Rob Holmes

EESignature

------------------------------------------------------------------------------------------------------------------------------------------
3ds Max (2023-2025), V-Ray 6.2, Ryzen 9 3950-X Processor, DDR 4 128MB, Gigabyte Aorus X570 Master motherboard, Sabrent Rocket NVMe 4.0 M.2 drives, NVidia RTX 4090, Space Pilot Pro, Windows 11 Pro x64, Tri-Monitor, Cintiq 13HD, Windows 11 x64
------------------------------------------------------------------------------------------------------------------------------------------
Message 5 of 28
leeminardi
in reply to: Ryawy

 

Try this script [edited 1/21/2024)

(
	obj = selection
	for o in obj do   
	(
		p = nodeGetBoundingBox o (matrix3 [1,0,0][0,1,0][0,0,1][0,0,0])
		o.pivot = (p[1] + p[2])/2. -- move the pivot
		resetXform o -- reset xform the object
		collapseStack o -- collapse modifier stack)
		updateShape o
	)
)

 

 

 

 

lee.minardi
Message 6 of 28
RobH2
in reply to: Ryawy

@Ryawy ...now we're talking. Got the pros @leeminardi on the case...!


Rob Holmes

EESignature

------------------------------------------------------------------------------------------------------------------------------------------
3ds Max (2023-2025), V-Ray 6.2, Ryzen 9 3950-X Processor, DDR 4 128MB, Gigabyte Aorus X570 Master motherboard, Sabrent Rocket NVMe 4.0 M.2 drives, NVidia RTX 4090, Space Pilot Pro, Windows 11 Pro x64, Tri-Monitor, Cintiq 13HD, Windows 11 x64
------------------------------------------------------------------------------------------------------------------------------------------
Message 7 of 28
Ryawy
in reply to: leeminardi

This is my first time using a script like this, so I'm not sure if it's working as intended. I have it saved and when I use "Run Script" it opens and performs the "Affect Pivot Only > Center to Object".  However, I need to go up click "Run Script" every time I want to perform the function again, and each time I make a new shape via "Create Shape From Selection" it still inherits the pivot of the mesh that it's being taken from. Can I make the script run automatically, or connect it to the "Create Shape From Selection" function? There doesn't seem to be a keyboard shortcut for "Run Script", at least that I can find.

Message 8 of 28
leeminardi
in reply to: Ryawy

I've made a minor edit in my last post to the code and have added the file Center pivots.01.ms (zipped).

 

To use it select as many objects as you like and then run the script via the Utilities Panel, Max script, Run script.

lee.minardi
Message 9 of 28
leeminardi
in reply to: Ryawy


@Ryawy wrote:

... to be a keyboard shortcut for "Run Script", at least that I can find.


Here's a brief tutorial on how to add a button to a toolbar t run the script.

lee.minardi
Message 10 of 28
dmitriy.shpilevoy
in reply to: Ryawy


@Ryawy wrote:

Can I make the script run automatically, or connect it to the "Create Shape From Selection" function?


Try this. I built on top of previous code, hopefully @leeminardi won't mind.
It expects Editable Poly object with selected edges.

 

macroScript toShapePivotCentered category:"Ryawy" (
	on execute do (
		obj = selection[1]
		if obj != undefined and classof obj == Editable_Poly do (
			edges = polyop.getEdgesByFlag obj 1
			if not edges.isEmpty do (
				newName = (uniqueName obj.name)
				obj.createShape newName 1 obj edgeFlags:1
				newShape = (getNodeByName newName)
				p = nodeGetBoundingBox newShape (matrix3 [1,0,0][0,1,0][0,0,1][0,0,0])
				newShape.pivot = (p[1] + p[2])/2. -- move the pivot
				resetXform newShape -- reset xform the object
				collapseStack newShape -- collapse modifier stack)
				updateShape newShape
			)
		)
	)
)

Message 11 of 28

@dmitriy.shpilevoy I welcome your edits and additions to my code.  I struggle  with Maxscript syntax and options.  I'm bascally an old school FORTAN coder with some experience with VBA and LISP.  My strength I feel is undertstanding the basic math manipulations as applied to CAD but determining what Maxscript functions and then the syntax to use them is a real battle for me.

 

I'd appreciate it if you could explain the purpose of the following lines of code from your post.   In particular,

 

Line #1 - what does this accomplish?  Wha can you do with "toShapePivotCentered" and "Ryawy"

Line #3 - having "obj = selection[1]" worked then it didn't until I changed it to "obj = selection".  I dont know wy he change helped.

Line #4 - I get that you are checking to see if something is selected and it's an Editable_Poly.  Should editbale_meshes also be acceptable?

Lines #5 and 6 - why the need to check for edges?

Lines #7 to 9 - why are these needed?

 

Thank you,

Lee

lee.minardi
Message 12 of 28

Heh, I'm almost your "evil twin brother" - not a programmer, terrible math skills. I'm an artist and used to weird methods to workaround max's... occasional unexpected behavior, maybe that's why maxscript looks normal to me.

Line #1

It defines macroscript so it can be used through Customize to put on toolbar or assign a hotkey for it.

 

Line #3

selection[1] just tells max "whatever is selected, use first of that" and yes, $ and "selection" can work for one thing, but throw an error for the other. Can't say I fully understand it, but usually can find a way to use it.

Line #4
Editable_mesh doesn't have a way to create shape from edges. Recreating it manually would be too complex for me. Easier approach is to convert to Poly first, but that might be undesirable for Ryawy.

Lines #5 and 6
If no edges selected there is nothing to create a shape from. Also script might crash when trying to do something like that.

Line #7
Creates unique name for new shape using original object's name as prefix. For me it makes sense - allows to figure out what it was made from. Might create a mess after working with few objects named "Box001", "Box002" etc, but I don't know how max file is organized.

Line #8
Creates shape from selected (flagged with 1) edges.

Line #9
I need to do a bunch of stuff with new shape, but when it's created, original poly object is still selected. Getting reference to shape by name since it seems like a proper way to do that without switching selection from poly to shape and then back. That would be slow with interface flickering.
Assigning it to variable because max documentation had suggestion of caching everything when possible and it's more convenient to work with for me.

At least that's what I think it does 😃

Message 13 of 28
leeminardi
in reply to: Ryawy

@dmitriy.shpilevoy thanks for the explanations.

I think what's  first needed to understand either of our codes is a statement of what is given, the action of the user, and then the result.  I assumed that the user woud perform a detach before execution of the max script and then select a bunch of objects.  After executng my code each object would have a pivot centered within its bounding box.

I think that you are assuming that the user has an object with the edge subobject selected and your code centers the pivot for each edge within the object.  Do you agree?

 

lee.minardi
Message 14 of 28
dmitriy.shpilevoy
in reply to: Ryawy

@leeminardi My edit supposed to mimic "create shape from selection" button, but with centering pivot for each created shape.

Message 15 of 28
Ryawy
in reply to: dmitriy.shpilevoy

Nothing is happening when I run it, but I'm not sure how much of it is just me not knowing how to use scripts. Also, I'm working in 2021, if that could make a difference in the scripting. I create a new script, paste in what you have here, then save it. Then I go to my editable poly, select the edges I want to use, and run the script. Is this correct?

Message 16 of 28
dmitriy.shpilevoy
in reply to: Ryawy

@Ryawy 

Save it as filename.mcr then drag-n-drop into max viewport.
Now in Customize / Hotkey Editor find "toShapePivotCentered" and assign it to some hotkey.
Select Editable_Poly object, select edges you want to create shape from and press hotkey you chose earlier.

 

dmitriyshpilevoy_0-1706076203952.png

 

Message 17 of 28
Ryawy
in reply to: dmitriy.shpilevoy

@dmitriy.shpilevoyI'm able to get it working from the hotkey itself working now! But now it's creating the shape but not centering the pivot. I tested @leeminardi 's script again and when I run it, it does the same as before; it centers the pivot to the whole object and does not create a shape. If these two functions really can't be combined, what would I have to add to make the first one hotkeyable too? Would it just be adding the first line?

Message 18 of 28
dmitriy.shpilevoy
in reply to: Ryawy

Pretty much. Wrap the code in 

 

macroScript NameForHotkeyEditor category:"Ryawy" (
	on execute do (
	-- code goes here
	)
)

 

 

 

Message 19 of 28
Ryawy
in reply to: Ryawy

Thank you. I should be able to make this work now. It's not perfect but it's the best possible result it seems. I'm trying to stitch them together myself and it's... not working, either.

 

Message 20 of 28
leeminardi
in reply to: Ryawy

@Ryawy I think part of the problem with getting a fully acceptable solution is how your original statement is being interpreted.  That is "...base mesh and my project involves breaking smaller pieces off of it for lofting". @dmitriy.shpilevoy assumed, I think, that "pieces" were single edges that had not been detached.  I assumed that the "pieces" could be a variety of objects that had already been detached.

 

A simple max file with an object showing a  "before" model and a corresponding "after" result would help to clarify your goal.

lee.minardi

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report