Here’s the code:
And that should select any objects that you want to select. You’ll have to put it in an array though. A handy hint which can save you a bit of grief.
This documents the work I’ve done on the Autocad API.
I will be posting code and helpful methods which you might find of use.
Thank you!
Here’s the code:
And that should select any objects that you want to select. You’ll have to put it in an array though. A handy hint which can save you a bit of grief.
My estimable colleague Rafik Ben made a blog post concerning a problem.
For reference, here it is: http://routetomastery.com/blog/2017/01/08/has-pair-with-some-problem/
So what’s so good about Rafi’s problem?
Well like most things in the world, the problem, is not the actual problem. When it comes to computer science, the *actual* problem lies in identifying or understanding it. And the assumptions one makes are no less important.
Let’s see this in example:
> A man and his son are driving in a car one day, when they get into a fatal accident. The man is killed instantly. The boy is knocked unconscious, but he is still alive. He is rushed to hospital, and will need immediate surgery. The doctor enters the emergency room, looks at the boy, and says…
> “I can’t operate on this boy, he is my son.”
> *How is this possible?*
It’s one of those things where you either have the answer instantly or you will never get it. It’s because your underlying assumptions and expectations were hidden and/or incorrect. The thesis of this post is this: identify the assumptions inherent behind every problem. For in doing so, you will be more likely to solve it successfully.
Assumptions area always inherent in a problem
Every problem has its own assumptions. And these assumptions will drive very different solutions. For example, in the post Rafi made:
Assumptions to consider when formulating algorithms
Some assumptions which I feel are important when considering problems:
Another human related issue: the problem must be understandable to the coder, and easily maintainable:
Summary
Understand the problem and its assumptions, and you’re halfway there.
Here is a gist basically listing the above:
https://gist.github.com/BKSpurgeon/69f624f959e80a7842a2a319d797f120
Question: What is the most exciting thing since sliced bread?
The answer is AutoCad’s associative framework. It’s been two years since it’s been released, and it’s arguably one of the most powerful features of AutoCAD which has now been exposed to .net. You’d hardly know it exists because hardly anyone seems to talk about it in the forums. Anyways, I”m really excited about this new tool and I hope to be walking you all through it in the upcoming few weeks.
There’s a tutorial out there:
http://au.autodesk.com/au-online/classes-on-demand/class-catalog/2014/autocad/sd5217
but I suspect it might be too hard-core for most of you so I really want to simplify it and walk you through the process. I hope you’ll derive as much pleasure from devouring it, as I will have producing it.
What is the benefit?
It’s just really really cool
Ben
There’s not much out there in the way of introductions. You’d have to wade through some manuals and it can be tedious. A simple walk through of how to get started. You would do well to record it at 1.5-x2 playback speed.
Autocad .net c# Plug in – Hello World Example from Tek1 on Vimeo.
Ok, so you’ve got a bunch of entities in a collection. You only want to deal with circles. You need to iterate through the collection and consider only the circles. But how will you identify the circles from the other objects.
You can cast
Entity en = en as Circle
And then you can test whether entity is null.
If (en == null )
{ // throw new Exception etc. etc. }
Or you can try the equivalent:
If (en is Circle)
{ // Perform operation etc. etc.}
What is the catch with this approach?
I’ve also seen folks on the forums use the Gettype to check for the type of the entity. It goes something like this:
en.GetType() == typeOf(Circle)
The Catch with this approach
Another approach is to use Dxf codes to check for the name. But this is overcomplicated. I don’t see many people using it on the forums and you need the object ID of the relevant entity and all the overhead associated with it.
In my opinion, keep it simple. Casting, after all things considered, is probably the best option, but you have to watch out – all subclasses will return true. So you need to use the most granular class you can if that is at all important.
It is very common that you will need to create selection filters for different types of blocks. Why repeat yourself?
There is a very simple utility that I wrote that is amazingly handy for solving this very issue. Best part is that it accepts wildcards, so you can search for block references which, for example, start with Fire by passing in “FIRE*” as the argument:
public static SelectionFilter GetSSFilterBlockReferenceByName(string name)
{
TypedValue[] filterlist = new TypedValue[2];
filterlist[0] = new TypedValue(0, “INSERT”);
filterlist[1] = new TypedValue(2, name);
SelectionFilter filter = new SelectionFilter(filterlist);
return filter;
}
So simple!
When dealing with selection sets we can obtain the object ids of the objects contained within. The method though, returns an array.
But what if we want an ObjectIDCollection?
We can simply pass the ObjectID[] array into the ObjectIDCollection constructor.
Simple. The last thing you want to do is iterate through the array and add it to a collection individually. A simple yet handy hint which can save you a lot of effort.
Batch Processing Using AcCoreConsole is now here.
What is AcCoreConsole?
Example:
Watch the Video: It is will explain the technical stuff below:
For Geeks Only:
Geek-speak: How does it work? (It might not make sense to most of you guys but that’s ok – all you need to know is that you CAN automate things if you want to):
Here is my ScriptFile:
(Remember when pasting that you have to add the .scr extension)
My .net DLL:
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
If you have any questions: Go ahead and call me!
AcCoreConsole is AutoDesk’s brand new toy. It is basically a command line version of AutoCAD. It has no “User Interface”. That means that if you are a user, there are no menus to click on. No buttons. Nothing. You have to do everything via text. Via command line, like it was in the very beginning.
You cannot see lines.
What is the benefit of this you ask? Well it allows for super fast batch processing.
Please watch my screencast for a very brief introduction to this new technology. I will provide another video of the batch processing power of this babey.
https://knowledge.autodesk.com/community/screencast/d6ef5929-4208-443d-8b53-eca0c637328a
I hope you learn something.
Ben