PDA

View Full Version : custom gizmo


loran
10-20-2009, 10:46 AM
How can I create custom gizmo or geometry within my script? I am creating an explosion toolset and I want my bomb gizmo to be created from spline...

SyncViewS
10-20-2009, 11:46 AM
Hi Loran, take look at scripted manipulators, they provide drawing functions and mouse interaction checking to create custom gizmos.

- Enrico

PEN
10-20-2009, 12:25 PM
Or use a plugin helper class and build it in there. I have an example of one on my site and there is lots in the help file about it.

loran
10-20-2009, 01:10 PM
I am curently using a SphereGizmo and I want to have a specific design, I don't like manipulators. I want all to be in the script, no plug ins or something else to install

SyncViewS
10-20-2009, 01:18 PM
You can actually include a SimpleManipulator in a standard MacroScript, like a Rollout or a Structure, nothing more to add to a single scripted file, and really versatile. You can have a look at standard lightTool.ms code for a sample:

..\<MaxRoot>\stdplugs\stdscripts\lightTool.ms

- Enrico

loran
10-20-2009, 04:46 PM
Got it! I just spy how Paul Neal did is custom helpers ;)
By the way, is there a best way to do that?


rad = 15
c1=circle radius:rad
c2=circle radius:rad
c2.rotation = eulerangles 90 0 0
c3=circle radius:rad
c3.rotation = eulerangles 0 90 0
c4=circle radius:17
t1=text()
--t1.rotation = eulerangles -90 0 0
t1.size= rad-4
t1.text="bomb"
t1.pos = [0,-2.5,0]
converttosplineshape c1
converttosplineshape c2
converttosplineshape c3
converttosplineshape c4
converttosplineshape t1
addAndWeld c1 t1 0
addAndWeld c1 c2 0
addAndWeld c1 c3 0
addAndWeld c1 c4 0
c1.name="kaboom-BOMB"
c1.wireColor = [255,100,200]

Polimeno
10-21-2009, 04:05 PM
Hi Loran, take look at scripted manipulators, they provide drawing functions and mouse interaction checking to create custom gizmos.

- Enrico

yeah,
and i also suggest you to watch Boboīs MasterClass The Secret World of Scripted Manipulators. Youīre going to find a lot of usefull tips, specially in the chapter 06.

i cleaned up your code a little bit:

fn create_sphereGizmo thePrefix:"kaboom_" theName:"bomb" Rad:15 Colour:blue thePos:[0,-2.5,0] =
(
c1= circle radius:Rad wirecolor:Colour name:(thePrefix + theName)

c2 = copy c1 radius:Rad wirecolor:Colour
c2.objectOffsetRot = eulerAngles 90 0 0

c3 = copy c1 radius:Rad wirecolor:Colour
c3.objectOffsetRot = eulerAngles 0 90 0

c4 = circle radius:(Rad-2) wirecolor:Colour

t1=text size:(Rad-4) text:theName pos:thePos

converttosplineshape #(c1,c2,c3,c4,t1)

addAndWeld c1 t1 0
addAndWeld c1 c2 0
addAndWeld c1 c3 0
addAndWeld c1 c4 0
)


hope it helps

PEN
10-21-2009, 04:48 PM
Well if what you want is a spline based control that works just fine. You can also build the splines vert by vert which is the other way that I do it in some of those spline controls.

PEN
10-21-2009, 04:50 PM
"MasterClass The Secret World of Scripted Manipulators DVD"

Where would one find this?

