.NET

Reply
Active Contributor
raulpa
Posts: 49
Registered: ‎10-12-2006
Message 1 of 12 (802 Views)

SendCommand

802 Views, 11 Replies
10-24-2006 04:45 AM
Hi:

Can somebody please tell me if it is possible to Synchronously execute a command sent via SendCommand while using the COM/ActiveX interface in VB 2005? I know I can do this in VBA (in my particular application the commands executed via SendCommand are always complete and the program never needs to wait for user data), but I was hoping I could do the same using VB 2005. Unfortunately, so far I have not been able to do that. In the example below the SendCommand is executed after the file has been saved and I want it to execute before the file is saved. Can somebody please tell me if it is even possible to do what I want to do?

Any ideas would be greatly appreciated,

Raul


Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports System.IO

Public Class ClsTest

>CommandMethod("Test")> _
Public Sub Test()
Dim OutputPath As String = "c:\Test\dwg"
Dim ObjAcad As AcadApplication
Dim ThisDrawing As AcadDocument
Dim Obj As Acad3DSolid
Dim ZeroOrgin() As Double = {0, 0, 0}
Dim Width as Double = 2
Dim Depth as Double = 4
Dim Length as Double = 8

Directory.Delete(OutputPath, True)
Directory.CreateDirectory(OutputPath)

ObjAcad = DirectCast(GetObject(, "AutoCAD.Application.17"), AcadApplication)
ObjAcad.Visible = True
ThisDrawing = ObjAcad.ActiveDocument

Obj = ThisDrawing.ModelSpace.AddBox(ZeroOrgin, Width, Depth, Length)
ThisDrawing.SendCommand("_zoom" & vbCr & "e" & vbCr)

' I was hoping the Do Loop below would be the answer to my problem,
' but IsQuiescent is never True and as a result the program hangs.
' Without the Do Loop, the SendCommand is not executed until after
' the drawing is saved, which is not what I want. Any ideas how to
' solve this problem?
Do Until ObjAcad.GetAcadState.IsQuiescent = True
Loop

ThisDrawing.SaveAs(OutputPath & "\Test.dwg")

End Sub
End Class
*James Buzbee
Message 2 of 12 (802 Views)

Re: SendCommand

10-24-2006 05:16 AM in reply to: raulpa
Break the sequence up into parts and then use AutoLISP or ARX to control the
sequencing.
*tp
Message 3 of 12 (802 Views)

Re: SendCommand

10-24-2006 07:39 AM in reply to: raulpa
I use any thing as this
I wait that this can help you
tp

Imports AcAp = Autodesk.AutoCAD.ApplicationServices
Imports AcDb = Autodesk.AutoCAD.DatabaseServices
Imports AcRx = Autodesk.AutoCAD.Runtime

Public Module Module1

_
Public Sub Teste()
Dim doc As AcAp.Document =
AcAp.Application.DocumentManager.MdiActiveDocument
AddHandlers()
doc.SendStringToExecute("_zoom" & vbCr & "e" & vbCr, True, False,
False)
End Sub

Private m_Command As String = Nothing

Sub AddHandlers()
Dim d As AcAp.Document =
AcAp.Application.DocumentManager.MdiActiveDocument
AddHandler d.CommandWillStart, AddressOf CommandWillStart
AddHandler d.CommandEnded, AddressOf CommandEnded
AddHandler d.CommandFailed, AddressOf CommandFailed
AddHandler d.CommandCancelled, AddressOf CommandCancelled
End Sub

Sub RemoveHandlers()
Dim d As AcAp.Document =
AcAp.Application.DocumentManager.MdiActiveDocument
RemoveHandler d.CommandWillStart, AddressOf CommandWillStart
RemoveHandler d.CommandEnded, AddressOf CommandEnded
RemoveHandler d.CommandFailed, AddressOf CommandFailed
RemoveHandler d.CommandCancelled, AddressOf CommandCancelled
m_Command = Nothing
End Sub

