Message 1 of 5
AutoCAD 2016 - Visual problem inserting MLeaders on Standard VS Mechanical

Not applicable
12-14-2016
08:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Notice the blue lines appear after each step.
Mechanical version
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