Author Topic: editor.command()  (Read 5614 times)

0 Members and 1 Guest are viewing this topic.

sybold

  • Newt
  • Posts: 62
editor.command()
« on: November 19, 2014, 11:23:21 AM »
why does this code work

Code: [Select]
        <CommandMethod("TestSimple")> _
        Public Shared Sub TestSimple()
            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
            'call Editor.Command to send command directly
            ed.Command("Line", "0,0,0", "10,10,0", "20,50,0", "")
        End Sub

and this won't, getting einvalidinput

Code: [Select]
       <CommandMethod("TestSimple2")> _
        Public Shared Sub TestSimple2()
            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
            'call Editor.Command to send command directly
            Dim savepath As String = "c:\temp\output.zip"
            ed.Command("-etransmit", "c", savepath)
        End Sub

BillZndl

  • Guest
Re: editor.command()
« Reply #1 on: November 19, 2014, 12:07:54 PM »
Everytime I set a file path to a string in C#, I have to use double backslashes.

"c:\\temp\\output.zip"

Might not be it.

sybold

  • Newt
  • Posts: 62
Re: editor.command()
« Reply #2 on: November 19, 2014, 12:18:45 PM »
the path is right, using Commandasync it creates the zip now. but i get a error after its done.

Quote
System.NullReferenceException: Object reference not set to an instance of an object.
   at Autodesk.AutoCAD.EditorInput.Editor.CommandResult.Callback()

Code: [Select]
<CommandMethod("TestSimple3")> _
        Public Shared Sub TestSimple3()
            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
            'call Editor.Commandasync to send command directly
            Dim savepath As String = "c:\temp\output.zip"
            ed.Commandasync("-etransmit", "c", savepath)
        End Sub

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: editor.command()
« Reply #3 on: November 19, 2014, 01:34:46 PM »
Hi,

I don't know the VB equivalent for async and await C# keywords, but this works:

Code - C#: [Select]
  1.         [CommandMethod("TEST")]
  2.         public async void Test()
  3.         {
  4.             Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  5.             await ed.CommandAsync("_.-etransmit", "_c", @"C:\Temp\output.zip");
  6.         }

EDIT: this VB syntax seems to work:

Code - vb.net: [Select]
  1.         <CommandMethod("TEST")> _
  2.         Public Async Sub Test()
  3.             Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  4.             Await ed.CommandAsync("_.-etransmit", "_c", "C:\Temp\output.zip")
  5.         End Sub
« Last Edit: November 19, 2014, 03:47:49 PM by gile »
Speaking English as a French Frog

sybold

  • Newt
  • Posts: 62
Re: editor.command()
« Reply #4 on: November 20, 2014, 03:19:05 AM »
great!, going to read in this async stuff.

sybold

  • Newt
  • Posts: 62
Re: editor.command()
« Reply #5 on: November 20, 2014, 05:02:39 AM »
as a command it works, but not within a eventhandler

Quote
Autodesk.AutoCAD.Runtime.Exception: eInvalidInput
   at Autodesk.AutoCAD.EditorInput.Editor.CommandAsync(Object[] parameter)

Code: [Select]
Private async Sub docs_DocumentCreated(sender As Object, e As DocumentCollectionEventArgs)
        If (e.Document Is Nothing) Then
            Return
        Else
            AddHandler e.Document.Database.BeginSave, AddressOf Database_BeginSave
            AddHandler e.Document.Database.SaveComplete, AddressOf Database_SaveComplete

            If e.Document.Database.OriginalFileName.EndsWith("dwt") Then
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbLf & "New Document Created - " + e.Document.Name & vbLf)
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbLf & "Used Template - " + e.Document.Database.OriginalFileName & vbLf)
                If e.Document.Database.OriginalFileName.Contains("VSH_Template_") Then
                   ''' load form for customproperties
                   Application.ShowAlertDialog("NEW Drawing with vsh template!")
                End If
            Else
                ''' load form ýes/no backup

                    ''' if yes

                    ''' backup drawing with xrefs
                    Await e.Document.Editor.CommandAsync("-etransmit", "c", "c:\temp\output.zip")
                    ''' Application.ShowAlertDialog("backup created!")
                   
                    ''' else
                    ''' Application.ShowAlertDialog("no backup created!")
            End If
        End If
    End Sub

BlackBox

  • King Gator
  • Posts: 3770
Re: editor.command()
« Reply #6 on: November 20, 2014, 08:37:13 AM »
as a command it works, but not within a eventhandler

Correct; your event handler is attempting to call a command in Application context, which is causing the exception... For that you might instead consider using SendStringToExecute().

Cheers
"How we think determines what we do, and what we do determines what we get."