VB Scripting for Dynamos

We have decided to start using HCD graphics at our site and use the frsModules_Theme dynamo set.  I am creating my first custom dynamo to have a similar look as these dynamos.  I created my form, wrote my scripts, tested it and FAIL.  I have two questions about the VB scripting behind my form:

1.  The Edit script behind my dynamo has frmDyn.Open to open my form, but this only works if the form is on the current display.  I obviously don't want to have the form on every graphic.  How do I open the form if I store it in the User global file?

2. Below is a part of my UserForm_Active script.  I do not know how to set Objdynamo to the current dynamo object so it gives me an error when my form opens - "Object variable or With block variable not set".  So, my question is, how do I set Objdynamo equal to the current dynamo?

Dim objTest As Object

'Get Friendly Name
Set objTest = Nothing
Set objTest = findlocalobject(Objdynamo, "ps_FriendlyName")
If Not objTest Is Nothing Then
    FriendlyName.EditText = objTest.CurrentValue
End If

Thanks for any help,

Kevin

  • Kevin,

    Typically, a subroutine in a User.fxg module would open a form, also stored in User.fxg. In the example below, frmMyDynamoForm would be the name of your custom form. The subroutine passes the selected dynamo object to the form. The form would need to have objDynamo declared as a public global object (Public objdynamo As Object). Then you can pass the current dynamo object to the form and retrieve properties to populate your form, using the "if not objTest is Nothing" code you have above.


    Public Sub EditMyDynamo(objdynamo As Object)

    On Error GoTo ErrorHandler

    Dim frmDyn As New frmMyDynamoForm
    If Not frmDyn Is Nothing Then
    Set frmDyn.objdynamo = objdynamo
    frrDyn.Show
    Unload frmDyn
    Set frmDyn = Nothing
    End If

    Exit Sub

    ErrorHandler:
    frsHandleError

    End Sub


    The _Edit script of the dynamo object itself ("dynMyDynamo1" in the example below) would look like:


    Private Sub dynMyDynamo1_Edit()
    On Error GoTo ErrHandler
    EditMyDynamo dynMyDynamo1
    Exit Sub
    ErrHandler:
    frsHandleError
    End Sub
  • In reply to Ben Bishop:

    Ben,

    I am still missing something, because I can not get this to work. I still get an error when trying to edit my dynamo. When I compile my _Edit script on my dynamo I get: "Sub or Function not defined" and it highlights EditEMDynamo, which is the script I added to User.fxg. Below are my two scripts; any additional help would be greatly appreciated.

    This is in my User.fxg:

    Public Sub EditEMDynamo(Objdynamo As Object)
    On Error GoTo ErrorHandler

    Dim frmDyn As New frmEMDyn
    If Not frmDyn Is Nothing Then
    Set frmDyn.Objdynamo = Objdynamo
    frmDyn.Show
    Unload frmDyn
    Set frmDyn = Nothing
    End If

    Exit Sub

    ErrorHandler:
    frsHandleError
    End Sub

    And this is my dynamo script:

    Private Sub EM1_N__Edit()
    'Name: Tippe_1/EM1_N_ Version: 11.3
    On Error GoTo ErrHandler
    EditEMDynamo EM1_N_
    Exit Sub
    ErrHandler:
    frsHandleError
    End Sub
  • In reply to Ben Bishop:

    I did not know I had to put the script in a module, I had just placed it in with the other scripts on User.fxg. It works know that I created a module.
  • In reply to kdculb:

    Excellent! I'm happy you were able to make it work.
  • In reply to Ben Bishop:

    That's really useful. How would we suggest handling changes to ps_DataSourceNN parameter?

    I've implemented a update to a custom copy the MA3_CH dynamo to correct the pb_UserScale not displaying, and need to get expressions in the dynamo to DVSYS.MODULE to update.
  • In reply to gdpike:

    worked it out, using a number of help/web sources...

    when writing back values to objDynamo, i.e. in OK_click() subroutine, store strOldNode and strNewNode before/after updating ps_DataSourceNN, then execute

    If strOldNode <> strNewNode Then
    Dim blnSuccess as Boolean
    Find.Replace.FindReplaceInObject objdynamo, 8, strOldNode, strNewNode, blnSuccess
    'The 8 indicates to include search/replace in scripts
    End If