PDA

View Full Version : save Names to Maxfile - help please


JokerMartini
07-25-2011, 05:09 PM
I want to be able to run this script and it populate the drop down list with the Job Names , if they already exists in the maxfile. And if not then it will create the parameters to make it possible to save them in the file when a new one is created.
I've had some directional help pointed out by Anubis over on Script Spot but I have been unsuccessful in developing what I was hoping to achieve so far.
Below are two sets of code. The first one contains the UI that I have built for the creating of names and whatnot. Below that is the direction pointed out by other users to save those names with the maxfile. What is needed now is to combine the two and get something that works. I hope this all makes sense and that someone can help out.
Thanks
John


try(destroyDialog rlTestStore)catch()
rollout rlTestStore "Store with Maxfile"
(
local lstNamesArr = #()

fn fnUpdateNames =
(
rlTestStore.dlJobNames.items = lstNamesArr
)

button btnAddName "Add Name"width:124 height:18 pos:[10,6]
dropdownlist dlJobNames items:#() pos:[10,28]

on btnAddName pressed do
(
try(destroyDialog rlNewName)catch()
rollout rlNewName "New Name"
(
edittext etNewName "New Name: "

on etNewName entered txt do
(
appendifUnique lstNamesArr txt
fnUpdateNames()
try(destroyDialog rlNewName)catch()
)
)
createDialog rlNewName
)
)
createDialog rlTestStore 150 54




CA = attributes Names
(
parameters main
(
theNames type:#stringTab tabSizeVariable:true
)
)

--// variant #1 > add to rootNode
custAttributes.add rootNode CA
custAttributes.add rootscene CA

denisT
07-25-2011, 06:53 PM
may i show how i would do this task:

