.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SendCommand

11 REPLIES 11
Reply
Message 1 of 12
raulpa
1898 Views, 11 Replies

SendCommand

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
11 REPLIES 11
Message 2 of 12
Anonymous
in reply to: raulpa

Break the sequence up into parts and then use AutoLISP or ARX to control the
sequencing.
Message 3 of 12
Anonymous
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/
Message 4 of 12
raulpa
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
Message 5 of 12
Anonymous
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/
Message 6 of 12
Anonymous
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
Message 7 of 12
raulpa
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
Message 8 of 12
jason.brenton
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?
Message 9 of 12
Anonymous
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?
Message 10 of 12
jason.brenton
in reply to: raulpa

why? i am calling it from a .net dll, not vba
Message 11 of 12
Anonymous
in reply to: raulpa

wrote in message

>> why? i am calling it from a .net dll, not vba

You are calling what from a .NET dll?

A managed ObjectARX API, or an ActiveX API?

We mainly discuss using the managed ObjectARX API here, not the VBA/ActiveX API.

Your question about SendCommand() has the same answer regardless of what programming langauge you're calling it from, and has been asked and answered dozens of times in the VBA newsgroup (hint: search that newsgroup on the keyword "handent").

It may be called the VBA newsgroup, but it would more accurately be called the ActiveX newsgroup, because many topics about that API are discussed there, including those related to using it from standalone VB6 (not VBA); Delphi; C#; and other ActiveX-enabled development tools.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
Message 12 of 12
jason.brenton
in reply to: raulpa

well that is more clear of a response, as most likely SendStringToExecute uses similar style. either can be found. I'll check.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost