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

Having problems with sendcommand

15 REPLIES 15
Reply
Message 1 of 16
iwtblj
2356 Views, 15 Replies

Having problems with sendcommand

I'm using sendcommand instead of SendStringToExecute because I need to execute right away, but the problem is that it doesn't seem to be doing that.

{code}

app.ActiveDocument.SendCommand("(setq e (handent " & Chr(34) & Poly.Handle & Chr(34) & ")) \n")
app.ActiveDocument.SendCommand("fillet p !e \n")
plypts = Poly.Coordinates

{code}

After I run the fillet command, the coordinates in Poly should be updated, or at least they were in VBA, but their not. They don't change at all. Can anyone help me with this?

Thanks Edited by: iwtblj on Dec 15, 2009 11:09 PM
15 REPLIES 15
Message 2 of 16
Anonymous
in reply to: iwtblj

This is the typical VBA-style hacking that most have switched to .NET
precisely for the reason of not having to resort to that nonsense. I realize
that there a certain blogger seems to think this sort of kludgery is
acceptable, but it's really not because it basically solves one problem, and
creates many more in the process.

Where are you running this code from? A registered command? A modeless
dialog or control on a PaletteSet?

How to solve the problem depends on the answer.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6305404@discussion.autodesk.com...
I'm using sendcommand instead of SendStringToExecute because I need to
execute right away, but the problem is that it doesn't seem to be doing
that.

{code}

app.ActiveDocument.SendCommand("(setq e (handent " & Chr(34) & Poly.Handle &
Chr(34) & ")) \n")
app.ActiveDocument.SendCommand("fillet p !e \n")
plypts = Poly.Coordinates

{code}

After I run the fillet command, the coordinates in Poly should be updated,
or at least they were in VBA, but their not. They don't change at all. Can
anyone help me with this?

Thanks

Edited by: iwtblj on Dec 15, 2009 11:09 PM
Message 3 of 16
iwtblj
in reply to: iwtblj

It's from a registered command
Message 4 of 16
Anonymous
in reply to: iwtblj

The code here should help:

http://www.caddzone.com/CommandLine.vb

Use it like the AutoLISP (command) function, rather than
like VBA's 'SendCommand', and you do not have to pass
LISP expressions to convert handles to entity names, you
can just pass an ObjectId where the LISP (command)
equivalent takes an entity name.

Where 'id' is the ObjectId of the polyline you want to fillet,
it would work like this:

CommandLine.Command( "._FILLET", "_P", id )

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6305635@discussion.autodesk.com...
It's from a registered command
Message 5 of 16
iwtblj
in reply to: iwtblj

I've tried

CommandLine.Command("._FILLET", "_P", poly.ObjectID)

as well as

CommandLine.Command("._FILLET", "_P", poly.ObjectID.tostring)

but when I run this, *Invalid selection*
Message 6 of 16
Anonymous
in reply to: iwtblj

This works for me, with either light or heavy polylines:

{code}

public static class Test
{
[CommandMethod( "FILLETPOLY" )]
public static void FilletPolyCommand()
{
PromptEntityOptions peo =
new PromptEntityOptions( "\nSelect a polyline: " );
peo.SetRejectMessage( "\nInvalid input, requires a polyline," );
peo.AddAllowedClass( typeof( Polyline ), false );
peo.AddAllowedClass( typeof( Polyline2d ), false );
Document doc = Application.DocumentManager.MdiActiveDocument;
PromptEntityResult per = doc.Editor.GetEntity( peo );
if( per.Status == PromptStatus.OK )
CommandLine.Command( "._FILLET", "_P", per.ObjectId );
}

}

{code}

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6307830@discussion.autodesk.com...
I've tried

CommandLine.Command("._FILLET", "_P", poly.ObjectID)

as well as

CommandLine.Command("._FILLET", "_P", poly.ObjectID.tostring)

but when I run this, *Invalid selection*
Message 7 of 16
iwtblj
in reply to: iwtblj

Ah, I see. I was using the COM objectId instead of the .NET one. It works now. Thanks.
Message 8 of 16
Anonymous
in reply to: iwtblj

Looking at your OP again, I suspect you're using ActiveX rather than the
managed API.

If so, you can do it thusly:

Dim pline As AcadLWPolyline pline = ....

Dim id As ObjectId = DBObject.FromAcadObject( pline );

CommandLine.Command( "._FILLET", "_P", id )



--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6307830@discussion.autodesk.com...
I've tried

CommandLine.Command("._FILLET", "_P", poly.ObjectID)

as well as

CommandLine.Command("._FILLET", "_P", poly.ObjectID.tostring)

but when I run this, *Invalid selection*
Message 9 of 16
wouterbleumink4428
in reply to: iwtblj

Hi Tony,

First of, i am not a professional programmer, but an enthousiast. So excuse me if i am asking something stupid.

I would like to use your CommandLine.vb with my app.