try(destroydialog str_list) catch()
rollout str_list "Names" width:200
(
local data_ch = 1967
local jobs = #()

dotNetControl ui_list "ComboBox" width:191 height:22 pos:[4,4]

on ui_list KeyUp s e do
(
case e.keyCode of
(
(e.keyCode.Enter): if finditem jobs s.text == 0 do
(
append jobs s.text
ui_list.items.add s.text
)
)
)

on str_list close do
(
setappdata rootnode data_ch (with printallelements on jobs as string)
)
on str_list open do
(
jobs = try (execute (getappdata rootnode data_ch)) catch(#())
if not iskindof jobs Array do jobs = #()
ui_list.items.addrange jobs
)
)
createdialog str_list


the thing #1 is to use most appropriate ui control. i'm using .net ComboBox
the thing #2:
i don't like to add CA to the scene root node. It works but might cause some problems.
i'm trying to use more safe way to store the data (specially if the data can be stored as string value) - AppData.

JokerMartini
07-25-2011, 07:09 PM
That was the problem I was having when I was trying to hack together the max combo box which isn't exactly the most user friendly. I'm not to familiar with dotNet controls. I've found myself getting more and more into them considering there controls and functionality is much better. I appreciate you taking the time to put together this example script. I'll be sure to learn from it. It makes complete sense on what way your doing it.
I didn't want to use the CA either because it just seems like a hackish way of doing things but sometimes those ways work best.

In this case i think what you've written here will work great.
Thanks again denisT

John

JokerMartini
07-25-2011, 07:25 PM
Is there a way to have it add the name to the array after hitting enter on the keyboard?

on ui_list entered txt do
(
append in unique
)

denisT
07-25-2011, 07:53 PM
Is there a way to have it add the name to the array after hitting enter on the keyboard?

on ui_list entered txt do
(
append in unique
)

if we talking about dotnetcontrol ComboBox the control doesn't have Entered event. In my sample i use KeyUp event where check if the Enter key was pressed.

JokerMartini
07-26-2011, 08:44 PM
That works. I ended up getting it to work out great.
Thanks for your help.

PEN
07-26-2011, 11:02 PM
What problems have you had with scene Defs Denis?

denisT
07-27-2011, 12:09 AM
What problems have you had with scene Defs Denis?
it was a bug i max (hopefully it's fixed in 2012)... when you merge or xref object or xref scene the system replace all current global CAs with merged one. so it's posible to replace most recent with its old version.
if i have CA added to rootnode, and the logic of the attribute designed for current scene, the xrefed scene might change the logic a bit, and it might crash the system.
what happens... you xref some scene into the current. fine... you don't see a catch in it. you save the file...
but there is a big chance to never open it again. and it's very hard to fine the problem.
usually this happens if new definition of CA and the old one have different param blocks.
does it make sense?

JHN
07-27-2011, 08:21 AM
Is this on the scene root node only or also if you create a custom trackview node.
I'm in the process of storing much data under a new trackviewnode, lets call it the NMTrix node.


newTrackViewNode "NMTrix"


Under this node I will store all our pipeline data, so now I'm working on a layer manager, which serializes all (most) layer properties in a string, so I can have multiple layer setups stored. This is stored in a CA with a stringTab param. Will I be in trouble when merging or Xreffing. I though this is safe as I see more tools do store to a custom trackviewnode, like SME for example, and I think RPM does it too.

Thanks,
-Johan

denisT
07-27-2011, 12:55 PM
the problem with replacing of CA after merge/xref occurs for any type of CA for any max version before 2012 (+ sp)
fatal crash was happened for me when i applied CA to rootnode or material. XrefMaterial system has a problem similar to rootnode. i didn't know about Global Tracks. it might be OK.

JokerMartini
07-27-2011, 04:21 PM
I'm having an issue when trying to store two variables on the rootnode? Why is that?
Here is my code.


try(destroyDialog ::rlNewJobName)catch()
rollout rlNewJobName "New Job Name"
(
local data_ch = 2000
local data_jL = 2001
local jobNames = #()
local jobLocation = ""

edittext etNewJobName "New:" fieldwidth:150 top:true pos:[10,10]
listbox lbJobNames "" items:#() width:179 height:6 pos:[10,34]
edittext etLocation "Location: " fieldwidth:128 top:true pos:[10,120]

on etNewJobName entered txt do --//Job Names
(
appendIfUnique jobNames txt
lbJobNames.items = jobNames
etNewJobName.text = ""
)

on etLocation entered txt do --//Save Location
(
etLocation.text = jobLocation = txt
)

on lbJobNames doubleClicked itm do
(
temp = lbJobNames.items
deleteItem temp itm
lbJobNames.items = temp
)

on rlNewJobName close do
(
setappdata rootnode data_ch (with printallelements on jobNames as string)
setappdata rootnode data_jL (jobLocation as string)
)

on rlNewJobName open do
(
jobNames = try (execute (getappdata rootnode data_ch)) catch(#())
jobLocation = try (execute (getappdata rootnode data_jL)) catch("")
etLocation.text = jobLocation as string
lbJobNames.items = jobNames
print jobNames
)
)
createDialog rlNewJobName 200 160

denisT
07-27-2011, 04:44 PM
I'm having an issue when trying to store two variables on the rootnode? Why is that?
Here is my code.


...
jobLocation = try (execute (getappdata rootnode data_jL)) catch("")
...

you don't need to execute string from channel data_jL. it's already string... it should by something:

local path = getappdata rootnode data_jL
if path == undefined or not doesfileexist path do path = ""

JokerMartini
07-27-2011, 05:26 PM
It is always showing up undefined.....?


try(destroyDialog ::rlNewJobName)catch()
rollout rlNewJobName "New Job Name"
(
local data_ch = 2000
local data_jL = 2001
local jobNames = #()
local jobLocation = ""

edittext etNewJobName "New:" fieldwidth:150 top:true pos:[10,10]
listbox lbJobNames "" items:#() width:179 height:6 pos:[10,34]
edittext etLocation "Location: " fieldwidth:128 top:true pos:[10,120]

on etNewJobName entered txt do --//Job Names
(
appendIfUnique jobNames txt
lbJobNames.items = jobNames
etNewJobName.text = ""
)

on etLocation entered txt do --//Save Location
(
etLocation.text = jobLocation = txt
)

on lbJobNames doubleClicked itm do
(
temp = lbJobNames.items
deleteItem temp itm
lbJobNames.items = temp
)

on rlNewJobName close do
(
setappdata rootnode data_ch (with printallelements on jobNames as string)
setappdata rootnode data_jL (jobLocation as string)
)

on rlNewJobName open do
(
jobNames = try (execute (getappdata rootnode data_ch)) catch(#())

local path = getappdata rootnode data_jL
if path == undefined or not doesfileexist path do path = ""

etLocation.text = jobLocation as string
lbJobNames.items = jobNames
)
)
createDialog rlNewJobName 200 160

denisT
07-27-2011, 05:34 PM
...
jobLocation = getappdata rootnode data_jL
if jobLocation == undefined or not doesfileexist jobLocation do jobLocation = ""
...
createDialog rlNewJobName 200 160


you didn't set jobLocation variable.

JokerMartini
07-27-2011, 05:43 PM
You know what,
I was just randomly typing text in to test it out not realizing there was a test for doesFileExist.


Thanks denisT for the help once again!

CGTalk Moderation
07-27-2011, 05:43 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.