
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am left a little perplexed with this issue. This error occurs only in some drawings, which leaves me to believe it's a problem with the drawing itself, right?
Well; here's the thing... I am trying to set a leader style using the following line of code:
AcApp.SetSystemVariable("CMLEADERSTYLE", "STD-48") 'Set Leader
As we can see from the following screenshot, the style STD-48 exists:
So the drawing contains the style yet returns an eInvalidInput whenever I try to set it using the "SetSystemVariable".
For more background on how I use it, see the CreateLeader() method that is built (keep in mind, this was not programmed by me):
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 tpConveyorToolPalette) 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 'Determine which label If Infeed Then lbl = ctp.lblSetInfeedLeader Else lbl = ctp.lblSetDischargeLeader If Not IsMLeaderExists("STD-48") Then InsertLayoutTemplate() : ed.WriteMessage("STD-48 was not found. Drawing has been updated with latest template") Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView() 'Set "None" Snap Mode AcApp.SetSystemVariable("OSMODE", 0) AcApp.SetSystemVariable("ORTHOMODE", 0) SetLayerCurrent(acDoc, "QUOTE") 'Set Layer QUOTE AcApp.SetSystemVariable("OSMODE", oldOSMODE) 'Set Old Snap Mode AcApp.SetSystemVariable("CMLEADERSTYLE", "STD-48") 'Set Leader, ERROR OCCURS HERE!! '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 '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) AcApp.SetSystemVariable("CMLEADERSTYLE", oldLeaderStyle) 'Set old Leader SetTextStyleCurrent(acDoc, oldTextStyle) 'Set old text style Return False End If SetLayerCurrent(acDoc, oldLayer) 'Set Old Layer AcApp.SetSystemVariable("CMLEADERSTYLE", oldLeaderStyle) 'Set old Leader 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) AcApp.SetSystemVariable("CMLEADERSTYLE", oldLeaderStyle) 'Set old Leader 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
The program goes through the CreateLeader() succesfully two times. On the third time, it stops on the CMLEADERSTYLE setting.
I have AutoCAD 2014, should I be setting the leader style in a different and more robust way?
Thank you,
Alex
Solved! Go to Solution.