MotionBuilder Forum
Welcome to Autodesk’s MotionBuilder Forums. Share your knowledge, ask questions, and explore popular MotionBuilder topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Spread.py and setting FBCellStyle

1 REPLY 1
Reply
Message 1 of 2
ReviveOften
335 Views, 1 Reply

Spread.py and setting FBCellStyle

I'm attempting to put various types into spreadsheet cells (buttons, vectors, ints, reals, etc)...w/o any luck.

In fact, I can not get the sample Spread.py (Running MoBu 2012) to populate the cells with any values other than the text field....

# From shipped code...


s = FBSpread()
s.Caption = "Spread"
mainLyt.SetControl("main",s)

s.ColumnAdd("Col 1")
s.ColumnAdd("Col 2")
s.ColumnAdd("Col 3")

s.RowAdd("Row 1", 0)
s.RowAdd("Row 2", 1)
s.RowAdd("Row 3", 2)

s.OnCellChange.Add(OnSpreadEvent)
s.OnRowClick.Add(OnSpreadEvent)
s.OnColumnClick.Add(OnSpreadEvent)
s.OnDragAndDrop.Add(OnDragAndDrop)

c = s.GetColumn(0)
c.Caption = "first column"
s.SetCellValue(0, 0, 3)
s.SetCellValue(0, 1, 3.1416)
s.SetCellValue(0, 2, "py = 3.1416")


# only populates cell 0,2 with the text.....any ideas?

signed confused....
-js
1 REPLY 1
Message 2 of 2
cmot
in reply to: ReviveOften

If you change those values to a string (and start them with a letter) those commands work.

It seems like there's something broken in the way the SetCellValue is working, because the docs say that it's supposed to set the FBSpreadCell.Style of the cell you're putting something in to match the data type of whatever you're putting in there. It looks like, by default, it only works with strings.

You can set the cell style yourself though, and this seems to work.


# set some initial values:
s.GetSpreadCell(0,0).Style = FBCellStyle().kFBCellStyleInteger
s.SetCellValue(0, 0, 3)
s.GetSpreadCell(0,1).Style = FBCellStyle().kFBCellStyleDouble
s.SetCellValue(0, 1, 3.1416)
s.SetCellValue(0, 2, "py = 3.1416")


I only spent a couple minutes looking this up, though, so there might be something more to this. It is odd, though, that the script that shipped with MB doesn't seem to work out of the box.

Edit:
Totally missed your first line. You can check out the fbcontrols.h File Reference page in the C++ docs to see all the cell styles. There's a Button style, but it doesn't look like you put a button in it, it just makes the cell look and act like a button with the caption set by giving it a string through SetCellValue.

Vectors would probably have to be handled by splitting each value out across 3 cells, not all in a single cell (unless you made it a string and handled it with some funky formatting behind the scenes).

Edit2:
Found the reason it's only accepting strings by default. If you don't set the cell style yourself, all the cells are created as kFBCellStyleString. Also, setting them to kFBCellStyleDefault results in them becoming kFBCellStyleString.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums