CMDECHO NOMUTT not working

CMDECHO NOMUTT not working

David_Prontnicki
Collaborator Collaborator
701 Views
3 Replies
Message 1 of 4

CMDECHO NOMUTT not working

David_Prontnicki
Collaborator
Collaborator

Hi All,

I'm having a problem with CMDECHO and NOMUTT. Have a program that loads or reloads a linetype; found on Dev Blogs. It uses the Send Command option, which obviously writes to the command line. I am getting, setting and restoring the CMDECHO and NOMUTT but it is still writing to the command bar. How do I fully suppress this. I know it's due to the Send Command and that some things like purge cant be suppressed but if works with creating say a text style why not with loading/reloading a linetype?

 

Called from Form...

 

Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles btnInsert.Click

        Try

            Dim selectedLineType As String = lstSelectLinetype.SelectedItem.Filename

            Dim pathHelper As New DetailPathHelper(selectedLineType)
            selectedLineTypeName = pathHelper.LinetypeName

            Dim linetypeFilePath = _clientLinetypeService.FindLinetypeFileForClient(cmbSelectLineTypeFile.Text)

            _autocadSystemVariableServices.StoreSystemVariables()

            _autocadSystemVariableServices.SetSystemVariables()

            _autocadService.LoadLinetype(selectedLineTypeName, linetypeFilePath)

            _autocadSystemVariableServices.RestoreSystemVariables()

        Catch ex As Exception

            _autocadSystemVariableServices.RestoreSystemVariables()
End Try
End Sub

 

Sub Called...

 

 

Public Class AutocadService
    Implements IAutocadService

    Public Sub LoadLinetype(ByVal selectedLineTypeName As String, ByVal lineTypeFile As String) Implements IAutocadService.LoadLinetype

        Dim acDoc As Document = AutocadActiveDocument.Document
        Dim acCurDb As Database = AutocadActiveDocument.Database
        Dim ltReload As Boolean = False

        Try

            Using acDocLock As DocumentLock = acDoc.LockDocument

                Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                    Dim acLineTypTbl As LinetypeTable

                    acLineTypTbl = acTrans.GetObject(acCurDb.LinetypeTableId, OpenMode.ForRead)

                    If acLineTypTbl.Has(selectedLineTypeName) = True Then

                        ltReload = True

                    End If

                    acTrans.Commit()

                End Using

            End Using

            Dim acAppObject As Object = Application.AcadApplication

            Dim acDocObject As Object = acAppObject.GetType().InvokeMember("ActiveDocument", System.Reflection.BindingFlags.GetProperty, Nothing, acAppObject, Nothing)

            Dim sendCommandDataArray As Object() = New Object(0) {}

            If ltReload Then

                sendCommandDataArray(0) = "-linetype Load" & vbLf & selectedLineTypeName & vbLf & lineTypeFile & vbLf & "Yes" & vbLf & " "

            Else

                sendCommandDataArray(0) = "-linetype Load" & vbLf & selectedLineTypeName & vbLf & lineTypeFile & vbLf & " "

            End If

            acDocObject.GetType().InvokeMember("SendCommand", System.Reflection.BindingFlags.InvokeMethod, Nothing, acDocObject, sendCommandDataArray)

            sendCommandDataArray(0) = "regenall" & vbLf

            acDocObject.GetType().InvokeMember("SendCommand", System.Reflection.BindingFlags.InvokeMethod, Nothing, acDocObject, sendCommandDataArray)

        Catch ex As Exception
End Try
End Sub

 

System Variable Class...

 

Public Class AutocadSystemVariableServices
    Implements IAutocadSystemVariableServices

    Dim restoreOldFiledia As Integer
    Dim restoreOldCmdecho As Integer
    Dim restoreOldNomutt As Integer

    Public Sub StoreSystemVariables() Implements IAutocadSystemVariableServices.StoreSystemVariables

        restoreOldFiledia = Convert.ToInt16(Application.GetSystemVariable("FILEDIA"))
        restoreOldCmdecho = Convert.ToInt16(Application.GetSystemVariable("CMDECHO"))
        restoreOldCmdecho = Convert.ToInt16(Application.GetSystemVariable("NOMUTT"))

    End Sub

    Public Sub SetSystemVariables() Implements IAutocadSystemVariableServices.SetSystemVariables

        Application.SetSystemVariable("FILEDIA", 0)
        Application.SetSystemVariable("CMDECHO", 0)
        Application.SetSystemVariable("NOMUTT", 0)

    End Sub

    Public Sub RestoreSystemVariables() Implements IAutocadSystemVariableServices.RestoreSystemVariables

        Application.SetSystemVariable("FILEDIA", restoreOldFiledia)
        Application.SetSystemVariable("CMDECHO", restoreOldCmdecho)
        Application.SetSystemVariable("NOMUTT", restoreOldNomutt)

    End Sub

End Class

 

cmdecho.jpg

 

0 Likes
702 Views
3 Replies
Replies (3)
Message 2 of 4

norman.yuan
Mentor
Mentor

Not sure in what context your code is to run, but since you are doing Acad .NET API coding, why bother using Acad COM API's sendCommand() when you can simply use built-in .NET API functionality:

 

Database.LoadLineTypeFile()

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 4

David_Prontnicki
Collaborator
Collaborator

Thanks Norman,

 

This is why: https://forums.autodesk.com/t5/net/reload-linetype/td-p/9397842

😊

 

I am not a fan of send command for this reason and a few others, but I think I am stuck doing it this way....

0 Likes
Message 4 of 4

ActivistInvestor
Mentor
Mentor

SendCommand() is asynchronous which means that your system variables are being restored before the commands are executed.

 

Use the Editor.Command() method instead. 

0 Likes