AutoCAD 2016 - Visual problem inserting MLeaders on Standard VS Mechanical

AutoCAD 2016 - Visual problem inserting MLeaders on Standard VS Mechanical

Anonymous
Not applicable
655 Views
4 Replies
Message 1 of 5

AutoCAD 2016 - Visual problem inserting MLeaders on Standard VS Mechanical

Anonymous
Not applicable

Hey guys,

 

I usually develop on AutoCAD 2016 (standard version). Although, some users use AutoCAD 2016 mechanical. It has come to my attention that when users are using my function to insert MLeaders on the mechanical version, they do not visually update until the command has finished executing.

 

I'll try to demonstrate using screenshots with standard vs mechanical.

 

Standard version

 

Standard_VisualUpdate.png

Notice the blue lines appear after each step.

 

Mechanical version

Mechanical_VisualUpdate.png

Notice how the blue lines only appear on step 6.

 

Here's my code to enter in the leaders:

Public Function CreateLeader(ByVal acDoc As Document, ByRef CurrentConvIdColl As ObjectIdCollection, ByVal StartPoint As Point3d,
                             ByVal PromptMessage As String, ByVal textValue As String, ByVal Infeed As Boolean,
                             ByRef ctp As tpToolPalette, ByVal pc As clsProjectItem) As Boolean

    Dim oldOSMODE As Object = AcApp.GetSystemVariable("osmode") 'Get Snap Mode
    Dim oldLayer As Object = AcApp.GetSystemVariable("clayer") 'get current layer
    Dim oldLeaderStyle As Object = AcApp.GetSystemVariable("cmleaderstyle") 'get current leader style
    Dim oldTextStyle As Object = AcApp.GetSystemVariable("textstyle") 'get current text style
    Dim oldOtrho As Object = AcApp.GetSystemVariable("ORTHOMODE")

    Try
        Dim acBlkTbl As BlockTable
        Dim acBlkTblRec As BlockTableRecord
        Dim db As Database = acDoc.Database ' Current database
        Dim ed As Editor = acDoc.Editor
        Dim leaderId As ObjectId
        Dim mt As MText
        Dim pPtOpts As New PromptPointOptions("")
        Dim pPtRes As PromptPointResult
        Dim EndPoint As Point3d
        Dim lbl As Windows.Forms.Label
        Dim idx As Integer
        Dim ml As MLeader
        Dim leaderXData As String = "INFEED"
        Dim rb As ResultBuffer

        If Not Infeed Then leaderXData = "DISCHARGE"

        'Determine which label
        If Infeed Then lbl = ctp.lblSetInfeedLeader Else lbl = ctp.lblSetDischargeLeader

        Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView()
        AcApp.SetSystemVariable("OSMODE", 0) 'Set "None" Snap Mode
        AcApp.SetSystemVariable("ORTHOMODE", 0)
        SetLayerCurrent(acDoc, "QUOTE") 'Set Layer QUOTE
        AcApp.SetSystemVariable("OSMODE", oldOSMODE) 'Set Old Snap Mode
        SetLeader("STD-48")

        'Determine EndPoint
        SetLabelImage({lbl}, "Set")
        pPtOpts.Message = PromptMessage 'Prompt for user insertion point
        pPtOpts.UseBasePoint = True
        pPtOpts.BasePoint = StartPoint
        pPtRes = ed.GetPoint(pPtOpts) 'Get user to select the insertion point

        If pPtRes.Status = PromptStatus.OK Then
            SetTextStyleCurrent(acDoc, "SIMPLEX-96") 'Set text style

            EndPoint = New Point3d(pPtRes.Value.X, pPtRes.Value.Y, pPtRes.Value.Z) 'Fix up the point to be a point3d object
            Using lock As DocumentLock = acDoc.LockDocument
                db = acDoc.Database 'Get the current database

                'Start a transaction
                Using acTrans As Transaction = db.TransactionManager.StartTransaction()
                    'Open Model space for write
                    acBlkTbl = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead)
                    acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

                    'Create Leader
                    ml = New MLeader
                    ml.SetDatabaseDefaults()
                    ml.ContentType = ContentType.MTextContent
                    ml.ArrowSymbolId = Nothing
                    ml.TextAttachmentType = TextAttachmentType.AttachmentMiddle
                    rb = New ResultBuffer
                    rb.Add(New TypedValue(1001, "MYAPPNAME")) 'Nom de l'application
                    rb.Add(New TypedValue(1071, pc.PK_ID)) 'Integer32 = int dans SQL
                    rb.Add(New TypedValue(DxfCode.ExtendedDataAsciiString, leaderXData))
                    ml.XData = rb

                    'Create Text
                    mt = New MText
                    mt.SetDatabaseDefaults()
                    mt.SetContentsRtf(textValue)
                    If EndPoint.X < StartPoint.X Then
                        'Change location to fit user's pick point anf Right to Left text
                        mt.Location = New Point3d(EndPoint.X - textValue.Length * ml.TextHeight * ml.Scale, EndPoint.Y, EndPoint.Z) 'Normal Left to Right text
                    Else
                        mt.Location = EndPoint
                    End If

                    ml.MText = mt
                    ml.TextHeight = 0.1
                    idx = ml.AddLeaderLine(StartPoint)
                    leaderId = acBlkTblRec.AppendEntity(ml)
                    acTrans.AddNewlyCreatedDBObject(ml, True)
                    CurrentConvIdColl.Add(leaderId)

                    'Commit the changes and dispose of the transaction
                    acTrans.Commit()
                End Using 'Dispose transaction
            End Using 'Dispose Lock
        Else
            'Set Old Layer
            SetLayerCurrent(acDoc, oldLayer)
            SetLeader(oldLeaderStyle.ToString)
            SetTextStyleCurrent(acDoc, oldTextStyle) 'Set old text style

            Return False
        End If

        SetLayerCurrent(acDoc, oldLayer) 'Set Old Layer
        SetLeader(oldLeaderStyle.ToString)
        SetTextStyleCurrent(acDoc, oldTextStyle) 'Set old text style
        AcApp.SetSystemVariable("ORTHOMODE", oldOtrho)
        SetLabelImage({lbl}, "Completed")

        Return True
    Catch ex As Exception
        'Set Old Layer
        SetLayerCurrent(acDoc, oldLayer)
        SetLeader(oldLeaderStyle.ToString)
        SetTextStyleCurrent(acDoc, oldTextStyle) 'Set old text style
        CustomErrHandler(ex, System.Reflection.MethodBase.GetCurrentMethod.DeclaringType.Name, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        Return False
    End Try
End Function

I'm guessing it's something to do with the transaction ... No idea how to go about debugging that though. Any thoughts?

 

Alex

0 Likes
656 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

I've tried using the Editor.Regen() command but no luck...

 

Why would AutoCAD Mechanical react differently than AutoCAD Standard in such a way?

0 Likes
Message 3 of 5

Anonymous
Not applicable

I also tried Editor.ScreenUpdate() but no change ... All the lines appear once the command is terminated though, but not as I click and place them.

0 Likes
Message 4 of 5

Anonymous
Not applicable

Here's a cleaned up version of the code ... Tried to edit the main post but it does not let me.

 

Public Function CreateLeader(ByVal acDoc As Document) As Boolean
    Dim acBlkTbl As BlockTable
    Dim acBlkTblRec As BlockTableRecord
    Dim db As Database = acDoc.Database ' Current database
    Dim ed As Editor = acDoc.Editor
    Dim leaderId As ObjectId
    Dim mt As MText
    Dim pPtOpts As New PromptPointOptions("")
    Dim pPtRes As PromptPointResult
    Dim idx As Integer
    Dim ml As MLeader

    'Determine EndPoint
    pPtOpts.Message = "Place the leader" 'Prompt for user insertion point
    pPtOpts.UseBasePoint = True
    pPtOpts.BasePoint = New Point3d(0, 0, 0)
    pPtRes = ed.GetPoint(pPtOpts) 'Get user to select the insertion point

    If pPtRes.Status = PromptStatus.OK Then
        Using lock As DocumentLock = acDoc.LockDocument
            db = acDoc.Database 'Get the current database

            'Start a transaction
            Using acTrans As Transaction = db.TransactionManager.StartTransaction()
                'Open Model space for write
                acBlkTbl = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead)
                acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

                'Create Leader
                ml = New MLeader
                ml.SetDatabaseDefaults()
                ml.ContentType = ContentType.MTextContent
                ml.ArrowSymbolId = Nothing
                ml.TextAttachmentType = TextAttachmentType.AttachmentMiddle

                'Create Text
                mt = New MText
                mt.SetDatabaseDefaults()
                ml.MText = mt
                ml.TextHeight = 0.1
                idx = ml.AddLeaderLine(New Point3d(0, 0, 0))
                leaderId = acBlkTblRec.AppendEntity(ml)
                acTrans.AddNewlyCreatedDBObject(ml, True)

                'Commit the changes and dispose of the transaction
                acTrans.Commit()
            End Using 'Dispose transaction
        End Using 'Dispose Lock
    Else
        Return False
    End If

    Return True
End Function

 

This seems to me to be an AutoCAD Mechanical bug!! Please help! 😞

 

Can anyone please test this batch of code on AutoCAD Mechanical 2016 and let me know if they also get the same error? Call this function 4 times and you will only see the leaders appear once you've finished inserting all 4...

0 Likes
Message 5 of 5

Anonymous
Not applicable

Anybody...?

0 Likes