[CONNECT Update 10 MDL] - Need help migrating MDL to connect edition, its not working

Hello Everyone,

Our organisation have just upgraded our MicroStation v8i SS3 to MicroStation Connect edition version 10.10.00.23.

I am having trouble with my v8i MDL apps since its not working in my connect edition.

I am not a programmer and although I am learning VBA, I have been unsuccessful in trying to replicate the same MDL app function in VBA. If someone can easily modify and recompile my old V8i MDL app so it can work in my CONNECT edition, that will be great thanks. or if someone can guide me to write a VBA version of that MDL app, that'll be very beneficial for my learning too. 

I have attached my old v8i MDL app as a zip file. datstmp.zip

Basically, we used to call this MDL by using our custom tool with key-in as "LV=2;CO=3;WT=0;textstyle active AN18;MDL Load datstmp;place stamp" to place the 2 line of texts. 

and we used to call the same MDL by using our another custom tool with key-in as "LLV=2;CO=3;WT=0;textstyle active AN18;MDL Load datstmp;update stamp" to update the current file location and current date,time.

Output used to look like this pic: 

And also here's my initial attempt on replicating the same function in Connect vba, here's my codes:

Public Function GetDgnFilename(ByVal modelRef As ModelReference) As String
    GetDgnFilename = vbNullString
    GetDgnFilename = modelRef.DesignFile.FullName
End Function




Sub PlaceDateTimeStamp()
    Dim Path        As String
    Dim CustomPath  As String
    Dim oDate       As Date
    Dim CustomDate  As String
    Dim MyTime
    Dim CustomDateTime  As String
    
    Path = GetDgnFilename(ActiveModelReference)
    CustomPath = "File:\\ " & Path
    
    oDate = Now()
    CustomDate = Format(oDate, "Medium Date")   ' or "Short Date" or "Long Date" or your own custom date format
   
    MyTime = Time                               'Returns a Variant (Date) indicating the current system time.
    
    CustomDateTime = "Date: " & CustomDate & " " & MyTime
      
    Debug.Print CustomPath
    Debug.Print CustomDateTime
    

End Sub

Any help will be much appreciated.

(Thank you Jan Slegr for your comments in my other post)

Thank you 

Regards,

Shyam.

