• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Inventor Engineer-to-Order

    Reply
    Distinguished Contributor
    ludesroc
    Posts: 134
    Registered: ‎05-03-2005

    How to make a rule update???

    120 Views, 4 Replies
    12-11-2012 11:22 AM

    How to make a rule update when making changes to SQL DB value?

     

    I'm using this method...

     

    Child IntentDbConnection As :dbConnection
    dataProvider = :smileyfrustrated:QLSERVER
    connectionString = "Data Source=" & dataSourceName & ";Initial Catalog=" & initialCatalogName & ";Integrated     Security=True"
    onNullReturn = ""
    showInModelBrowser? = True
    End Child

    ' Get the design data.
    Child DT_cDesign As :dbDataTable
    Connection = IntentDbConnection
    selectCommandText = "SELECT dbUniqueId, BaseStructureHeight, PanelDepthNumeric, UnitMounting FROM cDesign WHERE Name = '" & designName & "' "
    tableName = "cDesign"
    showInModelBrowser? = False
    End Child

    ' Get the base height.
    Uncached Rule BaseStructureHeight As String
    If DT_cDesign.RowCount > 0 Then
    Return DT_cDesign.getFieldValue(0, 1)
    Else
    Return ""
    End If
    End Rule

     

    When making changes to the field (i.e.BaseStructureHeight), the rule doesn't update!!! I tried Uncached but that doesn't work!!!

     

    Thanks!

    Luc

    Ludesroc
    Please use plain text.
    Employee
    AlexKorzun
    Posts: 71
    Registered: ‎11-10-2008

    Re: How to make a rule update???

    12-11-2012 04:11 PM in reply to: ludesroc

    Hi Luc,

     

    Several notes:

    1. dbDataTable stores the tabular data in memory. If you know that the data cannot change and access to it is frequent, then it is the right solution. If you need to re-read data from the Server, call DT_cDesign.Fill() Method in your rule BaseStructureHeight

     

    2. You may wish to consider another approach: perform the queries on IntentDbConnection child. The Methods of interest would be GetQueryResultsByRow or GetQueryResultsByColumn. The return value will be List of Lists. The translation between database and Intent data types is automatic. The documentation is available on Wiki.

     

    Uncached Rule BaseStructureHeight As String

    Dim result = IntentDbConnection.GetQueryResultsByRow("SELECT dbUniqueId, BaseStructureHeight, _

                         PanelDepthNumeric, UnitMounting FROM cDesign WHERE Name = '" & designName & "' ")

    '.... more logic

     


    End Rule

    Thank you,

    Alex Korzun
    Principal Engineer
    Inventor Engineer-to-Order
    Please use plain text.
    Distinguished Contributor
    ludesroc
    Posts: 134
    Registered: ‎05-03-2005

    Re: How to make a rule update???

    12-12-2012 10:30 AM in reply to: AlexKorzun

    Thanks Alex!

     

    Using either suggested methods works great. When evaluating the rule in the Immediate window, I get the updated value...

     

    However, I need to find a way to trigger the update of the model. Is there a way to accomplish that? Rigth now, the only way I can update the model is by modifying the Intent code. I saw (Root.RenderSelf) but that doesn't seem to work!!!

     

    Regards,

    Luc

    Ludesroc
    Please use plain text.
    Board Manager
    Posts: 196
    Registered: ‎08-23-2006

    Re: How to make a rule update???

    12-12-2012 05:06 PM in reply to: ludesroc

    Since rules always have the correct value, there is no built-in way to "update".  Of course, if you change a rule's formula, then all dependent rules will update automatically.  In your situation, the rules no longer have the correct value because they have an external dependency.  So the solution to "fake" changing the rule's formula.  You do this directly thru the Intent API if you have a custom UI, or thru the IDE.  You can either literally change the rule's formula, or you can "unbind" it.  In either case, all dependent rules will also be unbound.  Then when you do an update/render, they will all be recomputed with the new values.  Of course you only have to change something that the DB-related rule depends upon, such as its connection string or whatever, in order to get it to re-read the data from the DB.

     

    Hope this helps.

     



    Jon Balgley
    Autodesk Inventor ETO team
    Autodesk, Inc.

    Please use plain text.
    Distinguished Contributor
    ludesroc
    Posts: 134
    Registered: ‎05-03-2005

    Re: How to make a rule update???

    12-12-2012 06:08 PM in reply to: Jon.Balgley

    Ok thanks John!

     

    Will live with that for now! I guess we could had this to ETO Idea Station...Re-compute button!!!

     

    Regards,

    Luc

    Ludesroc
    Please use plain text.