Polimeno
10-21-2009, 11:30 PM
plugin simpleManipulator kaboom_Boom
name:"kaboom_Boom"
invisible:false
classID:#(0x662c3c16, 0x77a572f7)
category:"Manipulators"
(

local blueColor = blue/255.0
local orangeColor = orange/255.0
local whiteColor = white/255.0
local Pos = [0,0,0]
local Seg = 8
local Rad = 15

parameters main rollout:paramRollout
(
txt type:#string ui:ed_text default:"BOOM"
)

rollout paramRollout "Parameters"
(
edittext ed_text "Txt: " fieldWidth:140 align:#center labelOnTop:true
)

tool create
(
on mousePoint click do
(
case click of
(
1:
(
theTM = matrix3 1
theTM.row4 = gridPoint
nodeTM = theTM
#stop
) -- 1

2:
(
#stop
) -- 2

) -- end case

)

)

on canManipulate target return ( findItem(getPropNames target) #txt ) !=0

on updateGizmos do
(
this.clearGizmos()
local flags = 0

if (target != undefined)
then
(
this.txt = target.txt
)

--GIZMO 1
local c1 = (manip.makeCircle Pos Rad Seg)
this.addGizmoShape c1 flags blueColor orangeColor

--GIZMO 2
local theTXT = filterString txt "\n" splitEmptyTokens:true
for i = 1 to (theTXT.count) do
this.addGizmoText theTXT[i] Pos flags whiteColor orangeColor

return ( findItem(getPropNames this) #txt ) !=0
)

)


evalute and go to create tab> helpers> manipulators> kaboom_Boom

Bobo
10-22-2009, 12:20 AM
"MasterClass The Secret World of Scripted Manipulators DVD"

Where would one find this?

Subscription center, under Training > 3ds Max Training Videos (English) > Scripting and API

I went today to check it out and it turned out to be quite entertaining ;)

Polimeno
10-22-2009, 09:25 PM
Subscription center, under Training > 3ds Max Training Videos (English) > Scripting and API

I went today to check it out and it turned out to be quite entertaining ;)


i liked it a lot Bobo, itīs very interesting !! ;)

just one question:
why max loses my custom scripted manipulators when save/open scenes ?? what do i have to do to keep it working ?
itīs independent, it doesnīt need scene nodes and can be created by itself...

Bobo
10-22-2009, 09:49 PM
i liked it a lot Bobo, itīs very interesting !! ;)

just one question:
why max loses my custom scripted manipulators when save/open scenes ??
what do i have to do to keep it working ?

iīve attached my screen.

If it is a scripted plugin, it MUST be installed as a plugin.
In other words, the .MS file must be in a Plugins folder or a Scripts\Startup folder so it gets loaded when Max starts. Otherwise it is like trying to load a scene with a missing DLL...

Polimeno
10-22-2009, 10:26 PM
If it is a scripted plugin, it MUST be installed as a plugin.
In other words, the .MS file must be in a Plugins folder or a Scripts\Startup folder so it gets loaded when Max starts. Otherwise it is like trying to load a scene with a missing DLL...

great, now itīs working.

thanks again Bobo !!

Polimeno
10-27-2009, 09:16 PM
Ok,
so now i have a question:

how is the best way to copy/paste my customManip.ms file via MXS ??
i want to put it inside startup Script path automatically.

fileIn isnīt working as i expected....


get source path
main_Path = "Z:\\scripts"

get the .ms file
file_MXS = main_Path + "\\" + "customManip.ms"

copy the file from that and paste to startup Scripts
????


StartupScripts_Folder = getDir #StartupScripts



thanks in advance

Polimeno
10-28-2009, 01:32 PM
i can run it,
but i donīt know how to spread it inside the StartupScript directory...


-- source Directory
file_Type = "\\*.ms"
NetWork_Path = "W:\\Scripts_Max"
sub_Path = NetWork_Path + ("\\" + "custom_Manipulator")
-- return
--"W:\Scripts_Max\custom_Manipulator"

-- load all .ms files
load_MXS = getFiles (sub_Path + file_Type)
-- return
-- #("W:\Scripts_Max\custom_Manipulator\custom_Manipulator_07.ms", "W:\Scripts_Max\custom_Manipulator\custom_Manipulator_08.ms", "W:\Scripts_Max\custom_Manipulator\custom_Manipulator_CTRL.ms")

-- get StartupScript Path (target Directory)
StartupScripts_Folder = getDir #StartupScripts
-- return
-- "C:\Program Files\Autodesk\3ds Max 2009\scripts\startup"

