Adding a user macro - SmartPlant Foundation - IM Update 44 - Customization & Programming - Hexagon

SmartPlant Foundation Customization

Language
English
Product
SmartPlant Foundation
Search by Category
Customization & Programming
SmartPlant Foundation / SDx Version
10

There may be cases where items in the drawing cannot be hotspotted correctly using the hotspotter rules. The SmartConverter can be made to call a specified SmartSketch macro that can add hotspots.

To create such a macro, do the following:

  1. On the SmartPlant Foundation server, run the SmartSketch Macro Wizard (MacroWizard.exe) located in the C:\Program Files\SmartSketch\Macro Wizard folder.

  2. Use the wizard to create a SmartSketch macro, providing the necessary data.

  3. Open the project for your new macro in Visual Basic.

  4. Click Project > References

  5. Add a reference to Intergraph SPF42 - Hotspotter Utilities.

  6. Locate the Command Control in your project and edit the Initialize method.

    Here is example code that hotspots any text box whose text begins with the word "NOTE". Refer to the Hotspotter utilities component reference section for descriptions of the available methods and properties.

    Private Sub igCommand1_Initialize()

        ' Hotspotter Utilities component
        Dim objHSUtils As HSUtils
        Dim strCmdLineArgs As String
        Dim objApplication As Object
        Dim objDocument As SmartSketch.Document
        Dim objSheet As SmartSketch.Sheet
        Dim objTextBoxes As SmartSketch.TextBoxes
        Dim objTextBox As SmartSketch.TextBox
        Dim strText As String
        Dim bSts As Boolean
                
        On Error Resume Next

        ' Create a reference to the Hotspotter Utilities component
        Set objHSUtils = New HSUtils

        ' Get the command line arguments.  These must be passed
        ' to HotSpotObject
        strCmdLineArgs = igCommand1.CmdLineArgs
           
        ' Get the ActiveSheet
        Set objApplication = igCommand1.Application
        Set objDocument = objApplication.ActiveDocument
        Set objSheet = objDocument.ActiveSheet
           
        ' Example: Hotspot all text boxes that start with the
        ' string "NOTE"
        Set objTextBoxes = objSheet.TextBoxes
        If Not objTextBoxes Is Nothing Then
            For Each objTextBox In objTextBoxes
                strText = objTextBox.Text
                If StrComp(Left$(strText, 4), "NOTE", vbTextCompare) = 0 Then
                    ' Make sure it's not already hotspotted
                    bSts = objHSUtils.IsObjectHotSpotted(objTextBox)
                    If Not bSts Then
                        ' Hotspot this one
                        bSts = objHSUtils.HotSpotObject(strCmdLineArgs, _ objTextBox, strText, "IObject")
                    End If
                End If
            Next
        End If
           
    ExitSub:
        'Terminate the command
        igCommand1.Done = True

    End Sub

  7. In Visual Basic, click File > Make to compile the macro.

  8. In the Make Project dialog box, make sure that Visual Basic saves the macro in the SPFSmartConverter folder under the SmartPlant Foundation installation folder.

    Depending on the options chosen in the Macro Wizard, the compile will create a file ending in DLL or in OCX.Edit the SPFSmartConverter.ini file in the SPFSmartConverter subfolder. In the [UserMacros] section, create an entry for the macro you just created. The format of this line is Macro|RunWhen, where:

    • Macro is the file name of the macro DLL, followed by a double quote, and then by the user-chosen arguments.

    SmartPlant Foundation may pass additional arguments to the user macros, all of which will be prefixed with -spf (for example, ‑spfmapfile).

    • RunWhen may be "A" (run after the SmartConverter hotspot processing) or "B" (run before the SmartConverter hotspot processing).