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

parameter ename for an extern command

13 REPLIES 13
Reply
Message 1 of 14
base2
495 Views, 13 Replies

parameter ename for an extern command

Ho guys..

I have this problem.
I have an extern command (inside an other file arx) that i must invoke it.

---------------------------------------------------------------------
ResultBuffer args = new ResultBuffer();
int stat = 0;
string se = ent.ObjectId.OldId.ToString();
args.Add(new TypedValue(RTSTR, "MYCOMMAND"));
args.Add(new TypedValue(RTENAME, entity.Id));
args.Add(new TypedValue(RTSTR, "c:\\temp\\myfile.ccc"));
// end resbuf command adn arguments...

// i call the command by resbuf...
IntPtr rb = IntPtr.Zero;
stat = acedInvoke(args.UnmanagedObject, out rb);
if (stat == (int)PromptStatus.OK && rb != IntPtr.Zero)
return (ResultBuffer)
DisposableWrapper.Create(typeof(ResultBuffer), rb, true);

-----------------------------------------------------------------------------

It seems that the argument ename isn't good....(no bad error or crash occurred) but the result of acedInvoke is -5001!
entity is an entity object get by my select...

any suggest or help is appreciated... 😉
thank You in advance
13 REPLIES 13
Message 2 of 14
Anonymous
in reply to: base2

Check this sample:
[code]
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
private static extern Int32 acedRedraw(long [] name, Int32 mode);
#if ACADR16
[DllImport("acdb16.dll", CallingConvention=CallingConvention.Cdecl, EntryPoint="?acdbGetAdsName@@YA?AW4ErrorStatus@Acad@@AAY01JVAcDbObjectId@@@Z")]
#elif ACADR17
[DllImport("acdb17.dll", CallingConvention=CallingConvention.Cdecl, EntryPoint="?acdbGetAdsName@@YA?AW4ErrorStatus@Acad@@AAY01JVAcDbObjectId@@@Z")]
#endif
private static extern int acdbGetAdsName(long [] name, ObjectId objId);

[CommandMethod("MyRedraw")]
static public void MyRedraw()
{
acedRedraw(null, 1);
}
// Highlight entity
[CommandMethod("HlEnt")]
static public void HlEnt()
{
PromptEntityOptions entityOpts = new PromptEntityOptions("\nSelect entity: ");
PromptEntityResult rc = Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(entityOpts);
if (rc.Status == PromptStatus.OK)
{
long [] ent = new long [] { 0, 0};
acdbGetAdsName(ent,rc.ObjectId);
acedRedraw(ent, 3);
}
}
[/code]
Message 3 of 14
base2
in reply to: base2

now i catch an exception...HERE:
args.Add(new TypedValue(RTENAME, entname));...
From the code below...
attached the value of entname and it's seems good..!



// code modified...
long[] entname = new long[] { 0, 0 };
acdbGetAdsName(entname, ent.ObjectId);
ResultBuffer args = new ResultBuffer();
int stat = 0;
string se = ent.ObjectId.OldId.ToString();
args.Add(new TypedValue(RTSTR, "EXTERNCOMMAND"));
args.Add(new TypedValue(RTENAME, entname));
args.Add(new TypedValue(RTSTR, ""));
args.Add(new TypedValue(RTSTR, "c:\\temp\\aaa.CCC"));


a
Message 4 of 14
Anonymous
in reply to: base2

Try:
args.Add(new TypedValue(RTENAME, entname[0]));
Message 5 of 14
base2
in reply to: base2

the same exception... and i don't know why...
Your suggest looks good... but i'm sorry... it's don't works! 😞
Message 6 of 14
base2
in reply to: base2

I reply to Myself...
i supposed that the problem is the extern command...not defined as function!
if it's true I cannot call it via acedinvoke.
but the problem remain.. I cannot call the command via sendstringtoexecute 'cause it need to some parameters..
Message 7 of 14
Anonymous
in reply to: base2

First, it is a real bad idea to pass to any command,
an object that is currently open in your app.

As far as how to use the external command, it depends
on how the external command is implemented.

Can you use the LISP (command) function to execute
the command? If so then you should be able to use
acedCmd().

See 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:5416234@discussion.autodesk.com...
I reply to Myself...
i supposed that the problem is the extern command...not defined as function!
if it's true I cannot call it via acedinvoke.
but the problem remain.. I cannot call the command via sendstringtoexecute 'cause it need to some parameters..
Message 8 of 14
base2
in reply to: base2