Sub CommandWillStart(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
If m_Command Is Nothing Then m_Command = e.GlobalCommandName
End Sub

Sub CommandEnded(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
If e.GlobalCommandName = m_Command Then

Dim db As AcDb.Database =
AcDb.HostApplicationServices.WorkingDatabase()
db.SaveAs("C:\Teste.dwg", AcDb.DwgVersion.Current)

RemoveHandlers()
End If
End Sub

Sub CommandCancelled(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
RemoveHandlers()
End Sub

Sub CommandFailed(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
RemoveHandlers()
End Sub

End Module





escreveu na mensagem
news:5372117@discussion.autodesk.com...
Hi:

Can somebody please tell me if it is possible to Synchronously execute a
command sent via SendCommand while using the COM/ActiveX interface in VB
2005? I know I can do this in VBA (in my particular application the
commands
executed via SendCommand are always complete and the program never needs
to
wait for user data), but I was hoping I could do the same using VB 2005.
Unfortunately, so far I have not been able to do that. In the example
below
the SendCommand is executed after the file has been saved and I want it to
execute before the file is saved. Can somebody please tell me if it is
even
possible to do what I want to do?

Any ideas would be greatly appreciated,

Raul


Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports System.IO

Public Class ClsTest

>CommandMethod("Test")> _
Public Sub Test()
Dim OutputPath As String = "c:\Test\dwg"
Dim ObjAcad As AcadApplication
Dim ThisDrawing As AcadDocument
Dim Obj As Acad3DSolid
Dim ZeroOrgin() As Double = {0, 0, 0}
Dim Width as Double = 2
Dim Depth as Double = 4
Dim Length as Double = 8

Directory.Delete(OutputPath, True)
Directory.CreateDirectory(OutputPath)

ObjAcad = DirectCast(GetObject(, "AutoCAD.Application.17"),
AcadApplication)
ObjAcad.Visible = True
ThisDrawing = ObjAcad.ActiveDocument

Obj = ThisDrawing.ModelSpace.AddBox(ZeroOrgin, Width, Depth, Length)
ThisDrawing.SendCommand("_zoom" & vbCr & "e" & vbCr)

' I was hoping the Do Loop below would be the answer to my problem,
' but IsQuiescent is never True and as a result the program hangs.
' Without the Do Loop, the SendCommand is not executed until after
' the drawing is saved, which is not what I want. Any ideas how to
' solve this problem?
Do Until ObjAcad.GetAcadState.IsQuiescent = True
Loop

ThisDrawing.SaveAs(OutputPath & "\Test.dwg")

End Sub
End Class



I'm protected by SpamBrave
http://www.spambrave.com/
Active Contributor
raulpa
Posts: 49
Registered: ‎10-12-2006
Message 4 of 12 (802 Views)

Re: SendCommand

10-24-2006 08:33 AM in reply to: raulpa
James, TP:

Thank you very much for both of your replies. I implemented what I thought you suggested. As you can see from the code below, I created a ClsSendCommand class which contains the MyZoomExtend Sub. The MyZoomExtend Sub is nothing more than a call to the SendStringToExecute Method. Since this behaves the same way as the original code (the zoom extend does not happen until after the Save), I assume I must have misunderstood your suggestion. Could you please tell me where I went wrong?

Thanks again for your help,

Raul


Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices

Public Class ClsSendCommand
Public Sub MyZoomExtend()
' I am aware that the Zoom extend command is probably not a good candidate
' for using either the SendCommand or SendStringToExecute method because the
' Zoom command is already exposed by the COM/ActiveX interface. However,
' this was the simplest example I could find. In reality, I need to use the
' vplayer and solprof commands, which I don't believe are exposed by the
' COM/ActiveX interface.
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_zoom" & vbCr & "e" & vbCr, True, False, False)
End Sub
End Class


Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports System.IO

Public Class ClsTest

>CommandMethod("Test")> _
Public Sub Test()
Dim OutputPath As String = "c:\Test\dwg"
Dim ObjAcad As AcadApplication
Dim ThisDrawing As AcadDocument
Dim Obj As Acad3DSolid
Dim ZeroOrgin() As Double = {0, 0, 0}
Dim Width As Double = 2
Dim Depth As Double = 4
Dim Length As Double = 8
Dim SendCommand As New ClsSendCommand

Directory.Delete(OutputPath, True)
Directory.CreateDirectory(OutputPath)

ObjAcad = DirectCast(GetObject(, "AutoCAD.Application.17"), AcadApplication)
ObjAcad.Visible = True
ThisDrawing = ObjAcad.ActiveDocument

Obj = ThisDrawing.ModelSpace.AddBox(ZeroOrgin, Width, Depth, Length)
' The problem I am having is that the line below does not get executed
' until after the SaveAs
SendCommand.MyZoomExtend()
ThisDrawing.SaveAs(OutputPath & "\Test.dwg")

End Sub
End Class
*tp
Message 5 of 12 (802 Views)

Re: SendCommand

10-24-2006 09:34 AM in reply to: raulpa
you need to call Sub AddHandlers().
I not use AutoCAD.Interop.
it forgives my English
tp

' ========================== START CODE ============================

Imports AcAp = Autodesk.AutoCAD.ApplicationServices
Imports AcDb = Autodesk.AutoCAD.DatabaseServices
Imports AcRx = Autodesk.AutoCAD.Runtime

Public Module Module1

_
Public Sub Teste()
Dim doc As AcAp.Document =
AcAp.Application.DocumentManager.MdiActiveDocument
' First call AddHandlers to inicitiate events
AddHandlers()
doc.SendStringToExecute("_zoom" & vbCr & "e" & vbCr, True, False,
False)
End Sub

Private m_Command As String = Nothing

Sub AddHandlers()
Dim d As AcAp.Document =
AcAp.Application.DocumentManager.MdiActiveDocument
AddHandler d.CommandWillStart, AddressOf CommandWillStart
AddHandler d.CommandEnded, AddressOf CommandEnded
AddHandler d.CommandFailed, AddressOf CommandFailed
AddHandler d.CommandCancelled, AddressOf CommandCancelled
End Sub

Sub RemoveHandlers()
Dim d As AcAp.Document =
AcAp.Application.DocumentManager.MdiActiveDocument
RemoveHandler d.CommandWillStart, AddressOf CommandWillStart
RemoveHandler d.CommandEnded, AddressOf CommandEnded
RemoveHandler d.CommandFailed, AddressOf CommandFailed
RemoveHandler d.CommandCancelled, AddressOf CommandCancelled
m_Command = Nothing
End Sub

Sub CommandWillStart(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
If m_Command Is Nothing Then m_Command = e.GlobalCommandName
End Sub

Sub CommandEnded(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
If e.GlobalCommandName = m_Command Then
Dim db As AcDb.Database
=AcDb.HostApplicationServices.WorkingDatabase()
db.SaveAs("C:\Teste.dwg", AcDb.DwgVersion.Current)
RemoveHandlers()
End If
End Sub

Sub CommandCancelled(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
RemoveHandlers()
End Sub

Sub CommandFailed(ByVal sender As Object, ByVal e As
Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
RemoveHandlers()
End Sub

End Module

' ========================== END CODE ============================



I'm protected by SpamBrave
http://www.spambrave.com/
*Tony Tanzillo
Message 6 of 12 (802 Views)

Re: SendCommand

10-24-2006 10:27 AM in reply to: raulpa
http://www.caddzone.com/CommandLine.cs

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5372117@discussion.autodesk.com...
Hi:

Can somebody please tell me if it is possible to Synchronously execute a command sent via SendCommand while using the COM/ActiveX interface in VB 2005? I know I can do this in VBA (in my particular application the commands executed via SendCommand are always complete and the program never needs to wait for user data), but I was hoping I could do the same using VB 2005. Unfortunately, so far I have not been able to do that. In the example below the SendCommand is executed after the file has been saved and I want it to execute before the file is saved. Can somebody please tell me if it is even possible to do what I want to do?

Any ideas would be greatly appreciated,

Raul


Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports System.IO

Public Class ClsTest

>CommandMethod("Test")> _
Public Sub Test()
Dim OutputPath As String = "c:\Test\dwg"
Dim ObjAcad As AcadApplication
Dim ThisDrawing As AcadDocument
Dim Obj As Acad3DSolid
Dim ZeroOrgin() As Double = {0, 0, 0}
Dim Width as Double = 2
Dim Depth as Double = 4
Dim Length as Double = 8

Directory.Delete(OutputPath, True)
Directory.CreateDirectory(OutputPath)

ObjAcad = DirectCast(GetObject(, "AutoCAD.Application.17"), AcadApplication)
ObjAcad.Visible = True
ThisDrawing = ObjAcad.ActiveDocument

Obj = ThisDrawing.ModelSpace.AddBox(ZeroOrgin, Width, Depth, Length)
ThisDrawing.SendCommand("_zoom" & vbCr & "e" & vbCr)

' I was hoping the Do Loop below would be the answer to my problem,
' but IsQuiescent is never True and as a result the program hangs.
' Without the Do Loop, the SendCommand is not executed until after
' the drawing is saved, which is not what I want. Any ideas how to
' solve this problem?
Do Until ObjAcad.GetAcadState.IsQuiescent = True
Loop

ThisDrawing.SaveAs(OutputPath & "\Test.dwg")

End Sub
End Class
Active Contributor
raulpa
Posts: 49
Registered: ‎10-12-2006
Message 7 of 12 (802 Views)

Re: SendCommand

10-24-2006 10:51 AM in reply to: raulpa
All:

Thank you so much for taking the time to respond. I finally got my problem solved. It looks like the problem was with the way I was using the CommandMethod. Here is the way I was originally using it (notice that I replaced the "<" symbol with ">" just to avoid the online editor from suppressing the entire CommandMethod line):

>CommandMethod("Test")> _

All I needed to do is this instead:

>CommandMethod("Test",CommandFlags.Session)> _

After adding the CommandFlags.Session everything works as expected (i.e. the SendCommands and rest of VB.Net code execute in the order in which they are typed).

Thanks again for your help,

Raul
Active Contributor
jason.brenton
Posts: 38
Registered: ‎10-02-2007
Message 8 of 12 (802 Views)

Re: SendCommand

02-07-2008 10:03 AM in reply to: raulpa
I see many examples of point parameters on commands, but what about selected/passed objects like polylines or blocks?

How are those commands formatted? maybe with the ObjectIds?
*Tony Tanzillo
Message 9 of 12 (802 Views)

Re: SendCommand

02-07-2008 02:23 PM in reply to: raulpa
This is a a topic for the VBA newsgroup.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5841893@discussion.autodesk.com...
I see many examples of point parameters on commands, but what about selected/passed objects like polylines or blocks?

How are those commands formatted? maybe with the ObjectIds?
Active Contributor
jason.brenton
Posts: 38
Registered: ‎10-02-2007
Message 10 of 12 (802 Views)

Re: SendCommand

02-07-2008 02:27 PM in reply to: raulpa
why? i am calling it from a .net dll, not vba

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community