<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic start lisp-Command immediately after sendstringtoexecute in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/start-lisp-command-immediately-after-sendstringtoexecute/m-p/6862639#M32827</link>
    <description>&lt;P&gt;hi !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a&amp;nbsp;vb.net-programm to create a drawing and save automatically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;before&amp;nbsp;the dwg will be saved a lisp should be loaded and run. (kind of postprocessing).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the following function will work without any mistake:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; Public Function LoadAndStartLisp(ByVal LispFilePath As String, Optional LispCommand As String = "")
        Dim Status As Integer = 0
        AcReInit()

        ' keine LISP-Datei angegeben
        If LispFilePath.Length = 0 Then Return -2

        If System.IO.File.Exists(LispFilePath) = False Then
            Return -1
        End If

        Dim acDoc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

        Using acTrans As Transaction = _Database.TransactionManager.StartTransaction()
            Using acDoc.LockDocument
                ' erfolgreich geladen -&amp;gt; 1
                Status = 1

                Try
                    Dim LispCommand2Load As String = "(load " &amp;amp; Chr(34) &amp;amp; LispFilePath &amp;amp; Chr(34) &amp;amp; "\r)"
                    _AcDocument.SendStringToExecute(LispCommand2Load, True, False, False)
                Catch ex As Exception
                    _Editor.WriteMessage("Kann Lisp nicht laden!" &amp;amp; vbCrLf &amp;amp; ex.ToString)
                    Return -2 ' Lisp nicht geladen
                End Try

                ' ausführen eines bestimmten Commandos
                If LispCommand.Length &amp;gt; 0 Then
                    Try
                        _AcDocument.SendStringToExecute(LispCommand, True, False, False)
                        _Editor.WriteMessage("rufe Lisp-Befehl auf: " &amp;amp; LispCommand)
                    Catch ex As Exception
                        _Editor.WriteMessage("Fehler beim Ausführen des LISP Befehls " &amp;amp; LispCommand &amp;amp; "" &amp;amp; vbCrLf &amp;amp; ex.ToString)
                        Return -3 ' Fehler beim Ausführen des LISP-Befehls
                    End Try
                End If

            End Using 'acDoc
        End Using 'acTrans
        Return Status
    End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my little test-lisp Shows first&amp;nbsp;a alert-message and then inserts a block into dwg.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;after the vb.net Programm finished the block the message will not Show and no block will be insert.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i double-click the middle mouse-wheel the lisp-Programm will be run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in my first &lt;SPAN&gt;thoughts&amp;nbsp;i missed a RETURN in the &lt;/SPAN&gt;LispCommand2Load-Variable - i add \r&amp;nbsp;- but this was not the &lt;SPAN&gt;solution!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;could someone help me ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;regards Jan&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Feb 2017 13:44:13 GMT</pubDate>
    <dc:creator>jan_tappenbeck</dc:creator>
    <dc:date>2017-02-08T13:44:13Z</dc:date>
    <item>
      <title>start lisp-Command immediately after sendstringtoexecute</title>
      <link>https://forums.autodesk.com/t5/net-forum/start-lisp-command-immediately-after-sendstringtoexecute/m-p/6862639#M32827</link>
      <description>&lt;P&gt;hi !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a&amp;nbsp;vb.net-programm to create a drawing and save automatically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;before&amp;nbsp;the dwg will be saved a lisp should be loaded and run. (kind of postprocessing).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the following function will work without any mistake:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; Public Function LoadAndStartLisp(ByVal LispFilePath As String, Optional LispCommand As String = "")
        Dim Status As Integer = 0
        AcReInit()

        ' keine LISP-Datei angegeben
        If LispFilePath.Length = 0 Then Return -2

        If System.IO.File.Exists(LispFilePath) = False Then
            Return -1
        End If

        Dim acDoc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

        Using acTrans As Transaction = _Database.TransactionManager.StartTransaction()
            Using acDoc.LockDocument
                ' erfolgreich geladen -&amp;gt; 1
                Status = 1

                Try
                    Dim LispCommand2Load As String = "(load " &amp;amp; Chr(34) &amp;amp; LispFilePath &amp;amp; Chr(34) &amp;amp; "\r)"
                    _AcDocument.SendStringToExecute(LispCommand2Load, True, False, False)
                Catch ex As Exception
                    _Editor.WriteMessage("Kann Lisp nicht laden!" &amp;amp; vbCrLf &amp;amp; ex.ToString)
                    Return -2 ' Lisp nicht geladen
                End Try

                ' ausführen eines bestimmten Commandos
                If LispCommand.Length &amp;gt; 0 Then
                    Try
                        _AcDocument.SendStringToExecute(LispCommand, True, False, False)
                        _Editor.WriteMessage("rufe Lisp-Befehl auf: " &amp;amp; LispCommand)
                    Catch ex As Exception
                        _Editor.WriteMessage("Fehler beim Ausführen des LISP Befehls " &amp;amp; LispCommand &amp;amp; "" &amp;amp; vbCrLf &amp;amp; ex.ToString)
                        Return -3 ' Fehler beim Ausführen des LISP-Befehls
                    End Try
                End If

            End Using 'acDoc
        End Using 'acTrans
        Return Status
    End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my little test-lisp Shows first&amp;nbsp;a alert-message and then inserts a block into dwg.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;after the vb.net Programm finished the block the message will not Show and no block will be insert.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i double-click the middle mouse-wheel the lisp-Programm will be run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in my first &lt;SPAN&gt;thoughts&amp;nbsp;i missed a RETURN in the &lt;/SPAN&gt;LispCommand2Load-Variable - i add \r&amp;nbsp;- but this was not the &lt;SPAN&gt;solution!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;could someone help me ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;regards Jan&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 13:44:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/start-lisp-command-immediately-after-sendstringtoexecute/m-p/6862639#M32827</guid>
      <dc:creator>jan_tappenbeck</dc:creator>
      <dc:date>2017-02-08T13:44:13Z</dc:date>
    </item>
    <item>
      <title>Re : start lisp-Command immediately after sendstringtoexecute</title>
      <link>https://forums.autodesk.com/t5/net-forum/start-lisp-command-immediately-after-sendstringtoexecute/m-p/6863010#M32828</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can simply a space (" ") as validation with SendStringToExecute (as you'd do at command line).&lt;/P&gt;
&lt;P&gt;In the path string, you have to rplace each anti-slash with a slash or a double anti slache before using it in the (load ...) lISP expression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;C#&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;private void LoadAndStartLisp(string lispPath, string lispCmd = "")
{
    var doc = Application.DocumentManager.MdiActiveDocument;
    var loadStr = "(load \"" + lispPath.Replace(@"\", @"\\") + "\") ";
    doc.SendStringToExecute(loadStr, true, false, false);
    if (lispCmd != "")
        doc.SendStringToExecute(lispCmd.Trim() + " ", true, false, false);
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;VB (telerik conversion)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Private Sub LoadAndStartLisp(lispPath As String, Optional lispCmd As String = "")
    Dim doc = Application.DocumentManager.MdiActiveDocument
    Dim loadStr = "(load """ + lispPath.Replace("\", "\\") + """) "
    doc.SendStringToExecute(loadStr, True, False, False)
    If lispCmd &amp;lt;&amp;gt; "" Then
	doc.SendStringToExecute(lispCmd.Trim() + " ", True, False, False)
    End If
End Sub

'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik
'Facebook: facebook.com/telerik
'=======================================================
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 15:17:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/start-lisp-command-immediately-after-sendstringtoexecute/m-p/6863010#M32828</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-02-08T15:17:58Z</dc:date>
    </item>
  </channel>
</rss>