-- get the last file
Count = load_MXS.count
customManip_MXS = load_MXS[Count]
-- return
--3
--"W:\Scripts_Max\custom_Manipulator\custom_Manipulator_CTRL.ms"

if (doesFileExist(customManip_MXS) == true )
then
(
-- test properties
getFileSize customManip_MXS
getFileAttribute customManip_MXS #directory

-- load
File_In = fileIn customManip_MXS

-- read & execute
File_Read = openFile customManip_MXS mode:"rt"
execute File_Read
File_Copy = save

format "% % % " (File_In as string) (File_Read as string) (StartupScripts_Folder as string)
)
-- return
--CTRL_ <File:W:\Scripts_Max\custom_Manipulator\custom_Manipulator_CTRL.ms> C:\Program Files\Autodesk\3ds Max 2009\scripts\startup OK
--OK



what am i missing ??

Bobo
10-28-2009, 02:26 PM
fileIn() SHOULD work.

You said it wasn't working as expected, what did you get when you tried and what did you expect to get? When you get errors or unexpected results, please tell us about them :)

fileIn() is equivalent to opening a file in the editor and pressing Ctrl+E or selecting Run Script from the MAXScript menu. If I had to do what you are trying to do, I would have used it.

FileIn() loads AND EXECUTES the script in global scope. So you don't have to execute() anything after that.

Polimeno
10-28-2009, 02:55 PM
fileIn() SHOULD work.

You said it wasn't working as expected, what did you get when you tried and what did you expect to get? When you get errors or unexpected results, please tell us about them :)

fileIn() is equivalent to opening a file in the editor and pressing Ctrl+E or selecting Run Script from the MAXScript menu. If I had to do what you are trying to do, I would have used it.

FileIn() loads AND EXECUTES the script in global scope. So you don't have to execute() anything after that.

after reading and evaluating the file - wich is fine using FileIn() , as you said -
i want to spread the .ms file automatically to my local StartupScript directory (search, read, load, copy and paste).

so, how can i do that ??
any ideas ?

Bobo
10-29-2009, 05:34 AM
after reading and evaluating the file - wich is fine using FileIn() , as you said -
i want to spread the .ms file automatically to my local StartupScript directory (search, read, load, copy and paste).

so, how can i do that ??
any ideas ?

You mean COPY the file to the directory?

copyFile sourceFilename targetFilename

Polimeno
10-29-2009, 03:17 PM
You mean COPY the file to the directory?

copyFile sourceFilename targetFilename

testing :

-- source Directory
file_Type = "\\*.ms"
NetWork_Path = "W:\\Scripts_Max"
sub_Path = NetWork_Path + ("\\" + "custom_Manipulator")

-- load all .ms files
load_MXS = getFiles (sub_Path + file_Type)

