[VBA] Need help with MDL Wrapper Function for mdlSheetDef_setBorderAttachmentId

The documentation when followed generates the following error message:

Bad DLL calling convention (Error 49)

While this error has a help page, it does not explain any specific corrective action that can be done.

The Wrapper statement, from the MDL help is:

Declare Function mdlSheetDef_getBorderAttachmentId Lib "stdmdlbltin.dll" ( ByVal sheetDefIn As Long , ByRef borderAttachmentIdOut As DLong ) As Long

There is also a property in the VBA SheetDefinition object named MdlSheetDef that, according to its help "Retrieves the associated SheetDef pointer that a program can use as an argument to MDL mdlSheetDef functions."

With no example, we cannot determine how to use this or even if this is the way to use the subject wrapper function.

We seem to have hit a brick wall on this and need help from a Bentley Programmer.

Parents
  • I'm sorry to say the wrapper function matches the documentation.  The wrapper function requires an ElementId passed by value but VBA does not support it. The only way to pass the element ID to the wrapped function is to use the CExpression support.  For example,

        Dim theAddr As Long

        Dim id As DLong

        id.Low = 1111

        expr = "mdlSheetDef_setBorderAttachmentId((void*)" & theAddr & ", " & DLongToString(id) & ")"

        GetCExpressionValue expr

    The CExpression scanner only supports 32-bit integers so this only supports element ID's up to 2147483647.  I don't think that is a problem as it takes a long time to go through 2 billion element ID's.

    John Gooding

  • OK, this is my code from the earlier post:

    Sub changeModelType2Sheet()
        Dim thisModel As ModelReference, refBorder As ModelReference
        Dim thisSheet As SheetDefinition
        Dim refBorderElID As DLong
        
        Set thisModel = ActiveModelReference
        ' Assume 1st reference file slot for now
        Set refBorder = ActiveModelReference.Attachments(1)
        ' This next line changes the model type to a sheet
        thisModel.Type = msdModelTypeSheet

        ' This appears to read the element ID of the 1st reference file
        refBorderElID = refBorder.AsAttachment.ElementID
        Set thisSheet = thisModel.GetSheetDefinition
        With thisSheet
            'This code fails to set the sheet size.
            .FormName = "ANSI D"
            'However, this code will cause the ANSI D sheet site
            'to be set as the form name

            'It took some trial and error to develop this result.
            'VBA Help was no help

            .Width = thisModel.WorkingUnitsToDouble("34'") * 1000
            .Height = thisModel.WorkingUnitsToDouble("22'") * 1000
            .AnnotationScaleFactor = 10

            'This next code will throw the error. Comment it out and most
            'everything else works.

            mdlSheetDef_setBorderAttachmentId thisSheet, refBorderElID
        End With
    End Sub

    When It go to modify this, I will be replacing my code:

    mdlSheetDef_setBorderAttachmentId thisSheet, refBorderElID

    with some version of this:

    expr = "mdlSheetDef_setBorderAttachmentId((void*)" & theAddr & ", " & _
            DLongToString(id) & ")"
    GetCExpressionValue expr

    As I understand your example, theAddr is the address of the sheet definition(?) and id is the DLong containing the element ID of the model Reference that contains the sheet border.

    My code appears to successfully retrieve the element ID as the Sheet Definition (address of ... ?)

    1. So, can I change DLongToString(id) to DLongToString(refBorderElID) and skip using the code id.Low = 1111 since I have the correct value in my DLong already?

    2. And if that is OK, what syntax can I use to put my thisSheet which contains my SheetDefinition already, into the expr line of code?

    TIA


    Charles (Chuck) Rheault
    CADD Manager

    MDOT State Highway Administration

    • MicroStation user since IGDS, InRoads user since TDP.
    • AutoCAD, Land Desktop and Civil 3D, off and on since 1996
  • Bump!

    I'm getting close, but need a little more help. See my last post - two questions at the bottom.


    Charles (Chuck) Rheault
    CADD Manager

    MDOT State Highway Administration

    • MicroStation user since IGDS, InRoads user since TDP.
    • AutoCAD, Land Desktop and Civil 3D, off and on since 1996
Reply Children
No Data