ScriptSpot

Forum topic · General Scripting

Script for costing via attributes on objects

By Tim82 · 2012-04-15

Description

Hi there,

I'm trying to research whether or not I'm able to get a cost estimation from 3D max.
I haven't had much luck so far, but a guy on the CGTalk forums suggested that inside Maya, you can add attributes to objects.

After a search, I found that you can do this is 3D max too. Great news!

Can the scripting gurus here please tell me if this can be done;

Assign a number to an object (let's say 10 objects, numbered 1 to 10)

Somehow assign a price or a value to that number/object that can be tallied up as a total figure.

Make a script that grabs the number ID from all of the objects in a scene and tallies the cost attached to the ID number.

For example;

Couch/sofa has an attribute of 1. 1=$1000
Dining chair has attribute of 2. 2=$60
Table has an attribute of 3. 3=$500

Run Maxscript, 1+2+3=$1560

Can this be done? Or something similar, less clunky perhaps?

Thanks in advance,

Regards,
Tim.

Comments (1)

br0t · 2012-04-18

Heya,

that should not be a big problem. a very simple way to do it is this (not using indices, just the price itself):


try(destroyDialog roPriceCalc)catch()
rollout roPriceCalc "Price Tool" width:170 height:94
(
	button btnSet "Set price" pos:[103,7] width:61 height:27
	spinner spnPrice "" pos:[6,12] width:75 height:16 range:[-1e+007,1e+007,0] type:#float scale:1
	label lbl1 "$" pos:[85,13] width:16 height:16
	button btnGet "Calculate price of selection:" pos:[6,38] width:158 height:27
	label lblSum "" pos:[6,71] width:158 height:16 style_sunkenedge:true
	
	
	on btnSet pressed do
	(
		for s in selection do
		(
			setUserProp s "price" spnPrice.value
		)
	)
	on btnGet pressed do
	(
		local priceAll = 0
		for s in selection do
		(
			thePrice = getUserprop s "price"
			if thePrice != undefined do
			(
				priceAll += thePrice 
			)--end if
		)--end for
		lblSum.text = priceAll as String
	)
)
createDialog roPriceCalc

Can of course be improved in many ways. Works on selected objects. It uses the "User defined Properties" that can be set and edited manually by yourself for any object by rightclicking and looking inside the Object properties for the right tab. I have no idea why you would need a tool like this, but there you go. Do you plan to buy stuff for you household and make a layout in 3d first or what haha :D

Cheers