thanks! I've followed the acedCmd way...and also isn't a good way for me ..it works.
The object is not opened..in my application.
Why do You said that ? If I have an entity readed by select it's closed..
isn't it ?

I resume my code...

startmydialog..
getentity-->>(bal bla...) select pick ona object
acedcmd( bla bla ... invoke extern command )
restoredialog..

it's seems ok.
If you see some problem in this ...could You tell me where it is ?

thank You very much for your suggest 😉
Message 9 of 14
Anonymous
in reply to: base2

Your code shows the use of an Entity,
and references its ObjectId or Id property,
but it does not show where the entity is
closed.


--
http://www.caddzone.com

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

wrote in message news:5416522@discussion.autodesk.com...
thanks! I've followed the acedCmd way...and also isn't a good way for me ..it works.
The object is not opened..in my application.
Why do You said that ? If I have an entity readed by select it's closed..
isn't it ?

I resume my code...

startmydialog..
getentity-->>(bal bla...) select pick ona object
acedcmd( bla bla ... invoke extern command )
restoredialog..

it's seems ok.
If you see some problem in this ...could You tell me where it is ?

thank You very much for your suggest 😉
Message 10 of 14
base2
in reply to: base2

I understood...
You said that a row as:

Entity ent = (Entity)trans.GetObject(ids[0], OpenMode.ForRead, false);

followed by
-->acedcmd( bla bla ... invoke extern command, ent )
--> ent.close();
-->restoredialog..


it's a little dangerous...
maybe...but it's the only way that i know to use the entity as parameter. is there another way...?
Message 11 of 14
Anonymous
in reply to: base2

As far as passing the entity as a param, you
don't need it. You only need its object id, and
for that you don't even need to open it, as
the object id is needed to do that.

To say what you're doing is a little dangerous
is an understatement. You need to learn more
about the API, and specifically the perils of
leaving objects open longer than you need to.

--
http://www.caddzone.com

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

wrote in message news:5417816@discussion.autodesk.com...
I understood...
You said that a row as:

Entity ent = (Entity)trans.GetObject(ids[0], OpenMode.ForRead, false);

followed by
-->acedcmd( bla bla ... invoke extern command, ent )
--> ent.close();
-->restoredialog..


it's a little dangerous...
maybe...but it's the only way that i know to use the entity as parameter. is there another way...?
Message 12 of 14
base2
in reply to: base2

sorry, it's a little hard to me understand the real problem...

ResultBuffer args = new ResultBuffer();
args = new ResultBuffer();
args.Add(new TypedValue(RTSTR, "EXTERCOMMAND"));
args.Add(new TypedValue(RTENAME, ent.Id));
args.Add(new TypedValue(RTSTR, ""));
args.Add(new TypedValue(RTSTR, "c:\\temp\\gege.CCC"));

Command(args); // THIS Perform acedcmd..

You said that I can substitute this
args.Add(new TypedValue(RTENAME, ent.Id));
with a similiar expression...
args.Add(new TypedValue(RTENAME, Ids[0]));
without entity opened.... where ids[0] it's the id selected by user...
Message 13 of 14
Anonymous
in reply to: base2

sorry I do not follow you.

The ObjectId that you pass to GetObject() is the
same as the ObjectId that's returned by the resulting
object's Id property.

So, if the only reason you are opening the object
is to get its object id, then there is no point to it,
because you already have the object id.

--
http://www.caddzone.com

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

wrote in message news:5418111@discussion.autodesk.com...
sorry, it's a little hard to me understand the real problem...

ResultBuffer args = new ResultBuffer();
args = new ResultBuffer();
args.Add(new TypedValue(RTSTR, "EXTERCOMMAND"));
args.Add(new TypedValue(RTENAME, ent.Id));
args.Add(new TypedValue(RTSTR, ""));
args.Add(new TypedValue(RTSTR, "c:\\temp\\gege.CCC"));

Command(args); // THIS Perform acedcmd..

You said that I can substitute this
args.Add(new TypedValue(RTENAME, ent.Id));
with a similiar expression...
args.Add(new TypedValue(RTENAME, Ids[0]));
without entity opened.... where ids[0] it's the id selected by user...
Message 14 of 14
base2
in reply to: base2

of course! i'm very blind! 😞
thank You very much !!!

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