ScheduleField.SetStyle not working as I would expect

ScheduleField.SetStyle not working as I would expect

MattKincaid
Advocate Advocate
457 Views
4 Replies
Message 1 of 5

ScheduleField.SetStyle not working as I would expect

MattKincaid
Advocate
Advocate

I'm writing some code to modify the style of some cells in an existing schedule.  My code looks somethng like this.

 

Snippet

Private Sub test(field As ScheduleField)
 
    Dim style = New TableCellStyle
    style.FontHorizontalAlignment = HorizontalAlignmentStyle.Right
 
    field.SetStyle(style)
 
    Debug.Print(field.GetStyle.FontHorizontalAlignment.ToString)
 
End Sub

 

My debug.print statment prints "Center" everytime, which is unexpected to me.  What am I missing? All I'm trying to do is right align all the columns in a schedule.  Is there a better approach I should be taking?

 

I'm using 20150704_0715(x64), update release 9.  Thanks!

 

0 Likes
Accepted solutions (1)
458 Views
4 Replies
Replies (4)
Message 2 of 5

jeremytammik
Autodesk
Autodesk

Regenerate?

 

Commit?



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 5

MattKincaid
Advocate
Advocate

Thanks for the reply Jeremy.  Do you mean regenerating the document?  I sprinkled a few calls to the Regenerate routine into my test code (see below) and still experienced the same behavior. 

 

I'm committing the transaction several levels up in the call stack so it would be complicated to post the code here.  But I can do so if you really need it.  Just let me know. 

 

It's possible that I just have a fundamental misunderstanding regarding how transactions work.  In my sample code "field" is just a local variable that I'm passing into my routine.  I would expect any changes made to the "field" variable to be reflected even if I haven't committed the transaction. I expect that if it was an issue of not committing the transaction, my Debug.Print statement would still print "Right". Is that not how it works?  Do I need to commit the transaction immediately after my field.setStyle() call or something like that?

 

Thanks.

 

Snippet

Private Sub test(doc As Document, field As ScheduleField)
 
    Dim style = New TableCellStyle
    style.FontHorizontalAlignment = HorizontalAlignmentStyle.Right
 
    doc.Regenerate()
 
    field.SetStyle(style)
 
    doc.Regenerate()
    Debug.Print(field.GetStyle.FontHorizontalAlignment.ToString)
 
End Sub

 

0 Likes
Message 4 of 5

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Matt,

 

Yes, that is exactly what I meant.

 

I am not aware of any issues with these methods.

 

Have you taken a look at theScheduleAutomaticFormatter Revit SDK sample?

 

/a/lib/revit/2016/SDK/Samples/ScheduleAutomaticFormatter/CS/ScheduleFormatter.cs

 

That makes use of the SetStyle method.

 

If that does not help, all I can suggest is to implement an absolutely minimal reproducible case for the development team to analyse:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Preferable, an RVT file with an embedded macro that does nothing but the calls to set anf get the style.

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 5

MattKincaid
Advocate
Advocate

Thanks for pointing me to the sample code, Jeremy.  The problem was I wasn't doing the SetCellStyleOverrideOptions calls.  I didn't know you needed to do that.  Once I added that everything worked great.  Appreciate the help.

0 Likes