Author Topic: Reset Xref/Collapse/Edit Poly  (Read 3982 times)

2023-01-26, 08:30:12

aaouviz

  • Active Users
  • **
  • Posts: 886
    • View Profile
    • Another Angle 3D
I'm a big fan of speeding up my workflow as much as possible... I'm not great with scripting but I get by with basic skills.

One thing I've never been able to figure out is how to make a multi-command script (accessible by toolbar button OR hotkey OR both?) is:
 - (with selected object)
 - Reset Xref, then
 - Collapse, then
 - Convert to Edit Poly

I find myself doing this hundreds of times when setting up a new imported file.

Does this tool exist? If not, are there any super smart scripters out there that can quickly help me out?

Thanks for any tips!
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-01-26, 09:51:53
Reply #1

James Vella

  • Active Users
  • **
  • Posts: 537
    • View Profile
I assume you mean Reset Xform instead of Reset Xref?

You could do this for multiple objects by using this code:

Code: [Select]
for obj in selection do
(
  ResetXForm obj
  ConvertToPoly obj
)

Copy this into your Maxscript editor:
editor" border="0

Then drag and drop to your toolbar, it will create a button
drag" border="0

You can then right click on that button, change the icon/name etc.


2023-01-26, 10:10:24
Reply #2

aaouviz

  • Active Users
  • **
  • Posts: 886
    • View Profile
    • Another Angle 3D
Hi James - you are indeed right with your assumption... ugh I'm obviously tired...

I'll test this out and let you know how I go. A million thanks for the help mate!
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-01-26, 10:15:52
Reply #3

James Vella

  • Active Users
  • **
  • Posts: 537
    • View Profile

2023-01-26, 10:35:50
Reply #4

aaouviz

  • Active Users
  • **
  • Posts: 886
    • View Profile
    • Another Angle 3D
Oddly enough, every time I drag into the toolbar Max decides to crash.

I've made previous little script toolbar buttons with the following code (and adding the toolbar button via the settings)

macroScript 'NAME'
   category:"AAScripts"
   toolTip:""
( code here
)

I tried adapting this with your code but getting errors.

Any idea where I'm going wrong?
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-01-26, 10:39:31
Reply #5

James Vella

  • Active Users
  • **
  • Posts: 537
    • View Profile
Did you drag and drop the exact code I wrote? Or did you edit it with your code?

I suggest copy it as I have first, test that if it works, if it crashes let me know.

Also which 3dsmax version are you using?

FYI if you are going to put your code then you need to evaluate the script, drag and drop wont work, it only works for code without the header, so for example:

Code: [Select]
macroScript ResetAndCollapse
   category:"AAScripts"
   toolTip:"ResetAndCollapse"
   
(
for obj in selection do
(
  ResetXForm obj
  ConvertToPoly obj
)
)

Once this is in your Editor you press CTRL+E (not drag and drop).

You can then go to Customize > Customize User Interface > Toolbars
toolbar" border="0
« Last Edit: 2023-01-26, 10:47:53 by James Vella »

2023-01-26, 10:40:59
Reply #6

aaouviz

  • Active Users
  • **
  • Posts: 886
    • View Profile
    • Another Angle 3D
Yes, was crashing with your code exactly.

Very odd.

Max 2023.1


When I try to run it with my own code (below) this is the error:
- Runtime error: ResetXForm requires a node

Code: [Select]
macroScript AAResetXformCollapse
category:"1AAScripts"
toolTip:""
for obj in selection do
(
  ResetXForm obj
  ConvertToPoly obj

)
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-01-26, 10:49:32
Reply #7

James Vella

  • Active Users
  • **
  • Posts: 537
    • View Profile
you are missing another set of parenthesis, check my code above. I don't use 3dsmax 2023, so if its still an issue after using the additional parenthesis you might need someone who's using the latest version to help.

2023-01-26, 10:50:26
Reply #8

