Precast Blog
Author: admin
-
-
Autocad Plug-in: Creating Order Forms Automatically
Normally creating order forms are a nightmare.
How does everyone else create order forms?
I have no idea how people do it. They would have to manually count/iterate through every single block which exists in the model space and simultaneously note down the parts’ associated panel number(s). They could do it on their PC, or they could do it on paper. And the worst part is, is that it would distract them from doing some real work. (Or work that they would rather be doing).
Trust me – I’ve been doing monkey work like this since I was a kid. Counting panels, counting beams, counting parts: it really is a crime against humanity. Not only is it painfully tedious, it’s error prone: it’s like trying to count the stars in the sky: it is very easy to lose count, to lose your place, or to make mistakes.
Automatic Order Forms Demo – The power of the Autocad API customisation
The power of the Autocad .Net API breaks the back of it for you. I begged the head boss to let me release this to the public, just to give you an idea of the cool things that the API can do. I now present to you automated order forms: no more counting. No more errors. All done in less than 5 minutes (as opposed to five hours).
-
WPF Tunnelling – Explanation by analogy
Tunnelling – What is it?
And no, I’m not referring to how El Chapo escaped.
Refresher: what is bubbling?
In the last post we talked about “bubbling”.
It’s kinda like those instances where you get a parking fine. If you don’t deal with it then, you’ll get another fine. If you don’t deal with it there, you will get a notice from the county court. Still not paying? Soon the police will come knocking – and like with all things – especially lies and drugs, things keep progressing to ever increasing heights of danger and pain and turmoil. Pretty soon you could end up going to jail simply because you didn’t pay a parking fine. But if you dealt with it properly at the time – well there would be no need to spend 2 years in prison for it. (Do you think I am kidding? Guess again. Why oh why wasn’t the “event” dealt with early before it bubbled up to become more serious? An excellent question. I suppose you would have to ask what was going through the mind of the judge.
Tunneling is the exact oppose of bubbling
Nebuchadnezzar was once the top dog in all the land. Nobody could so much as breath without obtaining his express written consent. All life, energy and glory started with him. But suppose something happens, suppose someone in the privacy of his own room refused to bow down to the great emperor. What did he do? He issues an event to find the culprit.
He has an extensive network of spies. And word travels pretty quickly so this is how they would have found the guilty culprit:
- The King asks his Prime minister who did it.
- The prime ministers ask State delegates.
- The state delegates ask the county delegates
- The county people ask local area managers.
- The local area managers ask every Tom, Dick and Harry on the street.
- And the people on the street finally identify Daniel as the guy who refuses to bow down.
In other words, an event begins at the top and works its way down the hierarchy to the control element responsible for triggering the event.
Now that was simple, wasn’t it?
-
What is a routed event?
What is a routed event?
This is the answer that is typical on Stack Overflow sites and other such forums:
A routed event is a type of event that can invoke handlers on multiple listeners in an element tree, rather than just on the object that raised the event.
It seems – with all due respect to those coders – are not applying the old programming adage:
Always write explanations as if the guy who ends up reading it is a violent psychopath who knows where you live.
Now such MSDN techno-speak just hurts everyones’ heads. Why can’t they just speak plain English? I’m no expert, but here it is explained simply so that you can understand:
Explanation By Analogy: What is a routed event?
Our judicial system employs routed events. Suppose that somebody commits a crime. This is an “event”. This event can be handled in any one of the following courts, (from the lowest court to the highest court in the land, respectively):
- Lower/Magistrate court
- County/Distruct Courts
- Supreme Court
- State/Territory Court
- The High Court
- The Privy Council
- and above that: The Supreme Court of the Galactic Republic
Now, as is the case, all courts have jurisdiction over the matter. A petty theft can be tried in the High Court – if you wanted to. The High court has jurisdiction, but is that what you really want? Most cases start off in the Lower courts, and then, if required, the matter is passed onto a higher court. And if so required, that court passes on the matter to a still higher court. It can go all the way to the top.
Or on the other hand, if you so decide: the theft can be handled at the lower court, and the matter can end there.
Routed events work the same way. If an event happens in the lower court, you, the programmer, can so choose to have the event “bubble up” and be handled by a higher court. The matter can go as high up as you wish and can be taken care of there.
Now that, in effect, is how routed events work. Something which starts in the Lower Court can be passed on and can be “handled” and heard in the Privy Council. And that’s it! So simple? Yet everyone tries to make it so complicated!
-
What is an event?
Assumed knowledge:
- Assume you know what a method is.
What is an event?
Let’s keep it simple. An event is anything which “happens”. “Oh great! That helps a lot :’( ,“ I hear you say. Examples are in order:
- The President comes to town. He could come at anytime. You don’t know when he could come. So when he comes, it’s an event.
- Somebody wins the lottery.
- A house catches fire.
- Somebody clicks a button.
All of these are events.
What happens next?
- Subscribers explained
What happens when an event happens? Anything you want!
Just say a house catches on fire. We will call this event “HouseFireEvent”. When this event is raised (i.e. when it happens), the following occur:
- People start screaming “OMMAGOD OMMAGAD!” (let’s call this the scream method)
- They call the fire department. (let’s call this the call-fire-department method)
- A fireman puts the fire out. (let’s call this the extinguish method).
In other words, the above methods are “called” when the house-fire event is raised. The house-fire event in fact maintains a list of methods which occur or are run when an event is raised. These methods are called subscribers. How can an event maintain a list of methods you ask? Good question. Usually there is a big book the fire warden in the floor of your department has tucked away in the back drawer of his desk. This book details all the protocols which must be followed when there is a fire. i.e. examples include: (i) staying calm, (ii) taking any valuables you have with you but no more, (iii) evacuating the building in an orderly and calm manner. These instructions, or “methods” are also known as “event handlers” because they are procedures which are called when a particular event occurs.
So in the above example, the event handlers would be: (i) Scream method, (ii) call-fire-department method and lastly (iii) the extinguish method.
………that’s it – it’s as simple as that!
-
What is a call-back function?
Example by Parable and Analogy
I have a secretary. At the end of the day, I ask her to: (i) take the firm’s outgoing mail and to drop it off at the post office, and in addition to that, after she has dropped the mail off, I ask her to do something else: (ii) whatever task I wrote for her on one of those sticky notes. Now, what is the task on the sticky-note? It depends on the day. Sometimes it might be to: (i) purchase some stationary. Other times it might be to: (i) file some papers, (ii) send some emails, (iii) print some documents etc.
Suppose on this particular day, I require her to print off some documents. In summary, first, she needs to drop off the mail and immediately after that is done, she needs to print off some documents.
Applying the story to some techno-computer geek speak
The method name in this case is: DropOffMail. And the call back function is: PrintOffDocuments. The PrintOffDocuments is the call back function because we want the secretary to do that, only after PrintOffDocuments has run.
So I would “pass: PrintOffDocuments as an “argument” to the DropOffMail method. Now the DropOffMail method must be able to accept functions in its method signature. After the DropOffMail is run, then the call back function, PrintOffDocuments would be called and would run.
So in short, the mail would be delivered, and she would run a print job (which would be the call-back function).
I hope that was simple enough for you!
-
What is an ObservableCollection?
For those wanting a simple answer without the geek-speak, I’ll try to explain:
Normal Collections
Every now and then I go to NYC and my friend asks me to buy stuff for him. So I take a shopping list with me. The list has a lot of things on there like:
- Hugo Boss jacket
- Clive Christian’s Imperial Majesty ($215,000/16.9 oz.)
- Mont Blanc – pen. $500.
- Fur coat. ($4500)
- Ferrari ($750,000)
Well I”m not buying that stuff. Way tooo expensive! So I cross them off and remove them from the list and I add in:
- 12 dozen Titleist golf balls.
The ObservableCollection
So I come home and my friend is not pleased. But that was in the old days, now he’s got onto this whole smart phone thing – and he now has an Iphone with an IShoppingList app that’s on the cloud. Here’s how it works: whenever you remove something from the online shopping list on the cloud: he gets a notification on his phone (i.e. an sms or email etc) and in addition to that stuff happens. What happens exactly? Usually a phone call asking me to put the stuff back on the list.
The observable collection works just the same way. If you add or remove something to or from it: someone is notified. And when they are notified, they do stuff. What stuff exactly? Well whatever you want! they can sing, dance, do the hokey-pokey etc.
That sums it all up!
-
The difference between Synchronous and Asynchronous Execution
Synchronous Execution
My boss is a busy man. He tells me to write the code. I tell him: Fine. I get started and he’s watching me like a vulture, standing behind me, off my shoulder. I’m like “Dude, WTF: why don’t you go and do something while I finish this?”
he’s like: “No, I”m waiting right here till you finish it off”. This is synchronous
Asynchronous Execution
The boss tells me to do it, and rather that waiting right there for my work, the boss goes off and does other tasks. When I finish my job I simply report to my boss and say: “I’m DONE!” This is Asynchronous Execution.
…….it really boils down to something as simple as that!
-
Getting a Selection Set
This is a code block from my award winning BlockUtility static class.. But you would want to create the selectionFilter according to your own requirements – hence I have not used a static class for getting the selection filter. Apologies for the lack of readability in my code. The blog just kills the formatting.
What do we want to do?
- We want to prompt the user to select some objects on the screen.
- And we want to select only certain objects using a selection filter and
- we want to place all the filtered objects in a selection set.
And Viola! You now have your selection set which you can use to further read and manipulate Autocad objects!