-- get stdplugs stdscripts Path (target Directory)
root_Path = (getDir #maxroot) + "stdplugs" + "\\stdscripts"
load_StdScripts = getFiles (root_Path + file_Type)
load_StdScripts.count

-- get the last file
Count = load_MXS.count
customManip_MXS = load_MXS[Count]

-- get file name
File_customManip = getFileNameFile customManip_MXS

-- copy file to its own directory
Copy_customManip = (getFileNamePath customManip_MXS) + "\\" + File_customManip + "_00.ms"
copyFile customManip_MXS Copy_customManip

-- returns
"\*.ms"
"W:\Scripts_Max"
"W:\Scripts_Max\custom_Manipulator"
#("W:\Scripts_Max\custom_Manipulator\custom_Manipulator_07.ms", "W:\Scripts_Max\custom_Manipulator\custom_Manipulator_08.ms", "W:\Scripts_Max\custom_Manipulator\custom_Manipulator_CTRL.ms")
"C:\Program Files\Autodesk\3ds Max 2009\stdplugs\stdscripts"
38
3
"W:\Scripts_Max\custom_Manipulator\custom_Manipulator_CTRL.ms"
"custom_Manipulator_CTRL"
"W:\Scripts_Max\custom_Manipulator\\custom_Manipulator_CTRL_00.ms"
true

BUT if i change the part --copy file to its own directory

to this :

-- copy file to target Directory
Copy_customManip = root_Path + "\\" + File_customManip + "_00.ms"
copyFile customManip_MXS Copy_customManip

-- returns
"W:\Scripts_Max\custom_Manipulator\custom_Manipulator_CTRL.ms"
"custom_Manipulator_CTRL"
"C:\Program Files\Autodesk\3ds Max 2009\stdplugs\stdscripts\custom_Manipulator_CTRL_00.ms"
false
OK

or this :

-- other target Directory
StartupScripts_Path = (getDir #startupScripts) + "\\"
Copy_again = StartupScripts_Path + File_customManip + "_00.ms"
copyFile customManip_MXS Copy_again

--returns
"C:\Program Files\Autodesk\3ds Max 2009\scripts\startup\"
"C:\Program Files\Autodesk\3ds Max 2009\scripts\startup\custom_Manipulator_CTRL_00.ms"
false

in both cases i got FALSE....
why ?? what am i missing ?

Bobo
10-29-2009, 07:07 PM
You can get false in several cases:

*The file is already there
*The path is wrong / folder does not exist yet
*You have no rights to write to that directory (which would be the case with Vista and UAC on since nobody can write to a Program Files subfolder).

Does any of these look like your case?

Polimeno
10-29-2009, 07:20 PM
You can get false in several cases:

*The file is already there
*The path is wrong / folder does not exist yet
*You have no rights to write to that directory (which would be the case with Vista and UAC on since nobody can write to a Program Files subfolder).

Does any of these look like your case?

yes, the third one...

do i have other options ?
is there any chance to populate my plugIn using macros ?

Bobo
10-29-2009, 08:42 PM
yes, the third one...

do i have other options ?
is there any chance to populate my plugIn using macros ?

Of course you do, this has been changed since Max 9 even before Vista came out.
For Macros, Icons and Startup Scripts there are alternative User paths that should be used to place custom MacroScripts, Icons and Script files.

Instead of hard-coding your paths, use the methods to get the system settings:

getDir #userstartupscripts

--on my WinXP machine returns:
"C:\Documents and Settings\bpetrov\Local Settings\Application Data\Autodesk\3dsMax\2010 - 64bit\enu\scripts\startup"

whereas

getDir #startupscripts
--returns
"C:\Program Files\Autodesk\3ds Max 2010\scripts\startup"

On Vista, these paths will be slightly different (they are under C:\Users\UserName\), but the general idea is that these paths are user-modifiable, while the C:\Program Files\ are not under Vista and Windows 7.

JHaywood
11-03-2009, 10:33 PM
Subscription center, under Training > 3ds Max Training Videos (English) > Scripting and API

I went today to check it out and it turned out to be quite entertaining ;)

I downloaded the subscription video, and of course it's great. But I don't see the notes and project files available. Any way I can get those too?

PiXeL_MoNKeY
11-03-2009, 10:39 PM
Those are on the info page that pops up when you click the link from the training page, right under the Presenter Biography.

-Eric

Polimeno
11-24-2009, 09:29 PM
Of course you do, this has been changed since Max 9 even before Vista came out.
For Macros, Icons and Startup Scripts there are alternative User paths that should be used to place custom MacroScripts, Icons and Script files.

Instead of hard-coding your paths, use the methods to get the system settings:

getDir #userstartupscripts

--on my WinXP machine returns:
"C:\Documents and Settings\bpetrov\Local Settings\Application Data\Autodesk\3dsMax\2010 - 64bit\enu\scripts\startup"

whereas

getDir #startupscripts
--returns
"C:\Program Files\Autodesk\3ds Max 2010\scripts\startup"

On Vista, these paths will be slightly different (they are under C:\Users\UserName\), but the general idea is that these paths are user-modifiable, while the C:\Program Files\ are not under Vista and Windows 7.

thanks a lot Bobo, now itīs working like a charm.

CGTalk Moderation
11-24-2009, 09:29 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.