aaouviz

  • Active Users
  • **
  • Posts: 886
    • View Profile
    • Another Angle 3D
Yes, was crashing with your code exactly.

Very odd.

Max 2023.1


When I try to run it with my own code (below) this is the error:
- Runtime error: ResetXForm requires a node

Code: [Select]
macroScript AAResetXformCollapse
category:"1AAScripts"
toolTip:""
for obj in selection do
(
  ResetXForm obj
  ConvertToPoly obj

)

P.S. I don't think it's your code that's causing the crash but rather something buggy with my max...
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-01-26, 10:53:19
Reply #9

James Vella

  • Active Users
  • **
  • Posts: 537
    • View Profile
Make sure you add the additional parenthesis:

Code: [Select]
macroScript ResetAndCollapse
   category:"AAScripts"
   toolTip:"ResetAndCollapse"
   
(
for obj in selection do
(
  ResetXForm obj
  ConvertToPoly obj
)
)

2023-01-26, 10:55:25
Reply #10

clemens_at

  • Active Users
  • **
  • Posts: 140
    • View Profile
btw soulburnscripts has this functionality too:


2023-01-26, 11:03:17
Reply #11

aaouviz

  • Active Users
  • **
  • Posts: 886
    • View Profile
    • Another Angle 3D
btw soulburnscripts has this functionality too:



Doesn't seem to work with 2023 unfortunately.

(Or, it is crashing for me, at least).
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-01-26, 11:07:18
Reply #12

aaouviz

  • Active Users
  • **
  • Posts: 886
    • View Profile
    • Another Angle 3D
Hi,

I am SO sorry to be one of those annoying-people-you're-helping-with-nothing-in-return... BUT

Please see attached screencapture.

Either I'm doing something wrong, or something buggy is up with my max. Either is very likely...

Can you spot a problem? Thanks again James you're skills are impressive
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-01-26, 11:10:52
Reply #13

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 8848
  • Let's move this topic, shall we?
    • View Profile
    • My Models
I use transform toolbox for this. It lets you reset transforms without adding modifier in the stack. Single press of a button and no need to constantly go to utilities panel and collapsing the stack. On top of that it also has some quick pivot alignment and other useful tools. I always summon this window at the start of modelling sessions and park it somewhere in the corner. I would permanently dock it in a toolbar, but unfortunately that way it creates too much wasted space.
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2023-01-26, 11:11:48
Reply #14

clemens_at

  • Active Users
  • **
  • Posts: 140
    • View Profile
Quote
Doesn't seem to work with 2023 unfortunately.

(Or, it is crashing for me, at least).

works fine in 2023.1 here...

2023-01-26, 11:12:55
Reply #15

aaouviz

  • Active Users
  • **
  • Posts: 886
    • View Profile
    • Another Angle 3D
Quote
Doesn't seem to work with 2023 unfortunately.

(Or, it is crashing for me, at least).

works fine in 2023.1 here...

Damn... obviously something up with my max then. Very curious infuriating...

Thanks for the suggestion and follow-up.
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-01-26, 11:17:18
Reply #16

James Vella

  • Active Users
  • **
  • Posts: 537
    • View Profile
Hm, I was just reading that the convert editable poly could have different syntax in 2023, you could try this but its a long shot.

Code: [Select]
for obj in selection do
(
  resetXForm obj
  convert obj #editable_poly
)

I think someone using 3dsmax 2023 could debug this one better than I could at this stage.

edit:
I had #polymesh before, I updated it to editable_poly, apparently you can use these... 'polymesh','editable_mesh','editable_poly' etc.
The reset xform could also be different in 3dsmax 2023...
« Last Edit: 2023-01-26, 11:33:28 by James Vella »

2023-01-26, 16:13:20
Reply #17

Ink Visual

  • Active Users
  • **
  • Posts: 169
    • View Profile
This won't help you with writing your own script, but in case you're also looking for a solution to this, Assembly Tool Plugin (free) has a function that does exactly what you described.
It's called "Prepare Models for Work"


