Description
Key Learnings
- Learn how to create custom grips with GripOverrule.
- Learn how to create custom grip with context menu.
- Learn about associating actions to custom grips.
- Learn about using data with custom grips.
Speaker
- NYNorman YuanNorman Yuan is a civil engineer turned software developer, and has been doing AutoCAD programming over 20 years since mid-1990s. His software development career started from using AutoLISP and then AutoCAD VBA, then expanded to generic software development for enterprise information system, covering desktop applications, web applications, database development/management. Norman has been primary custom AutoCAD application developer for a few companies of different sizes. He is currently working with WSP, a huge global engineering consulting company. His office is based in Edmonton, AB, Canada (WSP Canada Inc.). He is now narrowing his software development scope to be more focused on AutoCAD-related work processes in the company. Norman is a member of Autodesk’s Expert Elite program and posts AutoCAD programming related articles at his blog "Drive AutoCAD with Code".
NORMAN YUAN: OK, let's get started. This class is about using custom grip to enhance user interaction with the AutoCAD entities. I'm Norman Yuan, and I'm a software developer, IT consultant. I've been working on this. I've been in-- attended Autodesk University for quite a few times, and I've been giving the class speech two or three times.
OK, so a little bit of my background information. I've been using AutoCAD for more than 30 years, since the late 1980s. And started doing [? has ?] [INAUDIBLE] [? engineer, ?] and later moved on to programming and started AutoCAD programming since early 1970s. So it's almost 30 years.
So I believe some of you are interested in AutoCAD programming, you must have a very likely run into my blog here. Let me just quickly show here. My blog here. As you can see, I have my blog first posted since 2009 till now, over 10 years, have over maybe 100 or 200 posts there.
OK, now about this class. So who the audience of this class is talking to? So let's see. It should be someone who does AutoCAD customization and programming. Obviously, because this topic is about AutoCAD programming, so you at least need to know some of AutoCAD programming [INAUDIBLE] something.
Concretely, so some of you maybe, at least it would be best to have some very basic AutoCAD done at API programming because this class is totally about using AutoCAD.net API to do the custom grip API grip programming.
So in this case, of course, if you want to do AutoCAD.net API programming, obviously, you need have a very basic knowledge about Microsoft.NET framework programming.
Then maybe some of you may have AutoCAD less programming, VBA [? programming ?] experience, and only haven't started move on to AutoCAD.net API programming or just started.
So obviously, in this case, you may be a little bit hard for you or be hard to look into the code to understand everything. But in this class, I will focus on to show what we can do with .API to customize the entity grip rather than focus on the code itself.
So I think this will inspire some of you who has a list of [? ABA ?] programming experience who want to jump onto the .net API programming wagon, or get started because, from my personal experience, when I before work a lot less [? than ?] VBA. Once I moved to .net API, I saw this amazing capability with .API to manipulate grips. I thought, wow, I really want to do that because as a [? list ?] programmer and [? VBA ?] programmer, you just cannot do that, right? So that's why whoever attend to this class.
Now, goes let's get started with the real topic of this class.
Firstly, what is entity grip? As you can see, every AutoCAD user knows that-- you can see, whenever if you have a graph entities in AutoCAD editor, once you click to select it, you will see there's a different type of grip built in, right? Obviously, it serves as a [? visual ?] handle to indicating the geometrical information of the entity. And obviously, it implies you might be able to do something.
And then, besides those plain AutoCAD [INAUDIBLE] those are very basic entity grip. Other AutoCAD were vertical products like a Civil 3D, MEP, or Architecture, all those kind of things comes to their own custom entity grip.
For example, for this one, there's like-- it's a Civil 3D pipe network. It shows different structure and pipes. Let me show it in AutoCAD itself, say. For example, in this drawing, this is a plain AutoCAD entity. As we know, if we select it, for line we have three grips. For add grip, as you can see, you put your cursor on it, it may automatically show contacts menu to give you some option. Or you can right click to get some other options.
And if you do something like for [? and ?] grip, you can drag it to stretch. From middle grip, you click it, it's a default to move. For circle, you have a [INAUDIBLE]. And here, we have Civil 3D labels. It comes with its own custom grips.
For example, for this one, you select it. There's a tool to grip [? that ?] may serve a different purpose. For this one, you can see you can drag the label to somewhere. For this, you can move the entire label along the line. No matter where your mouse goes, it's just moving along the line.
So as AutoCAD programmer, and before when I only do [INAUDIBLE] and VBA, sometimes when I look at those things, I was dreaming that if I could do something like this, we can [? have use ?] a lot in many cases.
So that comes to once .net API available, then once I learned how to use the grip overrule to do this, you can imagine how happy I was.
So let's go back to here. So that's what the entity grip is. And now, let's see. What can we do with .net API tool to create a custom entity grips?
So of course, one reason, as we just saw, from a different AutoCAD vertical products, usually they come quite some custom grips for their own custom entities. Now, then comes the question, why do we want to do that?
So because, first, as we know, as AutoCAD use the grip is there. It basically is a provider, a visual shortcut for user to do something with the entity selected.
So in that case, in many cases, you don't have to select something, type command, or even click menu, then go back to [? something. ?] It's very straightforward.
So once we know the need to create a custom entity grip, we will need to realize two things. One thing is how the custom grip appears visually when entity is selected. And what we want the grip entity look like.
Again, for example, for this one you'll see they have a hint for this. Square one is for moving. For this, diamond one is for drag the custom grip along that [? line. ?] So it's made to provide a visual hint for user to indicate what kind of thing it can do.
And also, the other consideration is, when we create a custom grip, do we want that the original AutoCAD basic grip still there? Or we want say to hide them, say, we want for particular entity, we can only show our own custom grip to provide shortcut to specific business required action. For example, we don't want the user to drag the end of a line to stretch it, for example, in particular case.
In that case, we can use the entity grip overrule to hide the basic one and only show our custom [? device ?] one. Then that second important thing is what action we are going to associate with this custom grip because the whole point for the grip is not-- besides the visual to provide some visually to show the geometry information, the more important because there is a grip or handle user can hold it, [? do ?] something. You must associate a specific action to that grip.
So this is the two tasks when we build our custom entity we have to keep our mind to do it properly. Now, let's see how actually we are going to create a custom grip.
So as I said, firstly, let's see a simple do nothing grip. Although, in previous slide I said, we need to associate this properly to associate a particular action to the grip in order for the custom grip make sense. But in this example, I just show something [INAUDIBLE] do nothing grip because we just want to show the process, first, how to visually create this grip.
Let's say, firstly, quickly show a video to show the-- for example, in this video, I want to create a grip for a closed polygon. So add a customer grip in the middle of the extent of the closed polygon.
If the polygon is not closed, I am not going to add that custom grip. And I also want to provide an option, do we want to show only custom grip, or we want to show all? That means all the grips comes with AutoCAD built in. And the custom grip by this code. So let me just run that.
So firstly, I enable this grip overrule. I give the option, say, to choose you want to show the custom polygon only on or not. So if I said no, that means we show all grips, custom ones or basic ones.
Once it is enabled, as you can see, when we choose the closed polygon [? polyline ?] we have that show. If we choose the not closed, then we don't have that one. Let me just re-enable this one. And this time I choose no.
Now, if I pick that, as you can see, we have all the grips shows. OK, so let's stop this. As I said, in this class we focus on to show what we can do rather than code itself. But I still like to show the code for this quickly to see what we need to do.
Let me go to the code window here. So let's see, basically, when you need to create a custom grips, the basic thing you need to do is to create your grip overrule. For example, this one I used this to derive from this grip overrule. And in this case, I'm not focusing on how to do overrules, but only is it to introduce two key things.
First, when you write create the overrule you want to say, apply to which type of entity? In this case, I want to apply polyline. Then, if you don't set any other filter, obviously, the overrule will apply to all the polyline. But in my case, as I just showed, I only want to apply to particular polyline which is closed.
So in this case, we can set a few filters. For example, we can set filter by ID. Say we can pass one or more ID as a array, or we can use the [? x ?] data or extension dictionary. In that case, we have to attach [? x ?] data or extension dictionary to a particular polyline, so only those polyline is targeted.
Or we can have whatever custom filter we want to use our code. In this case, you tell the overrule, hey, I want to use custom filter. If you use custom filter, then you have to override this method and put your code here.
So as previously I said, in this particular, I want apply to closed polyline. So I just override this. I put up a code here to see the testing entity if it's a ployline. If it's polyline and I only return [? to ?] if it's closed. If it's not sure, if it returns for false, then this overrule we are not applied to this entity. So in this case, it's simply doing that.
Then in the overrule, that's how we apply the grip. But how do we create, actually, grip [? for-- ?] so that is this one class, we have to create a class derived from this base class grip data.
In this grip data, all those basic things where you create, there's two method we need to override to create our own custom grip. One is we'll put draw in this method, we actually draw our grip here. We indicating what size, how big it is. You can draw it as a square or rectangle or triangle or small circle, whatever you want to draw.
But of course, you don't want to draw it too big or too small. Usually, you may want to test it. But based on the information provided by the method, in this case, as we saw, I just draw a small square there, draw a circle, actually. I just draw a circle. I want to draw a particular color.
Then usually, then there's a action we want to associate to the grip. So here's where you do to override this method on hot grip. So usually, it's once your mouse cursor on top of the grip, it becomes hot. So if you do nothing, you just do whatever the AutoCAD design is, you just return the [? base. ?]
So in that case, it will show the regular right click context menu, [? say, ?] provide some information like a stretch or those kind of standard thing. But for this case, if you want to avoid that to only [? associated ?] your own custom action, you can come and [? add ?] this, and you do your own. But in this particular case, we want do nothing, so I just written OK. That means everything is done.
So let me just-- because first of all, let me just firstly put a breakpoint here. Let me run it quickly to show what happens here. Let me first close based on-- to let me put breakpoint here to show when the actual custom grip is created.
And one put a breakpoint here to see when the target polyline is located. Then, when the actual custom grip would be created here. So let's quickly run that. We can have a--
OK, so firstly, let me enable run the overrule, enabled overrule polygon, polygon grip overrule. So I want to-- so let's just-- enabled
So once it's enabled, whenever you click that, as you can see, firstly, it's found, OK, this polyline is closed. So I identify one. I identify [? it is. ?] It should be the custom grip overrule should apply to this.
So if I continue, as you can see, then it immediately, the AutoCAD will see, OK, I need to show the grip. So in that case, I write a code to say, OK, if the polyline is closed, then I go ahead to create this custom grip, which is this one, right?
So if I go ahead, first, we find where we want to say I want the grip in the center of the [? extends, ?] I do a calculation. I find a center point, and I go ahead. I create a new one. I put a grid point in that center. Then I add into the grips group. So then [? that's ?] done.
Again, here, is if we want to show also all other AutoCAD built in grip, we need this to be there. But since I decided to not hide them, so I will also [? call ?] the base get grip point method, which is AutoCAD built in function. It automatically quit all those basic grips.
So once it's there, as you can see, and once that grip created and one AutoCAD ready to draw it, and it goes into this class and call this method to actually draw our custom grip.
So as you can see, it goes here and keep going. Then I want to draw as a circle in that point. So then, it draws that. Everything's there.
So let me go back to that. As you can see, in this example, as we can see-- maybe I need still come back to the code here just to emphasize one thing.
So here, as you can see, we just need to do two things. First, we need to derive a class from this to actually draw, define our grip, what kind of grip we are, and what kind of application we want to do. More on this because the first one is do nothing, so there's nothing here.
And then, we'll need to have a overrule. If you ever run into another overrule, like a job overrule, or something else, you will know that, in general, how to create overrule, and how to apply to that. Or to say, the only difference for the grip overrule is you need to override this method. Get-- that's one AutoCAD to determine which grip AutoCAD need to draw to the selected entity. So that's where we actually create our custom grip and get it done.
And there's other virtual method to be override, but we'll see in the next example. So let's go back to here. Now, let's move on to the next example.
Now, let's actually see how to associate a particular action to a grip. Take this as an example. So let's imagine, say, we want to drag a line, stretch a line, but incrementally increase the length or reduce the length incrementally.
So let's see here. Let's just quickly see this video.
Ah, no. Yes, here. [INAUDIBLE] above for this one, you see I just have two grip on each end of the line. While we click and drag it, I show each increment why you can drag it. Say--
As you can see from the property window, the length-- the change will be incrementally by 100. So the user never need to worry about the length when they drag a line it's accurate or not, right? So [? that's ?] the an overrule does.
Of course, in this case, I can choose to say to hide all those original grips, built in grips, if I only want this line to be [? dealt ?] by yourself for this stretch only.
OK, let's close this down to-- so in this case, as we can see, again, let's just show the code quickly and the key things here. So let's stop this. Let's stop this to show for this increment-- so again, as we previously showed here, first, we derive this to create our own grip. First thing is here to draw how it will look like.
So we draw it, in this case, I draw it in a diamond shape. So the next thing is how to associate a action, in my case, it's a drag action if you ever done that API programming to create a jig action, you will know that.
So in that case, in this particular case, I actually went in overwrite this method with a jig. So I create a separate piece of code outside the grip so it just [? being ?] caught inside it to do the actual work. So the grip itself doesn't need to know what actually to be-- is entirely up to me to this define something, OK, I want to just use the jig to do something with this entity which is selected, which is where the custom grip related to.
So as you can see, in this case, I just associate this piece of code in this and make sure I don't return, OK, I return this. So it allows you to show something, allows the custom grip move along with your mouse.
So then come to here again. So as you can see, obviously, once we have this custom grip, we will need to use it in overrule to decide which entity I want applied, I want to use this custom grip.
So again, here, I say I want to use only line. And I want to use custom filter. So in this case, then I say-- where's my custom filter here? I only [? say, ?] I only want to use not every line, only the line which has an extension dictionary with a particular name. If not, I am not going to apply that.
So in this case, let's have a quick run on this. OK.
For example, if I have just another line, then if I-- incremen-- just second. Incremental drag overrule. Apply it. So I [? cannot ?] say I want it to be 200. So in that case and this one, as you can see, the reason I apply it, but for this one, I don't have that one.
Why? Because if we see this line, if we see this [? line ?] because we have a extension dictionary attached. So in that case, I can say apply-- I can say, I can apply the increment drag grip overrule to that. I have [? to ?] say, I want to select this line, which the code does is to attach a extension dictionary to that. Once I apply that, as you can see, now I have that, now we can do that.
So obviously, in a particular drawing, you don't want every line to-- you apply the other one apply this particular action to every lines, only particularly. So you can do that. And if you want to remove that, we can say clear increment rules. Say, now I pick ISO. I don't want to apply it anymore.
Now, if you select it not apply that anymore, but this one still. So that's the-- oh, I should have closed this. Let's go back to here to stop this.
OK, then let's quickly see the next example. OK, so this one, the reason I made this overrule is because this one I want to apply it overrule to block reference which has one or more attribute. But here is something we have to pay attention is that an attribute is a subentity owned by a block reference.
You cannot directly apply a rule to a subentity. So what do we do here? So let's quickly first see the example of it, see a quick video to show how it works.
So firstly, I enable this overrule. As you can see, it's enabled. Then, if I click that, as you can see, there's a grip appears attached to the attribute. But actually, that grip belongs to the block reference, not the attribute. But I just draw it so it draw it that way, so it appears the grip is from the attribute.
So let's see what I can do. For example, in this case, when you click that, you can drag the attribute to anywhere.
So if I disable this, right? So if you see like one up here again. Let's just stop this. So again, let's just quickly see the code for a couple key points here.
So for the attribute move, again, it's just, firstly, you derive your custom grip from a grip data class. Then here's how you want to draw it. Again, you can choose whatever shape, look, color you want to draw it.
And here's what action associated. So here, as you can see, This grip has a custom property. I can inject it into this. So again, in this particular custom class, it doesn't care what action it will do. It just say, give me an action, I'll do it for you when this method is called by AutoCAD.
So in my case, I just say in somewhere, I just set this property at a certain point to supply a particular action to this custom grip. So when AutoCAD [? cause ?] this, say, OK, I just do whatever the action does. The action just goes on whatever it does.
So in that case then, let's see what the actual action is. So again, once we have this custom grip available, we need to actually create with overrule. So firstly, the overrule, the first is, as [INAUDIBLE] I saw it, although it looks like the action is against an attribute inside a block reference. But the overrule can only apply to the block reference itself.
In that case then, I will need to do a filter to decide which block we need to. So in that case, I have a custom filter here. It says, OK, if the entity is a block reference and the block has at least one attribute, then this block is the target.
And this is where the actually custom grip to be created. So in that case, we see, OK, if the entity is a block and the block has at least one or more attributes, we go through there. But here, we only do this attribute if we want to.
So in that case, somehow if the attribute has a extension dictionary attached. If it is, then we go ahead to create our custom grip. So here, it [? has ?] if we have the extension dictionary or not, if we have that particular dictionary, we go ahead to create our custom grip. And we put it in the attribute position. So it look like the grip is somehow related to this attribute not other attribute.
Then here's the action we want to do whenever user click the custom grip. Here's the action, the [? actual ?] action. We want do the move. So let's quickly show the code [? what-- ?] as you can see, the move is rather simple. We just want to select the point, get a point with the base point as with the attribute-- where is the base point? OK.
With the actual position as base point, we just want to [INAUDIBLE] another point indicating where I want to drag the attribute locations. Once we acquired a point, then we just transform the attribute to the location. So the action is completely outside of that data. Where's the-- completely outside this custom grip.
So again, as I said, it doesn't know what action is. It just say, as long as you give me action, I'll do it. So as you can see, for the same custom grips, we can say we can do the move, or we can set action to rotate. So whether you do it to rotate, or we can do the scale or whatever action you want to.
So that's how for this, so I'm not going to run this whole thing. It's just two key point to remember how to associate the action and how to decide whether we want to draw-- on which property we want draw the custom grip and where to draw it. That's it.
So let's move on to the next video. I have [? one. ?] OK, so that's the simple custom grip, fairly simple. Usually, you [? do. ?] But what if we want to do more than one action to particular grip, to particular entity when it's selected?
Obviously, you can add more grip, just like what I showed you in the Civil 3D label for the segment label. You have two grip, one to move the label, one is drag the whole thing along the line.
So obviously, you can do as many custom grip as you want, but you don't want to draw too many so that your entity will be occupied by too many grips. So in that case, that's where the custom grip with the context menu comes in.
So in that case, so here, there's a different way to show that. One way is to override the grip data class. There's the [? on ?] right click then you can somehow build your own context menu. But in this, you have to implement your own custom menu and implement this interface.
OK, I could-- yeah, you'll have to implement this interface then, but it's quite complicated. So the other method is to derive a custom class from a multimode grip PE. Multimode, that means one grip you can do, there's multiple mode you can use.
So in this case, each mode will-- [? while ?] you derived [? it ?] from this class, each mode will show as a custom menu just like-- let me-- so this then, you'll have to use particular method like this to add to. Let's go jump into the code to quickly show what--
First, let's show a example. Just second. OK. Let me first quickly show an example here. For example, for this one it's already-- for this one, for example this is a particular object that I created. As you can see, let me just stop there.
As you can see, when I put the mouse on one of the custom grip, it will show a context menu for many options you can do. And so that's called a multiple mode grip.
Let me-- OK, so in that case, I'll [INAUDIBLE] stop here. Let me show another quick example here, smaller example.
Again, this one is also applied to a block reference with the particular-- with the attribute. As you can see here, this custom grip shows three options you can do.
OK, again, let's show-- the [? critical ?] the point, the [? some ?] key point of this class here. So because for this multiaction--
Again, the first thing is, again, we create our own grip. So our own grip, then here's where we draw it. Again, you can draw it in whatever shape or color you want to.
And we can associate a particular action to this, but in this case, here's I just do whatever AutoCAD designed to do. But here, you see, I add a method to create multiple grip mode. So each mode will corresponding to one item in the context menu.
So we have this method, which will be caught in the grip overrule to actually create those mode. So as you can see, for each mode, we give it a ID and do something, and say that want the text to look like, we can show a tooltip. And more importantly, it's action. What action we want to do?
So we say we have a different action, say this action we can just do immediately what action it is. And the second one, we do. And also we can have an action to call a command. So in that case, I would define a command called toggle attribute visible. We'll show it in a moment.
Then we can define a action to be caught by the grip overrule. In this case, it's this action. So that means, whenever the context menu item, this or this, is selected, the grip overrule-- we'll show in the moment-- we'll call this action, we'll call it.
When this called action, we'll place on the ID here, we will say, OK, for the context menu, if the mode ID is one, we will set the height to increase the height. Or if the ID is one, we'll reduce the height because the method here will reduce the height.
So for example, let me see the-- so let's see the overrule itself, how to create that. So again, the first thing is how to apply it to this. And again, we also have the filter to decide, OK. So we only apply to blocks reference which has a attribute and we only apply if one of the attribute has the [? x ?] data attached.
So then come to the key thing, how to actually make the multiple mode grip available. So here, we will need to create a disk. We'll need derive this multiple grip from this class to this, which we have to override a bunch of methods to enable to do that.
So I'm now going to go to the data-- it's just [? quiet ?] otherwise, knowledge about-- you can look the code later from the class handout.
Then, the key thing says, once you have this derived class where you enable the overrule, you will [INAUDIBLE] the first, then call this method add [? x. ?] It means add extension. That means add a extension to the regular grip so it becomes a multiple mode grip. So it's called add [? x. ?]
So we created the instance of this derived custom class. We call this method, we add it into-- attach to the grip overrule. So then we can get this out of [INAUDIBLE].
So here's [? when ?] the actually multiple mode grid is created. So here, as you can see, first, we see if it's a block, if it has an attribute, and if the attribute has particular [? x ?] data attached, then this is the task we need to work with.
So here, we find the attribute center as the grip point. We actually create this customer grip. Then, again, as I said, we assign a action to that grip to change the attribute height.
Again, when we come back to here to see this, as you can see here, we have three options from the grip mode. Or we can say it's a three item in the context menu. But we only have a two the action we assign here. Yes, we assign the action here. We only assign it, but this one we don't need-- we use command, as I mentioned, we will see it in a bit.
So in that case, while we come back to [? why ?] we see that, we create-- then was the grip created [? added ?] to the grip, it's done. It's grip.
Then when this multiple action is called, that's where we have to override this. That means, whenever we put our mouse on our custom grip, AutoCAD will call this. Whenever we click any of the context menu item which is indicating a mode of multiple mode grip, AutoCAD will call this.
So in that case, we will override it to let our custom grip know what to do. So we go through all the grips that block reference has to see if it's our custom grip. If it is, we call this method defined here. We will [? call this. ?]
Then, in [? this, ?] depending on which mode ID is, it will do different things. But as you can-- if it's not our custom grip, we'll let AutoCAD do the thing. It's built in. So that's how this works.
OK, let's move on to next-- so now, it's come to-- very often, when we use AutoCAD we will need to deal with external data outside of drawing. So then, there's a chance, when use a deal with the a select entity through the grip, through our custom grips, the action may need to deal with some data.
So then, sometimes we can, when we build our custom data, we will need to somehow link to take the data into consideration. Safe-- let's say, take say, well, let me just go next step. Let's imagine such a scenario, like a drawing has a multiple block reference of a particular block which has a few attributes which are updated with a set of data from an outside data source, and whether it's database or data file or whatever. It's just outside of the drawing.
So for some reasons, the update require user to do it manually. So in that case, the typical thing will be-- so you may run a command. You may even open up a UI to present the available data for user to select. User select then click OK. Then everything then gets updated.
But obviously, sometimes if user just click your custom grip and get the data available, then do it, it will be more straightforward and very user friendly.
For example, we have a few blocks. We have a sets of record. For each record we have a product name, location, client name, things like that. Then now, in a particular drawing, we have a feel of this block and one or more of this block, I want to say user to update-- to choose one of the record to update the block. There are three attributes for this one.
Something like this. Say, if I use a right click, put the mouse on the custom grip, the less the custom menu show the less of the data instead of a particular action. It's just show the data available. You just pick one. So it's a safe-- it's a lot easier for user, say, to type command, to update, or show up a pop-up, a UI of dialog box with your text.
And the user click one from the list box or dropdown combo box and click OK, right? For this one, it's just put mouse there, click, it's done. Let's just see it to see how it runs.
Oh, sorry. That's the wrong-- sorry, that's the wrong-- I went too fast. Here.
OK, as you can see, first, I enable the overrule. And when I click that, you see everything there. I click, it's updated.
So it's just a one click to update. It's much better than you have to type a command or click [? toolbar, ?] show the data, click, select data, click OK to get it updated.
OK, so let's quickly stop this, quickly show the key point of the code. So how the data get to there?
So for this one, as you can see, firstly, again, we go back to the same way. There's nothing to this, nothing special to this. The only thing is here, to create the mode, in compared to the previous one, we adjusted the three. In this case, as long as we have a set-- as long as-- here, actually, I have a property we can assign this a class assess of data. The data, let's say, it's a list of data.
So we just go through for each data, we create a grip mode. That means, for each record we create a item for the context menu. So that's how it happens. So that's how we created that list.
Then, again, in the overrule part, again, we need to derive this and add the extension to the overrule. Let me just-- part. And this object has first been supplied the data sets.
Then we actually create a custom grip. We just make sure the data is passed to the grip. Then the grip knows the data when it's create a multiple mode, it will loop through for each record, create a mode. That's how it's created.
So that's a way to use-- obviously, we don't want to-- if the data set have too many records, say like 20 or 30, it may not be suitable to create a huge context menu with the 20, 30 item. So just use your common sense for this type of data, or this way of using data. There's just an example of the way of use data anyway.
So now, that's one way to use data. Now, let's move to one extra example. So here, that's an extra example. We can even store data inside of a block. So say, for particular situation, for example, I run into [INAUDIBLE] in my [? pass. ?]
Say, we have, in our case, it's in a drawing border, we have a block with the engineer or land surveyor name who is supposed to ask the project manager name [? there ?] the user want to choose from. And in that case, that's a name that sometimes changes from time to time because people come and go, right?
But it's not constantly updated, and even in a smaller office, they don't even have a database to store that. So we store the data within the block definition, and we use that data as a context menu to update. So let's see this example.
So first, I insert a block. I called it-- then, I enable the attribute is called attribute added overrule. I clicked, nothing still happened because I haven't applied overrule to a particular block, to this block because I need to add-- because I don't want to apply this to every block.
So in this block, say, I want to apply to that block, and I want to add a data list to particular attribute. Say, I want to add a set of username, for example. I first add a username, got John Smith. And I want add another name to the list to be used. Then the name will be stored as a extension dictionary to the blocks attribute definition.
OK, then I add the three names there. And of course, in this case, because I updated the definition, I saw I want to, in this case, I want to reinsert it. When I insert it, the block reference will have the extension dictionary comes with it. So the overrule will recognize, OK, I need to draw the custom grip here.
So in this case, when I clicked it, automatically it will pop up a small UI to have this three data available for user to choose from. But in this case, we also allow a user to enter. I use a combo box either to choose one or enter one.
So obviously, as you can see, this one, obviously, I can use multimode grip with the context menu instead, right? But I just show it to say there's a different way we can associate a particular action to a custom grip.
OK, so that's the example here. OK, here, as I said from the beginning, basically, in this class, well, during the demo session period, I just showed all the-- [? most ?] folks on the example and a few key points to the code to cover key things. And the further you need override the grip data class, then you need to build your own grip or grip overrules.
By that-- [? then ?] focus answer to show a concrete example to show what we can do. And the use of imagination, we can do a lot more than what I showed here.
So in this case then, as long as we has this key point in mind, to know where to do, then there's a lot of code to study. You can look at from my class handout, and also which has my entire [? regional ?] civil code project available to look into.
Obviously, there's still a lot more things I left not to discuss, haven't been discussed. For example, you have [INAUDIBLE] for [? entity ?] selected, and all has a different custom grips. That is [INAUDIBLE] something happened. Then there's more to explore.
But all in all, and I just want to-- whoever who are interested in this topic, to see how rich this API feature is, which allow us to do a lot more interesting thing. But don't overdo it. Don't abuse it.
And also, it's kind of-- not only it's quite advanced .API programming topics, but it's also quite time consuming. So to make sure you consider all the situation and being convinced that the use custom grips will give you the best user experience and best CAD work efficiency. That's where you can justify your time spent on this in quite advanced, complicated topic.
Then, there's probably many, or some of you, knows there's not many official documentation about this topic. From the available .net programming documentation, there's simply no sample code at all. Except just some very simple description of the method, even though detail [? explain, ?] sometimes it doesn't help at all.
So if you do a search on the net, you can find a few. There's the few I used and I looked and learned from, I list here. And of course, as I showed in beginning, I have my own .net programming topic blog there. But I have to admit, I haven't had any article published on this topic in my blog. So this class is the first one I focused my study on it and to make it public available through this AU class.
OK, that's probably all I have to talk in this, again, because it's the advanced topic. And I hope you guys to find the time to download the class handout and videos to do project, to look into the code in order to fully understand how it works.
And I hope this class demo should mainly show what we can do with the custom grip, which will inspire you to explore it for your work, and enjoy your exploration on it. OK, that's it.
Downloads
Tags
Product | |
Industries | |
Topics |