Kean Walmsley

July 2009

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Twitter Updates

    follow me on Twitter



    « Creating a table of block attributes in AutoCAD using .NET - Part 1 | Main | One year wiser? »

    June 18, 2007

    TrackBack

    TrackBack URL for this entry:
    http://www.typepad.com/services/trackback/6a00d83452464869e200e008c560828834

    Listed below are links to weblogs that reference Creating a table of block attributes in AutoCAD using .NET - Part 2:

    Comments

    Kean,

    Thanks to your post I was able to get 1.5 rabits, I figured out how to set the precision on the formula output, by using the field \f flag. And this led me to understand one other problem.

    But I found a little problem I'm just not comprehending:

    Why is it that when I make a new table, I add my formulas and they work fine. But when make a change to an existing table, then formulas don't show up.

    So I have 3 subs all together, 1 sub creates a new table, 1 sub updates existing, and 1 sub populates the formulas.

    From the first both subs I'm calling the populate formula sub, which is this:

    Sub RecreateFormulas(ByVal objid As ObjectId)
    Dim tr As Transaction = db.TransactionManager.StartTransaction
    Try


    Dim tbl As Table = objid.GetObject(OpenMode.ForWrite)

    Dim bottomSection As Integer = tbl.NumRows - 2
    For y = 2 To tbl.NumRows - 3
    tbl.SetTextString(y, 5, "%<\AcExpr (A" & y + 1 & "*E" & y + 1 & ") \f ""%lu2%pr1"">%")
    Next

    tbl.SetTextString(tbl.NumRows - 3, 5, "%<\AcExpr (sum(F3:F" & tbl.NumRows - 3 & ")) \f ""%lu2%pr1"">%")
    tbl.SetTextString(tbl.NumRows - 2, 5, "%<\AcExpr (F" & tbl.NumRows - 2 & "*0.05) \f ""%lu2%pr1"">%")
    tbl.SetTextString(tbl.NumRows - 1, 5, "%<\AcExpr (sum(F" & tbl.NumRows - 2 & ":F" & tbl.NumRows - 1 & ")) \f ""%lu2%pr1"">%")


    Catch ex As Exception
    MsgBox(ex.Message)
    Finally
    tr.Commit()
    tr.Dispose()
    ed.Regen()
    End Try
    End Sub

    But I'm getting different results :(
    What gives?

    Thanks.

    First things first, Viktor: you're not using the transaction to open the table. You shouldn't mix the open/close model with transactions: we recommend using tr.GetObject() to open objects.

    Kean

    Kean,

    Thanks for your advice. I did notice that you use tr.getobject in your code, and that's probably the right way, but I'm following a book by Jerry Winters, and he always seems to follow this procedure:

    1. start transaction
    2. objid.getobject
    3. commit transaction

    Well, either way, I tried both of these scenarios and when updating the table for the second time, not all formulas come back :(

    I'm not a ADN member, and ever since the upgrade on discussion forum, I can't get in there. So between here and theswamp.org is all the expertise i can get :)

    Thanks.

    Viktor,

    Sorry - I'm really not able to help troubleshoot issues not specifically related to my posts. Perhaps someone on TheSwamp can help...

    Regards,

    Kean

    Well, if anyone is looking to resolve this same question, I thought I'd post a follow up, it looks like you have to clear the textstring from a formula before placing another one in there. I guess this kind of makes sense. Here's what I did:
    tbl.SetTextString(y, 5, "x")
    tbl.SetTextString(y, 5, _
    "%<\AcExpr (A" & y + 1 & "*E" & y + 1 & ")" & _
    "\f ""%lu2%pr1"">%")

    Viktor.

    Verify your Comment

    Previewing your Comment

    This is only a preview. Your comment has not yet been posted.

    Working...
    Your comment could not be posted. Error type:
    Your comment has been posted. Post another comment

    The letters and numbers you entered did not match the image. Please try again.

    As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

    Having trouble reading this image? View an alternate.

    Working...

    Post a comment

    Feed & Share

    Search