Get the object created from the command HATCHGENERATEBOUNDARY

Get the object created from the command HATCHGENERATEBOUNDARY

nguyenthanguth
Contributor Contributor
553 Views
2 Replies
Message 1 of 3

Get the object created from the command HATCHGENERATEBOUNDARY

nguyenthanguth
Contributor
Contributor

Hello.

 

I have a Hatch object and I want to create a Poyline (sometimes Circle) around the Hatch.

 

I looked through the AutoCAD API docs but couldn't find an implementation of the `HATCHGENERATEBOUNDARY` command in the C# API.

 

So I did it via Command:

ed.Command("HATCHGENERATEBOUNDARY", hatch.ObjectId, "");

 

and CommandAsync:

CommandResult commandResult = ed.CommandAsync("HATCHGENERATEBOUNDARY", hatch.ObjectId, "");
commandResult.OnCompleted(() => { });

 

nguyenthanguth_0-1715414636262.png

 

I want the return result to be the created object. Can someone help me how to do it. Thanks

 

0 Likes
Accepted solutions (1)
554 Views
2 Replies
Replies (2)
Message 2 of 3

ActivistInvestor
Mentor
Mentor
Accepted solution

Just before you call Command(), you can add a handler to the Database's ObjectAppended event to capture newly-created objects, and then remove the handler from the event after Command() returns. Don't use CommandAsync() because it isn't needed (and rarely is).

 

 

0 Likes
Message 3 of 3

ActivistInvestor
Mentor
Mentor

Through a grueling process of copying, pasting and deleting, I was able to lobotomize code that provides a method I've used in place of the Editor's Command() method for a long time, and was able to get a minimal working version of it that automates the process I described above.

 

Rather than have to resort to the P/Invoke acdbEntLast() hack, this solution gives you all objects created by a command's execution, rather than only the last one.

 

You can find it here.

0 Likes