Parents
  • Output used to look like this pic

    Take a look at MicroStation Text Fields.  You may be able to achieve your requirements without any programming.

    Here's an example DGN file:

    TextFieldFileExample.dgn

     
    Regards, Jon Summers
    LA Solutions

  • Hi ,

    When migrating to CONNECT Edition there are a number of considerations, workflows, and paths that may be taken.  So, first I agree with  that "Option 1: MicroStation CONNECT can effectively replace this prior customization need/feature/functionality" - directly with MicroStation Text Fields (a powerful new feature to explore and leverage), here are a few Text Field Wikis that may help you get started.

    For any/all New or Existing/Advanced users, I completely recommend reviewing information we are organizing in this (one single entry point) blog post: Advancing to CONNECT Edition.  We will continuously editing and improving this link for all New and Existing/Advanced users to make all their options and information current and helpful as possible.

    HTH,
    Bob



  • here are a few Text Field Wikis

    Sift the Wikis that discuss Text Fields from those about Data Fields.  The terminology is similar but the semantics are different. Data Fields are 20th century technology and have nothing to do with Text Fields.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Robert & Jon,

    Thank you for your reply. Much appreciated

    I was testing today with Text Fields and I will test it further if it can fix my issue.

    One thing I noticed with Text fields that the texts with field are highlighted with grey color background, is there anyway I can remove that background highlight please? Thanks

    Regards,

    Shyam

  • One thing I noticed with Text fields that the texts with field are highlighted with grey color background, is there anyway I can remove that background highlight please?

    In Preferences dialog, go to Text category and switch on Hide Field Background option.

    Regards,

      Jan

  • Hi Jan,

    Thank you for your reply and apologies for a very late response.

    Although I found a way to create the same output via TEXT FIELDS. It wasn't the best option for my workplace since we have 1000's of drawings already with the File+Date stamp I have shown above and everytime someone was modifying those drawings, they needed a button to simply update the current file path and current date/time.

    So I went back to VBA again and found a way to have it working same way as we used to have in our v8i version with MDL application.

    Here's a code I have written in VBA connect edition.

    Modules: PlaceDateStamp

     

    Public Function GetDgnFilename(ByVal modelRef As ModelReference) As String
        GetDgnFilename = vbNullString
        GetDgnFilename = modelRef.DesignFile.FullName
    End Function
    
    Sub PlaceDateStamp()
       CommandState.StartPrimitive New clsStampPlacer                               'calls class module named clsStampPlacer
    End Sub
    
    
    
    Sub UpdateDateStamp()
             
            Dim txt As TextElement
            Dim oELScan As New ElementScanCriteria
            oELScan.ExcludeAllTypes
            oELScan.IncludeType msdElementTypeText
             
            Dim oTextEnum As ElementEnumerator
            Set oTextEnum = ActiveModelReference.Scan(oELScan)
             
            Dim FilePathUpdateCounter As Integer
            Dim DateUpdateCounter As Integer
             
            FilePathUpdateCounter = 0
            DateUpdateCounter = 0
             
             Do While oTextEnum.MoveNext
                Set txt = oTextEnum.Current
                
                If Left(txt.Text, 6) = "FILE: " Then                    ' scans for all texts in a file that starts with first 6 string as "FILE: "
                    Dim Path        As String
                    Dim CustomPath  As String
                    Path = GetDgnFilename(ActiveModelReference)
                    CustomPath = "FILE: " & Path
             
                    Dim text1 As String
                    text1 = CustomPath
                    
                    Debug.Print text1
                    
                    txt.Text = text1                                    'texts that has "FILE: " will be replaced by current active model design filename
                    txt.Redraw msdDrawingModeNormal
                    txt.Rewrite
                    
                    FilePathUpdateCounter = FilePathUpdateCounter + 1
                End If
                
                
                If Left(txt.Text, 5) = "DATE:" Then                     ' scans for all texts in a file that starts with first 5 string as "DATE: "
                    Dim oDate       As Date
                    Dim CustomDate  As String
                    oDate = Now()
                    CustomDate = Format(oDate, "Medium Date")
            
                    Dim oTime
                    Dim CusomTime As String
                    CustomTime = Format(Time, "hh:mm")
             
                    Dim CustomDateTime  As String
                    CustomDateTime = "DATE: " & CustomDate & " " & CustomTime
             
                    Dim text2 As String
                    text2 = CustomDateTime
             
                    Debug.Print text2
                    
                    txt.Text = text2                                     ' texts that has "DATE: " will be replaced by current system date and time.
                    txt.Redraw msdDrawingModeNormal
                    txt.Rewrite
                    
                     DateUpdateCounter = DateUpdateCounter + 1
                End If
                
                ShowCommand "Update Date Stamp"
                ShowPrompt "Updated Date Stamp"
            Loop
            
            'Check if there are any date stamps in a file, if there are none then prompt user if they want to place Date Stamp first?
            Debug.Print FilePathUpdateCounter
            Debug.Print DateUpdateCounter
            
            If FilePathUpdateCounter = 0 Then
                If DateUpdateCounter = 0 Then
                    If MsgBox("There is no Date Stamp in this Drawing." & vbNewLine & vbNewLine & "Do you want to place Date Stamp First?", vbYesNo, "Update Date Stamp") = vbYes Then
                        'CadInputQueue.SendKeyin "vba run [ProjectDateStamp]placedatestamp"
                        PlaceDateStamp
                    End If
                End If
            End If
            
    End Sub
    

    Class Modules: clsStampPlacer

    ' ---------------------------------------------------------------------
    '   Stamp Placer class
    ' ---------------------------------------------------------------------
    Implements IPrimitiveCommandEvents
    
    
    ' ---------------------------------------------------------------------
    Private Sub IPrimitiveCommandEvents_Cleanup()
    
    End Sub
    '--------------------------------------------------------------------------------------------
    'DropTextNode
    'Drops Text Node created in CreateStamp sub to two seperate texts before placing Date stamp.
    '----------------------------------------------------------------------------------------------------
    Private Sub DropTextNode(ByVal TxdNd As TextNodeElement)
        Dim oTexts As ElementEnumerator
        Set oTexts = TxdNd.Drop
        Do While oTexts.MoveNext
            Dim oElement As TextElement
            Set oElement = oTexts.Current
            ActiveModelReference.AddElement oElement
        Loop
        ShowPrompt "Placed Date Stamp"
    End Sub
    '------------------------------------------------------------------------------
    'CreateStamp
    'Creates a date stamp with active model file path and current system date & time
    '------------------------------------------------------------------------------
    Private Sub CreateStamp(ByRef point As Point3d, ByVal drawMode As MsdDrawingMode)
             Dim Path        As String
             Dim CustomPath  As String
             Path = GetDgnFilename(ActiveModelReference)
             CustomPath = "FILE: " & Path
             
             Dim oDate       As Date
             Dim CustomDate  As String
             oDate = Now()
             CustomDate = Format(oDate, "Medium Date")   ' or "Short Date" or "Long Date" or your own custom date format
            
             Dim oTime
             Dim CusomTime As String
             CustomTime = Format(Time, "hh:mm")
             
             Dim CustomDateTime  As String
             CustomDateTime = "DATE: " & CustomDate & " " & CustomTime
             
             Dim text1, text2 As String
             text1 = CustomPath
             text2 = CustomDateTime
             
             Debug.Print text1
             Debug.Print text2
             
             '
             '
             ' Now Combining 2 lines of texts to one text as textnode
             '
             '
             '
             '
             Dim TxtNd As TextNodeElement
             Dim oTextEnum As ElementEnumerator
             Dim txt As TextElement
             
             CadInputQueue.SendKeyin "active tnj lt;CO=3;textstyle active AN18"
             
             Set TxtNd = CreateTextNodeElement1(Nothing, point, Matrix3dIdentity)
             TxtNd.AddTextLine text1
             TxtNd.AddTextLine text2
             
             If drawMode = msdDrawingModeNormal Then
                DropTextNode TxtNd 'call function DropTextNode to drop text node to two seperate texts
             Else
                TxtNd.Redraw drawMode
             End If
                 
    End Sub
        
    ' ---------------------------------------------------------------------
    Private Sub IPrimitiveCommandEvents_DataPoint(point As Point3d, ByVal View As View)
        CreateStamp point, msdDrawingModeNormal
    End Sub
    ' ---------------------------------------------------------------------
    Private Sub IPrimitiveCommandEvents_Dynamics(point As Point3d, ByVal View As View, ByVal drawMode As MsdDrawingMode)
        CreateStamp point, drawMode
    End Sub
    ' ---------------------------------------------------------------------
    Private Sub IPrimitiveCommandEvents_Keyin(ByVal Keyin As String)
    
    End Sub
    
    Private Sub IPrimitiveCommandEvents_Reset()
         CommandState.StopDynamics
         CommandState.StartDefaultCommand
    End Sub
    
    
    Private Sub IPrimitiveCommandEvents_Start()
        CommandState.CommandName = "Date Stamp Placement"    'ShowCommand CommandState.CommandName
        ShowPrompt "Place Date Stamp"
        CommandState.StartDynamics
    End Sub
    ' ---------------------------------------------------------------------
    
    
    

    If anyone finds it helpful, they can reuse the code.

    As of now, the code is working perfectly fine for us. Only thing I'd like to add to this coding is, if I can have the scale option similar to when you are placing a cell - you have an option to scale up your cell before placing your cell. If anyone can guide me on how I can achieve that, that will be great. Thanks

  • Hi ,

    FYI. I updated Text Field Wikis to split Text Field links from Data Field links.

    Thank you,
    Bob



Reply Children
No Data