Need help on Modifier count check and checking if object is flat

Hi, I am trying to make a series of check on selected objects, before applying shell modifiers to it. Codes on Bottom of post.

1st check - if no objects selected, tell user to select plane, else if 1 or more objects
selected, move to 2nd check.

2nd check - if modifiers present on objects, tell user to collapse modifiers, else move to
3rd check.

3rd check - if objects selected not flat plane, tell user to select flat plane, else
apply shell modifiers to objects.

So far I have managed to script up to the 2nd check, however it works only when 1 object is selected. When i have multiple objects selected, this error occurs --Unknown property: 'modifiers' in $election. Can anyone help me to solve this problem and teach me how i can go about doing the 3rd check. Thanks!

Jason

on base150 pressed do
(
obj = selection as array
if selection.count == 0 then (messagebox "Select Plane" title:"Warning" beep:off ) else
(
if $.modifiers.count != 0 then (messageBox "Please collapse modifier stack!"
title:"Warning" beep:off) else
(
Shellmod = Shell()
Shellmod.selectOuterFaces = off
Shellmod.innerAmount = 0
Shellmod.outerAmount = 150
Shellmod.segments = 1

-- ModePanelup
max modify mode
ModPanel.AddModToSelection shellmod
)
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jahman's picture

.

do you really need all these warnings?

(
 
fn isPlane obj = isKindOf obj.baseObject Plane
 
fn isFlat  obj = (
	local bb = nodeGetBoundingBox obj obj.transform
	bb[2].z - bb[1].z < 0.001
)
 
validNodes = for obj in selection where isPlane obj and isFlat obj collect obj
select validNodes
convertToMesh validNodes -- force callapsing modifier stack
max modify mode
ModPanel.AddModToSelection (Shell selectOuterFaces:off innerAmount:0 outerAmount:150 segments:1)
 
)
JasonTeoJH's picture

Thank you!

Thanks for the reply! Really appreciate the time and effort you put into answering the questions.

As for your question, honestly? no. However, the 2 reason why i am doing this is because if there was no check, and i picked something not suitable, it would result in an error and i need to restart the script.

secondly I am really new to scripting, and i am learning by writing my own script for work, using all codes i can decipher online from tuts or other peoples's snippets of codes. Thus i would really like to know why the codes would result in that error and whats the way to solve it in that situation :)

jahman's picture

.

selection (is a collection of selected nodes) doesn't have modifiers property which you did try to access.
You need to iterate over selection to access each node separately.

fn checkNode obj = ... -- returns bool

for x in selection where checkNode x do ...

if you do it like this it will automagically skip all not suitable nodes
and even if selection is empty it will work with no explicit check

here's a greatest mxs forum on the planet which helped me really a lot in learning how to write scripts proper way

JasonTeoJH's picture

Thank you again!

Thank you Jahman, for explaining the mistake and your solution to me!

I actually have an account on cgs for about 10 years, i tried to ask a question a month ago and had no replies at all. T.T

Over here the people seems more friendly and open to help :)

Btw do you know where i can learn maxscript proper, can't even find an updated book on maxscript.

Jason

jahman's picture

.

I guess maxscript 101 could help you get started. It is still available on vimeo. But if you need a book I'd suggest you maxscript reference :)

Believe me it is not about people on cgs it all about level of questions. Mxs basics were explained so many times so it is easier to google the answer than to wait for one.
Try read others code. Find script that is most similar to your needs and learn by example.

ps. Search before asking and you'll make it.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.