2023-01-26, 16:32:26
Reply #18

Aram Avetisyan

  • Corona Team
  • Active Users
  • ****
  • Posts: 561
    • View Profile
If it is not working, you are most probably missing the "on execute" line.
Here is the script I wrote for exactly this, it also brings the pivot to XY center and Z min:

macroscript My_macro category:"Aram Avetisyan" tooltip:"Xform, Poly, Pivot XY Center Z Min"
(
 on execute do
 (
    for _ in $ do
    (
       resetxform _
       convertTo _ EditablePolyMesh
       _.pivot = [_.center.x, _.center.y, _.min.z]
    )
 )
max modify mode
)


You can then assign a hotkey for it in Hotkey manager.

Cheers.
Aram Avetisyan | chaos-corona.com
Chaos Corona Support Representative | contact us

2023-01-26, 19:32:40
Reply #19

aaouviz

  • Active Users
  • **
  • Posts: 886
    • View Profile
    • Another Angle 3D
If it is not working, you are most probably missing the "on execute" line.
Here is the script I wrote for exactly this, it also brings the pivot to XY center and Z min:

macroscript My_macro category:"Aram Avetisyan" tooltip:"Xform, Poly, Pivot XY Center Z Min"
(
 on execute do
 (
    for _ in $ do
    (
       resetxform _
       convertTo _ EditablePolyMesh
       _.pivot = [_.center.x, _.center.y, _.min.z]
    )
 )
max modify mode
)


You can then assign a hotkey for it in Hotkey manager.

Cheers.

Wow, this one works. Thanks mate.

One issue; it doesn't to the Collapse of multiple objects though. Do you think this is somehow possible?
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2023-01-27, 15:59:13
Reply #20

Aram Avetisyan

  • Corona Team
  • Active Users
  • ****
  • Posts: 561
    • View Profile
The script above is intended not quite for what you are saying. Imagine you want to Reset Xform and center the pivot for 100 objects, but you don't need to attach them.
I would suggest doing the attaching separately, there are already good native tools for it.

I will try to test the attaching functionality for the script when I have time. But you would really need to have this functionality separately.
Aram Avetisyan | chaos-corona.com
Chaos Corona Support Representative | contact us

2023-10-10, 11:41:29
Reply #21

aaouviz

  • Active Users
  • **
  • Posts: 886
    • View Profile
    • Another Angle 3D
Man, I suck at maxscript...

I want to make a simple "Save and then Exit" script (via toolbar button).

This is what I have, but I can't quite get it to work as intended. Any helpers out there? Many thanks!

Code: [Select]
--Original script by: aaouviz
------

macroscript SaveAndExit
category: "AAScripts"
buttonText: "Save and Exit"
tooltip: "Save and Exit"
Icon:#("AAGen_01",1)


(
saveMaxFile
)
quitmax #noprompt
Nicolas Pratt
Another Angle 3D
https://www.instagram.com/anotherangle3d/

2024-01-04, 23:51:12
Reply #22

Okmijun

  • Active Users
  • **
  • Posts: 25
    • View Profile
Hi,
I am SO sorry to be one of those annoying-people-you're-helping-with-nothing-in-return... BUT
Please see attached screencapture.
Either I'm doing something wrong, or something buggy is up with my max. Either is very likely...
Can you spot a problem? Thanks again James you're skills are impressive

Do not worry, me too!
I have some ideas for scripting, to speed up workflow

1. use some batch merge script /there are a few of them/
2. explode and attach every file imported via batch merge script.

Basically, we should combine functionality of 2 scripts, merging, and attaching into poly.

merge
https://www.scriptspot.com/3ds-max/scripts/batch-merge
and soulburns attachselectedobjects
with pivot in center base, ofcourse!
furher more, we could incorporate multialign script to align them into raws...
and with few clicks, you have whole afternoon of work.

I hope I was clear enough what did I want to explain.