I would like to convert a large number of 3Dsolid's to individual MassElement's (an Autocad Architecture object).
There is a command available called MassElementConvert
next you have to select the object to convert (i'd like to use your code to parse the objectID)
then it askes you if you want to erase the source object's
then i want to add a description
enter the description

Is this possible to do with your code? I am also creating a registered command.

When i load your CommandLine.vb into VB.NET 2008 Express i get an error stating that 'Type 'Dictionary' is not defined'. Do i need and extra import (Autodesk runtime perhaps) or is this solved otherwise?

Thanx in advance and best regards,

Wouter
Message 10 of 16
Anonymous
in reply to: iwtblj

I was able to compile CommandLine.vb as is, but perhaps there is something else
in the VB test project that's missing from your project.

Try changing this line at the top of the file:

Imports System.Collections

To this:

Imports System.Collections.Generic

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6312997@discussion.autodesk.com...
Hi Tony,

First of, i am not a professional programmer, but an enthousiast. So excuse me
if i am asking something stupid.

I would like to use your CommandLine.vb with my app.

I would like to convert a large number of 3Dsolid's to individual MassElement's
(an Autocad Architecture object).
There is a command available called MassElementConvert
next you have to select the object to convert (i'd like to use your code to
parse the objectID)
then it askes you if you want to erase the source object's
then i want to add a description
enter the description

Is this possible to do with your code? I am also creating a registered command.

When i load your CommandLine.vb into VB.NET 2008 Express i get an error stating
that 'Type 'Dictionary' is not defined'. Do i need and extra import (Autodesk
runtime perhaps) or is this solved otherwise?

Thanx in advance and best regards,

Wouter
Message 11 of 16
wouterbleumink4428
in reply to: iwtblj

It works now, thank you!

Maybe you can help me with this:

My code copies object on certain layer's to a new drawing. So far so good.

But i want my code to begin execution on the base-drawing, and as soon as the object's are copied to the new drawing i want the code to continue executing on the new drawing. I tried to set the new drawing as 'active document', but when i execute the code get's executed on the base-drawing instead of the new one.

TIA

Wouter
Message 12 of 16
Anonymous
in reply to: iwtblj

You have a problem in that case.

When your code runs in the document context (e.g., a CommandMethod), you cannot
switch documents without your code being suspended until the document it was
started in becomes active again.

You can run your code in the application context, but unfortunately from that
context you cannot use the Command() method.

The only possible solution would be to eliminate the use of the Command() method
and do it the hard way (via the API), and then execute your code in the
application context, by adding the 'CommandFlags.Session' flag to the
CommandMethod attribute for the command.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6313761@discussion.autodesk.com...
It works now, thank you!

Maybe you can help me with this:

My code copies object on certain layer's to a new drawing. So far so good.

But i want my code to begin execution on the base-drawing, and as soon as the
object's are copied to the new drawing i want the code to continue executing on
the new drawing. I tried to set the new drawing as 'active document', but when i
execute the code get's executed on the base-drawing instead of the new one.

TIA

Wouter
Message 13 of 16
wouterbleumink4428
in reply to: iwtblj

Thank you for your reply.

I focused on using your CommandLine.vb. The following code is used to send the command:

CommandLine.Command("_MassElementConvert", gpid, "Y ", "D ", Omschrijving.ToString)

gpid contains the ObjectID from a Autocad.Group

But when executed, the code returns the following from autocad:

_MassElementConvert

Select objects to convert: <Bad Entity name: FFFFFFFFFFB702A0>
Y D Riolering

Any suggestions as to what i am doing wrong?

TIA, Wouter

Message 14 of 16
wouterbleumink4428
in reply to: iwtblj

Tony,

Is it possible to send an 'cancel' (like an ESC key-stroke) command using your CommandLine.vb?

Thanx
Message 15 of 16
Anonymous
in reply to: iwtblj

You can't pass groups to Command(), you have to pass an array
of the objectids and an empty string after that:

Dim entityIds As ObjectId() = Nothing

Database db = HostApplicationServices.WorkingDatabase
Using trans As Transaction = db.TransactionManager.StartTransaction()
Dim grp As Group = trans.GetObject(OpenMode.ForRead, False)
entityIds = grp.GetAllEntityIds()
trans.Commit()
End Using

' All transactions should be ended before callling Command() !!!

CommandLine.Command("_MassElementConvert")
CommandLine.Cmd( entityIds )
CommandLine.Command( "", "Y ", "D ", Omschrijving.ToString )

Regarding cancelling commands, the version of CommandLine.vb you
have does not do that, but I just posted a revised version it does at the
same URL. With it, you can cancel a command, by calling Command()
with no arguments.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6313946@discussion.autodesk.com...
Thank you for your reply.

I focused on using your CommandLine.vb. The following code is used to send the
command:

CommandLine.Command("_MassElementConvert", gpid, "Y ", "D ",
Omschrijving.ToString)

gpid contains the ObjectID from a Autocad.Group

But when executed, the code returns the following from autocad:

_MassElementConvert

Select objects to convert:
Y D Riolering

Any suggestions as to what i am doing wrong?

TIA, Wouter
Message 16 of 16
wouterbleumink4428
in reply to: Anonymous

Hello Tony,

 

It has been a while since my last reaction.

 

Thank you again for your code concerning commandposting.

 

But i still can't cancel a command using your routine. When i call CommandLine.Command() without args the execution crashes stating 'eInvalidResBuf'

 

I tried to fix this, but allas, i am not sure what to change. could you help out?

 

TIA and regards,

 

Wouter

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