Descripción
Aprendizajes clave
- Gain hands-on knowledge and use of advanced AutoLISP functions
- Get hands-on knowledge of creating Reactors in AutoLISP
- Gain hands-on knowledge of VBA-style programming with VLA functions in AutoLISP
- Get hands-on use of the Visual LISP Editor
Orador
DARREN YOUNG: All right, do we want to start on time? Do you want to quit and be done now?
AUDIENCE: No.
DARREN YOUNG: OK. Darn. All right. So You know, a couple of people have said they'd been in my stuff before. This is like years ago. I've actually done this as a lecture two, three times over the last five, six years. You know, it's a lot of information to go through and go through it quick, and I just thought I'd try it as a lab this year and see, you know, see how it goes.
It may weird some people out. If you like labs and you like a nice scripted do this, follow this, follow this, you probably noticed if you downloaded my handout there is no step one, step two, step three. I kind of run whatever. What does a class want to do? Where are we going to go? I don't want believe in training steps. I want to teach you how to think through problems.
And you know, the idea came from an old employer where I had to set up some shop equipment, some software I wasn't that familiar with, and I just had to figure it out. My only supportive contact was the developer who said, contact the consultant who knows it better than him. Consultant took the one vacation he's taken in like 10 years. And I got a machine installer there. So I ran into a lot of roadblocks. And then I actually trained the people at the company the same thing. Let's walk you through the roadblocks. I want you to see what I ran into and learn how I think about it.
So that's kind of how I run my labs. My apologies if you want a real step one, step two, step three. But like I said. The other reason I do it is you are free to email me anytime. Not so fast respond on the personal because when I get home, I don't want to touch a computer. Work email though, sometimes it's probably more appropriate in my other class where I had people that were in my same industry. But some companies, that's the competition, don't email them. you know. So you've got my work and personal.
But I've still got people that, hey, you know, a couple of years ago I was one of your classes, and I'm looking through this stuff now. I've got a question, feel free to reach out to me and I'll do what I can. I won't write your code for you, but I'll look at your code, or maybe give you some pointers, and hey, have you thought about approaching it this way, or stuff like that. So, as I said, for that reason I kind of run a little bit loose.
I hate the pictures. They threw that on the slide this year about me. Enough about me. It's about you guys. Like I said, there's a lot of stuff to cover or that we could cover, and it's in an hour and a half.
I blasted through the lecture in an hour, and honestly I could probably do an hour on any one of four areas that we can go over today. So I'm going to leave it up to you guys kind of. I'll disappoint some and make others happy, but whatever kind of majority people want to do, that's what we're going to go through.
So how many people here have never programmed AutoLISP before? One. OK, that's not too bad. Usually you know, my last class it was scripting on a particular product, and it's like half the people have never used the product. I'm not sure why they were there. But if you've never done LISPs before, this may not be a whole lot helpful to you. It may be downright confusing.
So how many people consider themselves a moderate level, even more advanced programmer in AutoLISP? OK, a few people. The rest of you guys kind of beginners who dabble in it here and there. All right.
So I had something I tried to do years ago and I was getting into LISP. I got it to work, but the code was like bad. And then some guy I knew-- anyone ever I'm familiar with the Super Purge utility? It's Owen Wingerd, the guy who wrote that, genius with coding. And he sends me back this little snippet in like five lines. This does that. And he's using all these advanced functions. What do those things do? So I'm going to figure this out.
So that's kind of the basis for this class. Way back then it was kind of hard to figure out some things if somebody doesn't show you.
So that being said, we've got some lab assistants in the back. We've got Ray Steve Garcia from ACCO. He's the guy just to the right to the guy in the left. We've got Wade Wiesels. ACCO is up in San Francisco Bay Area, mechanical contractor. He's in my industry, competitor, you know. We work in similar markets, But we're friendly. We don't beat each other up too much.
Wade Wiesels. He's out of Des Moines. He's the middle guy, modern piping. Again, a mechanical contractor not in our area, but I brought in people that I know, because I know they're going to work hard to help you out.
And then on the very right-- your left-- I just said that backwards. Sorry. We've got David Ronson, used to be on the contractor side, now he's on the vendor side, with applied software and mechanical.
The other two folks standing up in the back, help out if you want, or if you need a seat.
So we've got a few things we could cover, which like four areas I covered when I did the lecture. And I want to kind of do a survey, so please provide feedback.
We could cover some of the advanced functions, lambda, MAPCAR, Apply. And you know, maybe throw in something like a concept like recursion, where you have a function that calls itself. We could cover that.
We could kind of go over the Visual LISP Editor. How many people use the Visual LISP Editor versus something else? Not very many people use the Visual LISP Editor? We could kind of go over some of that. I'd recommend maybe not going too deep on that, because we'll be in it and using some of it, and I'll point out things just as we go.
Anyone do Visual Basic programming? A few people? You can do all that same stuff from LISP, you know. Active X programming, they call it. We can cover that. That is a whole topic all in itself.
And we can cover what's called reactors. That's code that will automatically execute when certain things happen. My code is going to run just before he saves the file. Now you've got to initiate the Save, but before AutoCAD actually saves it, it will call your code, or after. Or hey, after an object is deleted to your data from your drawing or added to your drawing, execute this code. That's what reactors do. So we could cover that.
So let's narrow it down to three-- advanced topics, Active X like VBA stuff-- Visual Basic programming-- and reactors. Who wants to cover the advanced functions? A few people. How about the Visual Basic style programming? Even, maybe same. How about reactors? About the same. So every one is about the same.
Should we just kind of touch on each and try to do the best we can, maybe half an hour on each topic? Everyone good with that? You guys all hate me? Come on, feedback.
AUDIENCE: [INAUDIBLE]
DARREN YOUNG: You know, this guy wasn't responsive at all. He didn't teach what I want him to. Come on, you guys can do that. I don't know. I'm pretty laid back, you know. Tell me where you want to go, and I again, that's why I want to.
You know, you take a class on Revit families, or AutoCAD CUI, you know what you're going to get, you know. And Some of this stuff is kind of niche. There are people in here, I guarantee, that know way more than I do. Then there are people that, I don't know what he's talking about. And so it's really hard, and that's another reason I run it kind of loose. We'll just kind of play it as we go.
So we're going to fire up AutoCAD. But before we do that, does everyone know how to get to their data sets? Have you taken a lab yet?
On your desktop-- and these are running like a frame. The computer is somewhere else. It's, you know, a virtual computer. So it's a little bit tricky in places. Sometimes Alt-Tab will screw you up. But on your desktop there's a data sets folder. And just for you, I asked them to put our class on the very top so we can find it easy.
And let's open up the handout. I'm going to do it in the PDF version. If you love to type and want to practice that, open the PDF. If you want to just cut and paste some of the code so we can run it in and then not worry about typos, use the Word Document format. So again, that's why I provide that. A little bit easier.
And so we've got some functions here. I've got to start my timer. I've got a timer here going so I can keep on track.
So we're going to start ripping through some of this stuff. I've actually got some sample LIPS code too. We also want to go to the desktop. And we're going to launch AutoCAD, just plain old AutoCAD 2019.
If anyone has any technical problems, questions, you know, we can't hold up the whole session for one person, but I've sat in labs too where, you know what, I want to dig in here more while he's moving on. I get that. You know, try to keep up. And if you've got questions, our lab assistants will help you out. But if you just want to dig into something deep and forget the rest, that's OK. We're OK with that too, but we can't catch you up on the whole class if you want to jump back in later.
But from AutoCAD we could just start a new drawing, default template. Not a big deal.
And we can type V-L-I-D-E. Visual LISP Interactive Development Environment is what that stands for.
And this is our Visual LISP Editor. I tend to maximize it. Then I go into Window Tile Horizontally and rearrange them. Does everyone look like they're kind of keeping up? Are we here? V-L-I-D-E. I'd tell you how to do that phonetically, but I don't know the official word, so I'd probably be likely to swear on a couple of them. But V-L-I-D-E. Visual LISP Interactive Development Environment is what that stands for. And that brings up our Visual LISP Editor.
AUDIENCE: [INAUDIBLE]
DARREN YOUNG: V list, or LISP? I don't know. It might be the same thing. I'm not sure. I always type V-L-I-D-E. Maybe I just learned something too.
So we're going to go File Open, and we're going to look for our data sets. Doo, doo, doo. There we go on the C drive data sets. We're at the top. I've got code.
And you'll see there's a D of a G in there too, and a LISP routine. We're going to load the LISP routine.
Why do I need the-- I don't know why I needed the AutoCAD. Oh, I think I know why. We'll get to that.
So in AutoCAD II let's do this. Let's open up my sample drawing. Again, we go over the C drive data sets. The top one is advanced LISP code. And we're doing this one, Advanced Functions. We're going to open that up.
We're not going to get it that real complicated drawing. I'll explain that later. But we won't get into that just yet. The most of our work is going to be in the Visual LISP Editor. Which if Alt Tab doesn't look like it works, if you come down here in your task bar, you can jump between it that way. And if I want to maximize my window again, Window Horizontally.
So has everyone got this? Again, if at some point you guys don't actually want to try this, and you just want me to blow through and explain it, but again, it helps to kind of kick the tires a little bit. I tried to keep you from having to type code. We're just going to highlight code and run it to kind of see what we're doing. I don't want to suspend most of the lab you know, fixing syntax errors. That's not helpful to you guys.
So the first one we're going to do is called Apply Well, in LISP, I can add two numbers together like that. So what I'm doing, if I double click on that end parentheses, highlight it, this little button here Load Selection loads the whole active window. Don't do that one. Just what I've got selected. Does everyone see that? And we're going to be doing this again and again, Highlighting Code, Load Selection.
I didn't wrap any of these in functions, so we don't have to type anything of the command line. Again, we're learning about LISP. We're going to try to minimize bouncing back and forth between AutoCAD and the Visual LISP Editor. But I can add two numbers together, and down here it returns my answer. So if you're not using the Visual LISP Editor, this is some kind of handy stuff right here.
You can do all kinds of stuff. And maybe we'll get into some of it. It can format and indent and you know, reload stuff. You can put breakpoints and step through your code and watch the variable's value change in a window as you step through it. There's a lot. I guess we may get through some of that. Maybe not. I did a lab on that one year probably less than five years ago that you guys can search online.
But that's how we add a couple of things together. Right? There is a function called Apply. And what that does it applies a function to a list of data. And so when I run this, again, I'm going to highlight it and run it, I got the same answer. Right?
Who thinks this one is easier to code? Who thinks this one is easier to code? No verbal responses, so it can't be that strong of an opinion. There is no, that one. All right.
So I would never use Apply in a case like this. But what if I don't know how long my list of numbers is? You know, I know a one and a three. Maybe they're coming from variables, you know. Or you know, here's another section. I'm going to build a list. And I'm going to highlight this one. And I'm going to take each item, you know, pull an item out of the list, and pull an item on the list, and them together. So I've got a list of numbers. It's not numbers. I'm not hard coding numbers anymore. I've got a list.
Now granted, I hardcoded that in there, but maybe I'm extracting values from objects in the drawing and other you know, mathematical algorithms, and so I don't really know what the number is. I'm just building a list of numbers. So I can't just type the math out, you know. But now I have a list of numbers. And so I can pull the first item out.
So again, I'm going to right click, and I can say Inspect. Here's a little Visual LISP thing. That tells me the value of that variable. I can highlight just that section of code again by clicking on the parentheses. Right click and inspect, and it actually executes that code. And I can see the value I'm pulling out.
Again, so I'm showing you a little bit of the Visual LISP Editor to go through these advanced functions. Highlight that one. Inspect. This one is 3. 1 and 1, you know. 1 and 3 is 4. But you'll see now I don't have just the numbers in there. I can do it that way, you know.
Here's a third example. What if I've got a really long list? Again, I could do something like this with a long list, or I could do that. But in this third example, I've got a list. I'm just going to run this first part. There's my data. What does this do? I'm quoting a function, and I'm constructing a list that has that in there, and now I'm evaluating that.
So I'm not using Apply in this example, but I've got a whole list of numbers. And I want to add them all together, like pretend Apply doesn't work. I just take the function, throw it in at the beginning list, and then evaluate it, and I get the same answer.
You know, same thing here. I'm showing you other examples that are a little bit more cumbersome now that we have a longer list. I could build the loop, and for each item I'm going to run through. And again, here I could make breakpoints and step through. We won't get bogged down on too much of that. Maybe we can go back later if people are interested. But that's if I've got a big long list of numbers. How would I add them together? And again, pretend the list is getting built some other way than you just typing it.
But again, when I've got a big list like this, how I add them together is still very simple. I take a quoted function and apply it to that list. That function applies to the list as a whole.
Does anyone have any questions on that? Yes?
AUDIENCE: Is there a particular reason you use one of these methods over another?
DARREN YOUNG: No. It just, I don't know. As you get to use it, I would try to force yourself to use them when you think it makes sense. And you'll get more comfortable. And you'll start to get it. This makes more sense here. Like I said, if I just know the numbers, traditional way works. These advanced functions, like I said, I'm pulling in information from multiple places. It's in different formats. A list is a common data structure in AutoLISP. And it's easy just to pass a function to it.
Addition maybe isn't the best example, but it's a clear example, because we can all wrap your head around it. I could use Apply with any function. It doesn't have to be addition. It could be, you know, making-- Any function that works on a list of data or needs a list of data could be used this way with Apply.
So the next one we're going to do MAPCAR. I'm going to bring those in there. And I've got a couple of different lists-- my list one and two. And I want to add them together. So MAPCAR and Apply, Apply I don't use nearly as much. MAPCAR is more common.
Apply applies that quoted function to everything in the list as a whole, the whole list at one time. MAPCAR applies the quoted function to each item in the list one at a time.
So when I run this, I've got two lists of data with three numbers in there, coordinates xyz. I've got two different xyz values. I want to add them together. How do I do that other ways? I'm going to pull all this stuff out, do the math, put them back in a list. MAPCAR does an addition between these two lists.
It could be one list. It could be two. It could be three lists. I can put any number of lists, but it's going to take the first item in each list and add it, second item in each list, add it, third item in each list, add it, and then return all three of those items in a single list. So you see how that Apply worked on the list as a whole? MAPCAR is actually going in and working on every item individually. So when I run this, I've just added those two coordinates together.
How do I get to the midpoint of something? Add the two coordinates, divide by 2. MAPCAR is an easy way to do that.
Who's learned something so far? Anybody? A couple of people? Good.
AUDIENCE: Do both lists have to have the same amount of elements?
DARREN YOUNG: Good question. Do both lists have to have the same amount of elements? No.
Actually, you know what? I jumped over one. Here's another one too. It's not numbers. I've got some text. I'm going to apply this straight case function to it to force them all the uppercase. So again, it doesn't have to be math.
So you're asking about the multiple stuff. This is how you would have to add those numbers together manually without MAPCAR. Remember, we did something similar with Apply. It wasn't that bad. This looks more complicated.
So again, we can come back to that option. And like I said, I kind of walked through the options. I showed you here's how you can do it without using MAPCAR. Here's another way to do it without MAPCAR. Here's the way to do it with MAPCAR. So you kind of get a contrast of how difficult they are. And then you can kind of see, you know, MAPCAR seems kind of magic, especially if you do more advanced things inside of it. You know, sometimes it's easier to see how would that be done manually? What is it really doing?
So the question was asked in the back do they have to be the same size? So here's a list with an x and a y. There's no z. Here's a list with an x, y, and a z. Try it out. You know, at one point I didn't know either, and I tried it out.
So you know, my last one was a scripting class in a different language and program, but I ran into problems all the time. And then the way mine-- you know, we fixed one of our problems. And somebody asked a good question. Well, you know, if you're going to lock it after you change it, shouldn't you unlock it before you change it? Well, it makes sense, but do I need to do that? Let's try it. Let's try it without. What happens?
You know, try those things and break it. That's how you really start understanding what these functions and commands do.
AUDIENCE: So the answer to that question is if you don't get three items on that list, you [INAUDIBLE]?
DARREN YOUNG: If I wanted an x, y, and z to come out of that statement. He was asking if, you know, I need to have three items in both of them if I want three items coming out. It's going to go until they match up.
If I had three lists-- one with an x, one with an xy, one with a z-- I'm going to get one item back. If I have two lists with two items and one with 3 and one with 10, I'm going to get two items back. So whatever the least number is, that's what I'm going to get back. And it just discards the rest. So there are cases where you'll do that.
And I might have an example later. I can't remember. It's been a few weeks since I did this. But I think it's on some of the other advanced functions. You know, sometimes if I know it's just two coordinates, I'll just tack on a 0, 0 at the end if I think that's what it needs to be. Or you know, sometimes I'll do that just to make sure the lists are the same. Throw in some irrelevant numbers. Maybe it's a 1. If I'm scaling something, I'll put it a 1. And you know, that third one doesn't scale because it's a 1 when it does the math.
Why did my window keep shortening up? There we go.
So that kind of works. So here's another case where remember I went up here? We had some text straight-cased, and then I gave it a list and made it all uppercase. So if you guys know what this function does, it takes an optional parameter and forces the case the other way. And this way it's just one way. It's using straight STR case with no parameter, and that forces it upper.
Well, what if I want it lower? Well, there is an optional parameter for that. What is the optional parameter t? So here's a case. Now they're all uppercase. Here's my function. Here's my list of text. I'd built a fake list with a bunch of Ts, so for every one it calls STR case with the text and a T. With the text and a T. It works its way through the list.
So here's a case similar. They're asking about I want three items out. Even though one of the lists had two, I would add a third item into that list that wouldn't affect the results.
Here's a case. I built my own list with just for T's in it to match up and run that function and forced the case the other way.
Yes?
AUDIENCE: [INAUDIBLE]?
DARREN YOUNG: You could. Yeah. The question is, could you use a for each? You could use any type of loop. You could construct. You know, here it's just hard typed in, but maybe I don't know that there's four. Maybe it could be 10. The program will determine it. You're drawing will determine it. You could build a loop that assembles enough Ts to match the number of items in your list.
But there are other ways to handle that too. I probably wouldn't do that anymore. If I just knew MAPCAR I would, but I also know lambda. And if you look at existing code, you'll see lambda is used much more common. lambda can be used with Applied, but it's more common to use with MAPCAR.
So this really has nothing to do with lambda, but I want to find out the number of seconds per week. And I can write code like that, right? Again, this is me probably poorly trying to explain how lambda works. I can write that, or I could just write another statement where I'm just doing all the multiplication based on those factors and getting the number I want.
So I didn't have to break it down. I just, on the fly, hard code jammed some numbers in there. And y'all know how to make functions in AutoLISP with defined function, defun. Lambda is the same thing as a function. It's just an unnamed function.
That sounds weird, right? Come on. Somebody agree with me even if you have to lie. That sounds kind of weird.
So remember how we built that list of Ts? Let's build this list again.
Now I'm only going to give it one list-- list of text. And I'm going to use MAPCAR. Oh, I just had a mind melt. Yeah, MAPCAR. I just had a brain melt.
So I'm using MAPCAR, and MAPCAR takes a quoted function. But it's not a simple function. I can't just do straight case. I need other stuff happening to it. So I'm going to define a function just like I would do with defun. Except I'm never going to use it again. I'm only going to use it here. I don't need to name it, so I don't need to call it anywhere else. I'm defining a function without a name right in the place where I want to use it.
And that function, does everyone know how to pass arguments to a LISP function? You know, you can make a little variable up there. And when you call it, you pass the argument. And then you reference that argument that comes in there.
Here's my function. This is the variable, this x here. It's easier to do this way. That little x is going to be each item in the list every time MAPCAR runs. MAPCAR is going to run that function, and it's going to take that function and pass apple in the place of x.
So now I'm going to do an STR case, apple with the t. Then it's going to run through and it's going to throw orange. Then it's going to throw banana, and then that other fruit that I don't know how to spell or pronounce. You know, that is some type of weird, exotic fruit, by the way. So you at least learned that if not know how to LISP.
But now I don't need all those four Ts. I don't need to build that for each loop to build this whole stack a Ts to pass this straight case. I'd built a function. And that's why you'll see MAPCAR used quite a bit with lambda. They kind of go hand-in-hand. Sometimes it's not as easy as just adding, subtracting. I want to do all kinds of stuff. I want if statements, and if this and if that, and do that. I just need the values. And then I'm doing a whole bunch of stuff, and then I want to spit it back as a list when I'm all done.
So that's what lambda does for you. It makes that function. Same thing is defined function-- defun-- but it doesn't have a name. You just define it in place. Can't reference it again. Again, that's the only place we need it.
Can everyone see this text? I wonder if there's a way to get the font a little bit bigger. Probably is. Well, I don't see where that showed up.
AUDIENCE: [INAUDIBLE].
DARREN YOUNG: Huh. Well, I won't spend a whole lot of time here.
AUDIENCE: [INAUDIBLE]
DARREN YOUNG: So I hit Font, and it didn't seem to do anything.
AUDIENCE: [INAUDIBLE].
DARREN YOUNG: But I don't know. Can you guys all see that? I mean, you should have the code pulled. You can pull the code up and walk through it there even if you don't want to run it.
[INTERPOSING VOICES]
Here's another example of MAPCAR in lambda. I've got a whole bunch of months, mixed case. The data is garbage, really bad. Right? You know, so what am I doing here? Oh, I think I know what I'm doing.
So I want a list. I want an uppercase J, lowercase A, N-- Jan, Feb, Mar, April. This now, you know, some of this other stuff we did, it's just as easy to do it the other way. Why do it? But I'm trying to show you kind of what it's doing.
This is a case where it's really helpful. I've got a list of months. I define this function with the lambda, and I want to pull the first letter out, force it uppercase, pull the second and third character out, make them lowercase, put them back together, and return the list. So this function here takes that whole list, and just gives me the first three characters of every month, with the initial character uppercase and the rest lowercase. So when I run that, that's my list.
So where we're just adding stuff, dividing, you know what? Why use this advanced function? It's not that difficult to do the other way. Right? This starts to be a little bit harder. Right? It's a little bit easier to do in this MAPCAR sense instead of building up a loop that counts and figures out where I'm at and things like that. That's the power of these advanced functions.
Like I said, I encourage you to kind of try to use them. The more you use them, the more comfortable you will be in using them.
So let's do this. Let's jump in. I'll show you a little bit of LISP Editor stuff. I'm going to toggle a break point. I put my cursor around here, on the beginning of that lambda, and I hit this little hand symbol here. Does everyone see that? It looks like nobody's typing. So this is, am I right in that? You guys would just prefer to kind of watch as I go?
AUDIENCE: [INAUDIBLE].
DARREN YOUNG: So, OK. You know, again, you don't need to run it, but you can. I've got the things pretty much where you could just double click, highlight, and run if you want to. But I didn't want to force you to type a bunch of stuff.
So I'm going to put a break point there. And I'm going to highlight the whole thing, and I'm going to run it. And it's kind of sitting there. Debug, F8, step into. Did that not work? You know what? Maybe it doesn't work if I put it there. I'm going to put it on the MAPCAR. Maybe this isn't the best example. Nope. All right. I'm going to stop it.
I'll find another example to show you this stepping into, I think. I'm going to try this one more time. And I'm going to throw it inside the function. There we go. So I made a break point. I put it at the beginning, so it really didn't know what to do. I put it at the beginning of the lambda function. It didn't know what to do. I worked it in there. So now it executed code, ran in there, and it stopped. So now, again, now we're talking more about the editor. I can double click this X, right click, and say, Add Watch. January.
And again, I've got these little arrows in here. Continue. We'll just rip through. Quit, reset. This keep stepping me into. If I click this one, it's going to step into the straight case. And then it's going to step into the substring. If I click Step Over, it's just going to finish the straight case. So I can control do I keep on stepping in, or do I just kind of jump over blocks? But I'm going to keep stepping into.
And again, I can add other things into that watch window. I can add a whole function in there. So now you can see what lambda is doing, right? It's throwing January into the x variable argument, pulling out the first letter, making it upper case, pulls up the second and third, and make some lowercase. And I'm going to keep stepping through this. And now we're running in it again. It's running a third time for the second item in the list. So this is kind of the power.
You know what? I don't want to do this anymore. I'm going to just step over stuff. And now you see it's not diving into the straight case. It just kind of steps over it. Or I could just step out a few times, or I could just say continue and now it'll stop stepping. Or it's supposed to. This LISP Editor has gotten more buggy over the years.
Who does not understand what I was just doing, what this MAPCAR is doing? Do you? I don't know. You've kind of got to play with it. That's why I like the LISP Editor. I could watch the variables, and I can watch some of these things and see what's happening.
MAPCAR does that whole lambda thing. January, February, just keeps dumping them in one after another. It does its thing in there. And then when it's all done, it just kind of, as it does it, it just stores it in the side. When it's done, puts it all back in the list, and returns the list.
Here's another one. Remember we talked about the midpoint? How do we get a midpoint? And again, here's a case where there are different, one x and y, one xyz. But here's a lambda. I have two lists, PT 1 and PT 2, point 1 and point 2. So I need two variables. Variable 1, coordinate 1, coordinate 2 are going to match the x from point 1 and point 2. It's going to match the y of point 1 and point 2.
So it's going to take the x's and add them together, and then divide them by 2. And then when it runs through again, it's going to pull the y value out of these two, assign them to those variables. It's going to add the y's together, divide them by 2. Then it's going to do the z's. Oh, wait. There is no z on point 2. So I should get the midpoint in x and y when I run this.
Does that make sense to everybody? We should probably keep moving on. Got about just under an hour yet. Anyone have any questions so far on this stuff? Like I said, you've kind of got to play with it a little bit. One other part of the lambda is this function. You might see that.
This is really to in Visual LISP Editor I can compile an FAS file instead of an LSP or a VLX In compiled LISP, under certain circumstances, if your code breaks or crashes while it's in that lambda, that code can be extremed to your command line, and expose some of your code.
And so when that first came out, well, how do we do that? We built another function called Function, and you put the lambda inside Function, and then that somehow wraps it up and protects it so that code is never exposed. Again, it was probably more important when people were doing commercial programs with LISP. You probably don't see that as much anymore. But you may see it. That's why that's there.
Here's another example. This is the example I was telling you about that I learned the advanced functions on, [INAUDIBLE]. I just selected that object. And let's see what type of object that is. It's a block reference. I want to get the coordinate of something in there through the entities. Or you know what I mean? But because it's a block, because it could have a scale factor, because it could be rotated, because it's also somewhere else in x and y space, how do I get the coordinate of an object inside of a complex object like that?
Well, this [INAUDIBLE] comes back with, what they call, a transformation matrix. Here's the point I picked. But here's the transformation matrix. And you've got to be better at math than me to understand how those work. But it's essentially a list of coordinates that, when you apply them with certain math, can translate one coordinate into another. It can scale it. It can rotate it. It can move it. It can scale and rotate.
So I needed to get the information from a complex object. And that transformation matrix, if you look it up in the LISP help, has got all kinds of complex stuff. There's the matrix, and there is a point. And if you look at the math on the transformation matrix, this is what I needed to do to get the point.
Again, same thing on the above. But instead, I'm using this now instead of this. So I've got all that code, or I've got this code. And I've got a lambda with inside of MAPCAR. And I've got MAPCARs inside the lambda. and I've got MAPCARs inside the MAPCARs inside the lambda inside the MAPCAR. That was my first example. And it's like, gosh, darn-it, how did he ever figure out how to do this? What the heck is that doing?
And that's why I just dug in and tried to figure them out. So I guess I encourage you to use those functions. Dig into them and see.
We've got about 45 minutes left. We'll just touch on recursion quick. Factorial-- you know, a factorial of four is 4 times 3 times 2 times 1. Factorial of 5 is 5 times 4 times 3 times 2 times 1. You know, what am I doing? I'm taking a number and multiplying it by the same number minus 1. I'm really doing the same thing over and over again until I get down to 1. Right? I'm doing the same thing repeatedly,
I'm browsing a folder structure trying to look for files. How many folders are underneath the folder I just went to? I don't know, but there's another folder. Then I'll get to the files. Oh, wait. There are more folders. I don't know.
Recursion is a concept where you build a function, and the function, as part of its workings, calls itself. Sounds weird. That's like saying, you know, I want to nourish myself, so I'm going to eat myself. I mean it doesn't make sense. It's kind of a weird concept to wrap your hand around, you know. If you've ever seen one of those TV screens where they've got a camera of the TV, and the TV's showing you the TV, and it just keeps going down, that's recursion.
In programming, it can be a very useful concept. Where it's most useful is when you have objects of unknown nesting levels. So I know I want to do something, but there might be something else in there, you know. It's like I said, folder structure in files. Within a folder, I can have files and folders. And if I'm looking for files, how do I get to files? I've got to go to a folder. But within the folder there's folders. Well, I've got to get to the files. I go to that folder to get the files, but there's more.
You see what I mean? I'm doing the same thing, but I don't know how many times I'm going to have to do it, because a certain condition may exist.
The other way to describe it is I've got a machine. I build a machine that takes the contents out of a box. It strips the cardboard off. It goes through and all the items are loose. But wait, all of a sudden a box has got another box in it. Whoa. Stop the conveyor belt, put that box in place, run that through. And that strips the cardboard off that sub box.
Oh, wait. There's another box? Hold up. Think of recursion like that. That's what the programming is doing.
Here's my factorial function. And if I say factorial of 4, so 4 times 3 times 2 times 1 is that. But you'll see when I build that function, I give it the number of 4. If my number is zero, just return 1. But if it's not, take the number I gave it, and then multiply it by that same number minus 1. But wait. That might not be 1 either, so I have to do it again. I've got to get to that inner most 1 and work on it.
So this function call here is calling this function. That is just plain bizarre. I still kind of sometimes struggle with how to apply recursion.
But this is what recursion is really doing behind the scenes. I've got a factorial of 4, factorial of 3. It's got, you know, I can build multiple functions. And you got factorial of 1. And so when I call this function factorial of 4, it calls this. While n, and then while 3 is the next number, but I know even with 3, I've got to repeat that process. So I call this function down here. And I pass the 3. Oh, wait. It's a 2? Then I've got to go down here. So that's kind of what recursion is doing behind the scenes.
You know, again, I'm not going to get real deep into explaining these. This is just one of those things that you just kind of play with.
There is a list of unknown nesting levels, let's just say. And I've got something I want to find out if it's in that list. But it could be anywhere in there-- nested, not nested. So I built this little recursive function. Just like MAPCAR and Apply, there's some other ones-- VL some. Is it somewhere in the list? You could look those up. But I've got, you know, I'm doing a lambda in there. But I'm also calling the function, again, in certain circumstances.
So I'm going to define that function. And I'm going to call this, and it returns t for true. Yes, 9 is somewhere in that list.
You know, here's another one. Who here's in manufacturing? Anyone architecture? A few people. Civil? OK. That's the least most trade that I'm familiar with is civil. So I don't know if this applies. But in manufacturing, revision 1, revision 2, maybe that's easy. Right? Just add a, b, c, d, e.
I even see that in the architectural side. What if it's az? What I do? Well, it's aa, ab, ac, ad. What if it's az? Well, now it's ba, bb, bc. What if it's za, zb, zc? Zz now becomes aaa.
Here's a little spring increment function I wrote. I want to increment a. There's my current revision, a. What's the next one? b. The current one is z. Next one is aa. Again, depending where it is, I have to do something all over again. I don't know how far that is.
Again, it's kind of beyond the scope of this to figure it out, but if you can go back to your office and figure out how that works and then write something similar, you'll understand recursion.
All right. Reactor support, the other thing we're going to do here. Project, the paths are different here, so I don't know if this is going to work. I've got a project. So I've got another thing I can do with the visual LISP is make a project. I like to slice and dice up my code. There's a lot of stuff, you know. String functions, like you know, the thing that strips off and gives me the first three letters of a month. That might be a function.
Maybe I've got a function that extracts attributes out of a block, you know. So then I've got a blocked out LISP, and a masked out LISP, and a P-line dot LISP. And I've got all these LISP functions that do specific things. They're just utilitarian, nothing specific.
Now I want to write code. I can build a project and reference in my libraries. Hey, you know what? I really need a function to extract attribute values from a block. I don't want to rewrite it again. It's obscuring from the business logic of I'm putting in my code. I already wrote a function that just magically I give it a block name and it gives it back to me. Done. I can build a project this way and reference in that code and compile it all into one, I can load them.
But I'm going to go and edit this guy. I don't know if it's going to work. Like I said, the project properties. It does seem to find them. There we go.
You know what? Because the paths are in there and it changed from what I had, we're not going to do that. But we're going to get into reactors now. I think that's right. Yeah.
Reactors are code that runs when certain events or triggers happen in your drawing. It's in the handout. There are reactors.
Here I've listed different reactors in the reaction event. So there are commander reactors. Do I want code to run when there's an unknown command, just before a command starts, or every time a command has ended? I could have code that does an undelete every time somebody does erase, or does an undo. You know what I mean? You could do that to somebody. Delete it, as soon as it deletes, calls your code, and does an undo and brings it back. Pretty cool, right?
So this is a whole list of the reactors' types and the different events they have for reference. It's getting harder and harder to find this stuff with the help online.
So a little word about reactors. 38 minutes. I've got to get going if we want to cover Active X.
Reactors can be persistent or transient. A persistent reactor means that I don't have to reload all this stuff in my drawing. So a reactor needs code to manage the reactor, and then it needs code to run. So the code that it needs to run always has to be loaded. So it's got to be in your ACAD.LSP or something. But you need code to configure out your drawing to load to call that code and when to call it.
A persistent reactor, when you set that up, that drawing will always remember, run this code. It's got to be loaded or it won't work. A transient reactor, I open my drawing again it won't run I still need to run my code so that it sets up the environment. It's just good for that session only. So that's a difference between persistent and transient reactors.
A transient sounds like we might want to use persistent maybe. It's just less stuff to do. But when I use a persistent reactor, what if I do something that tries to set it up again? Is the reactor already loaded, or is it not? Maybe it puts it in there twice. So a transient reactor is not too bad either. Just load it. I know it's not in there.
But those are differences. And again, I can't guide you one way or the other. It depends on what you're trying to do.
So I have some reactor support code here. And I don't even remember how this works I don't need to I wrote it once. It's in my library of stuff. I reference it from everything else when I need to do reactors. And this is what helps me know whether a reactor is loaded or not, so I don't accidentally load it twice.
So those are just my supporting functions. I'm going to load this whole file into memory. And we're going to do something simple. We're going to have a little alert box that we're going to call before I save and after I save. Those are my reactors, you know. I'm going to look at when saves happen. And before a save happens, I'm going to execute code, and after save happens I'm going to execute code.
And so this is the code. Pretty simple. Now there's a special way to write reactors. Again, it's in the LISP documentation online, but it needs to know the reactor and the data. And again, that's what those support functions kind of do for me. You know, when that code gets executed, it can give you information like what object caused it, if it's an object based reactor. You know, like a line was modified. Well, how do I know it was a line which line was it that information gets passed in. So those functions need to have two different parameters on their own.
I'm going to load that one. I'm just going to load all of these into memory, because that project isn't working. And we're going to open. So I'm going to load a reactor. I'm going to make it persistent, and I'm not going to check. So I'm going to load this. L-M-R, load my reactor.
So what it's going to do, this loads some of the functionality it needs. It's some advanced. These VLR functions don't work unless you call this first. I'm going to use the [INAUDIBLE] reactor just a little kind of a comment or piece of data. The event I'm looking for before save call this function. After the save, call this function. And so I'm going to build this special variable. That way. And then I'm going to add my reactor, and then I'm going to make it persistent.
So I'm going to come back to AutoCAD, load my reactor. And I'm going to save. (READING) Drawing is about to be saved by mainframe 2. That's the computer or username. (READING) Drawing has been saved.
So now I'm calling two pieces of code-- one before the save, and one after the save. And like I said, you know, that's a persistent reactor.
But what happens if I call that function again? So I can do a Save again, and it's going to keep doing this every time. But what if I type load my reactor again? I made it persistent. It stays in the drawing. I'm not checking to see if it's already there. And I'm doing it q save. (READING) My drawing is about to be saved. My drawing is about to be saved. I loaded that reactor twice accidentally. (READING) My drawing has been saved. My drawing has been saved. I've loaded that same reactor twice in this drawing.
Now as long as those two programs that actually run, as long as this pre-save code and this post-save code is loaded in memory, I can save that drawing, open it back up, and it's still going to work without having to add the load my reactor again.
So let's do that. I'm going to close this out. And I'm going to open that drawing again. Now I'm not going to type load my reactor anymore. Correct? But what I do need to do is make sure-- come on. Visual LISP IDE. I need to make sure that the functions that the reactor is going to call are loaded.
But now when I call it, it's about to be saved. It's about to be saved. It has been saved. It has been saved. So as long as the functions I need to call during the event happen, I don't need to load the reactor every time I open that drawing. The drawing remembers the reactor's there. It just needs the code loaded. That's a persistent reactor.
Let's see here. What's next? So like I said, look at the existing code, and that'll kind of help you what's going along.
I'm going to load a reactor persistent. This time it's checking. But because I've already jacked up this drawing I'm going to start a new one. Right?
All right. So again, because it's a new drawing, I've got to load everything all over again. Visual LISP Editor seems to be a little bit buggy sometimes about bringing it back and forth. I'm going to load those two functions, but I also need to do the reactor support functions, because those are what determine if the code is already loaded. And again, it's kind of broken out.
And again, that's why I use those projects, and I compile them into FAS. I load in what I need. But the code then I only run. Here's load my reactor, but you know, is it loaded? So I'm looking to see if the reactor is loaded. If that one is not loaded, and this one is not loaded, I load the reactors. I only load them once. So using those support functions, I'm checking to see if they're already loaded.
So now when I run this load my reactor routine, same one, it's just we've enhanced it, load my reactor. I'm going to type it once, Q Save. Drawing has been saved. Did I not load the other one? I might be missing pre-save. I don't know that I loaded this. There we go. Wrong drawing. Q Save. About to be saved.
So see what happened? Even though the reactor was loaded, I didn't have the code that the reactor was calling loaded, so it didn't do anything. About to be saved.
I'm going to type load my reactor now. Now I'm going to do a Save again. It's about to be saved. It has been saved. I don't get that double prompt. I can try to load as many times, but I'm checking beforehand.
Like I said, I don't remember how those functions work. I figured it out once, and I just referenced them in. I got a function that tells me. So every time I need to do a reactor, I don't have to figure out how to see if it's already loaded or not. I made it kind of a master function.
Does that makes sense? No? Yes? Keep going?
We also have-- let me close some of these out. Those are all persistent reactors, by the way. Here is a transient reactor.
Again, there's checking and no checking. You guys get what that does. But I'm going to check it. But now you'll see it says Add Reactor. Where the other one had this extra line in there that said make it persistent. So I'm going to use the one here that's not persistent.
So let's start a new drawing again, because I want to start fresh.
All right. Now we're going to go to LISP. And I've got four different things to load. Again, if I had a project set up, it's just the paths are screwed up from my project, because it's different on my system at home than here. So I'm going to go through. I'm going to load this whole window. I'm going to load the reactor support. I'm going to load the pre-save, the post-save code, and this T stands for transient or persistent if you're looking at the code back home.
I'm going to run this, again, same command name, load my reactor. Load my reactor. And I do Q Save. And it's prompting me to save. It's about to be saved. It has been saved. Load my reactor, Q Save. Still only asking me once that it's about to be saved and been saved because I'm checking. But it's now transient. I didn't make it persistent.
So if my drawing is saved, it's drawing three, close out of here, I'm going to go back into drawing three again. Now remember, the code that I want to execute has to be loaded. And that was the pre-save and the post-save. Now I'm going to go to AutoCAD, and I'm going to type Q Save.
My code doesn't execute. Remember it did before? It was persistent. It remembered the reactor was there. It just needed the code to execute. I have the code to execute, but now the reactor is not there when I open the drawing up again. It's not saved with there. I actually have to load all of that stuff all over again.
So that's kind of the key between a persistent and non-persistent reactor. Again, if I load all the reactor support, check it, that's the persistent one. I want the transient reactor. Load my reactor, Q Save, my reactor. Unknown command. I think I missed loading something here. There we go. Load my reactor. Now Q Save.
Come on. I know I missed something here. Reactor Support, pre-save, post-save, and I want a transient checking load. Load my reactor, Q Save. Huh. I might have broken something. It worked before, but you kind of get the idea.
It's the same code. I just didn't make it persistent. But I loaded it back in. This time it doesn't seem to be running. At this point, I would probably exit AutoCAD, restart, try it again.
I haven't done a lot with reactors in a long time. Back when I was doing more with it, I did know that sometimes, in some verticals or flavors of AutoCAD, they would just randomly fail to fire on certain things. I would build the same reactor in VBA, and it would work. It just wouldn't LISP. So the code would work, you know, randomly.
I think that was an AutoCAD Architecture issue, and it was a number of years ago. But, you know, those things can be a little finicky sometimes. I'm jumping in and out of stuff, loading multiple things. But key thing to keep in mind, the code you want to run and execute has to always be loaded manually by yourself.
The reactor can be loaded and configured one time per drawing, or every time the drawing, whether you make it persistent or not. You can take a persistent reactor, make it transient. You can take a transient, make it persistent. There are functions for that. They're in the LISP reference.
Any questions on that other than the many, because it's kind of complicated? Again, it's one of the things you really kind of have to play with a little bit. Yes?
AUDIENCE: You mentioned the vertical [INAUDIBLE] architecture. I've noticed the [INAUDIBLE]. Do you have any idea where [INAUDIBLE]. Is that still going to be supported in [INAUDIBLE]?
DARREN YOUNG: No clue, because we're moving to Revit.
LISP will be around as long as AutoCAD is. The object models for like the VBA style coding are still there in LISP. I don't know about the verticals, because I think that's tied to that whole AutoCAD I thing. My guess, you know what I mean? There are no more verticals really. They're all add-ins, other than I think Civil 3D. My guess is what's there is probably going to be there, if I had to guess. I don't know.
Be vocal with them about it. I beat them up on a lot of things.
So let's see how much time we've got left here. 22 minutes.
So we want to get into the Active X style of programming. And that's the third thing. That's where you're doing kind of Visual Basic style stuff. There are objects. Objects have methods which perform an action, or they have properties that have things.
So if I wanted to get the length of a line, how do I do that in AutoLISP? Does anyone know? Got to get the end points, start and end point, extract the coordinates, and you've got to do the math yourself, which now you know how to do with MAPCAR. Right?
So that's not too bad. But in the Visual Basic style there's a line object. Length is a property of the line object. You know, radius is a property of the arc object, although you can get radius and that stuff from LISP. But you know, there are different properties of that.
So here's where I'll get into a little explanation. All the Active X style functions begin with VLA. They don't work until you call that VL Load Com. I should've brought my little pointer.
I've already called it, but if you're in LISP-- and you know what, let's close out of some of these things. And I'm just going to type it down there. VLA, if you type a function, I'm just going to-- so it might be hard to see when I type add line and finish that, it turns blue, because it's a function. If I take out away the E, it's black. You might type a valid function and it's still black. That means you need to type that VL Load Com to load the Component Object Model for LISP. And that's simple as--
This is the same thing too. You need to do this for reactors to get the VLR functions to work. You can call it-- I can't type. I told you. You can see why I'm not a professional coder.
I can call this as many times as I want. It Doesn't matter. It just needs to be loaded once. So it's customary. If you need that functionality, throw it in the top of the code. You don't need to check to see if it's there. But it loads all those extra things.
So let's see if we're hooked up to the web.
When you go through the Help, it takes you online. And the only thing you can really see about an Object Model is under the LISP Developer Guide-- about object, head objects, model, AutoLISP, Active X. And it tells you kind of the structure of this object. An object is either in paper space or model space. Those things are in the drawing. The drawing as an object. It's got a paper space and model space. Paper space and model space has a line, layers, or you know what I mean? It's kind of a hierarchy structure.
Here's the object model. Now what? Not very helpful. So again, I've got these little tiny rails setup. Install the offline help. Now isn't the power of the internet that you get more than it would? You don't have to install that locally. There's way more stuff on the web than local. Leave it to Autodesk. You get more stuff when you install local than you get in the Cloud.
I wonder if I have permissions to even install this on here. I don't know that I even need to.
And then you can go into your Options in AutoCAD. And system, I clear that. Access online help when available. That forces it to the offline help. In the offline help, there is an Active X Developer Guide. There is an Active X Object Model, which is what I just showed you. But it's hyperlinked. So everything you pick on in that nice little tree structure takes you to the line object. It tells you the events that it can trigger, the methods that you can call on it to create line, delete line, gives you the properties that you can get, length, maybe angle, things like that. So the offline help is where you get all that stuff, but it won't work unless you install that.
And we're just going to do that real quick here so I can show you. It's kind of handy. But we'll see if I've got permission. It shouldn't take too long.
Nice. Something else is already happening. OK, trust me. It's there.
If you want to do actual VBA, there's an enabler for that. They were going to pull support darn near a decade ago, because Microsoft wasn't going to do it anymore. It's still there. Microsoft is still supporting it. So it's not built in, but you can download it. You don't need to do that if you're going to do it from LISP though. Only if you're going to do VBA code.
But you know, I've got some rules of thumb here. Let's go over quick. You probably won't get quite as much into the code because we're running a little low on time, you know.
So the active help says add line. So that means there's a function in AutoLISP called VLA Add Line. There you go. That's what the function name is. That's how you figure out what they are, because the LISP reference doesn't tell you that there's like-- it's in the handout-- 1,000, 2,000. There are like over 1,000 of these functions, and none of them are documented in LISP reference. So you've got to look at the Active X reference, which you can only really get if you install it locally. You don't really get access to that information. I haven't found it online. If you can find it, email it to me. I'd love to know.
But when you see that that's the object or the method, a method is like a function that you're calling. It's going to perform an action. So that's the Visual Basic style terminology. It just prefixes the VLA.
Yeah, use the documentation. Setting properties. There's a start point property. You know, so in LISP, I've got to do this, you know, DXF codes and build lists of dotted pairs and modify the DSF entity codes. There's a start point and end point. So in the Active X setting properties, it says there's a start point. And then it shows you what objects. So VLA put start point. That's how you call that. That's how you put that, assuming it's a read write property, by the way.
Active X, how do you read properties? There's the length property. VLA, get length. Put length. Get length. And now in Visual Basic, it's typically you would type object dot something. So it's, you know, my drawing dot model space dot line object, or you know I mean? It's a hierarchy. So it needs an object to work on.
LISP doesn't work that way, so the first argument in any of the LISP versions of these like Start Point is the object. And it's not an entity name. It's a VLAX object. And there are functions to turn an entity name into an Active X type of object. It's the same thing. It's just a different naming type thing.
Like I said, there's takes one extra argument. So there's the function. You pass the object. So where you'd normally do an entity name, there is a function that converts an entity name into the VB type equivalent. You pass that there, and then the rest of the arguments are the same as with the Active X documentation says. That's how you know what those 1,000 functions are and how you get to them, because you're not going to see it in the LISP reference anywhere. You'll just see it in code, and how did they figured this out?
This is how. It used to be installed locally when it was shipped with it, but it's getting harder and harder to find this information. I almost didn't find it. I took a shot in the dark and installed the offline help, and that's how I found it. But when I taught this last year, you could still get to it a little bit easier. But in 2019 it doesn't.
Here are some helper functions, VLAX. Again, these are going to need the VL dot load com called before you can use these. This converts an entity named to the VLA object's name so that you can use these functions.
This converts a VLA object name back to entity name if you want to use initget in LISP. Does that makes sense?
I'm probably standing in you guys' way. I'm sorry about that. My eyes are getting foggy with my contact lenses.
Where they have lists, VLA has safe arrays. Those getting a bit more. And everything's object-based. What's the root object in AutoCAD? It's the application. The application has a document. The document has a paper space and a model space. Paper space and a model space as entities. You know what I mean? It's hierarchy.
The root object, and that's how you get that there, is the Get ACAD Object. Make a safe array. You can fill it. You can make a variant.
Remember I said before, there are properties up here you can read and write too? Well, what if it's a read only property. What if that property doesn't apply to that object? You've got functions here. Is the property available? Is it right enabled? Help you do some error checking.
Points are handled differently. This takes a 3D point and converts it into the VLA model object, which is a safe array, a variance. It's kind of a pain a little bit.
You've got some other constants. Like Pi is 3.214. It's like a built-in variable. You know, same thing. You've got a bunch of built-in constants for the LISP.
I've rattled on enough. We should probably just blast through a little bit of it quick so you have an idea what I'm talking about. Got about 10 minutes. Yeah, that looks like it's about it.
So we're going to come into LISP. And I'm going to open up my file, Active X functions. Again, going to load com. Well, I should probably draw something first, right, if I'm going to select an entity? Nope. It gets buggier every year.
Here we go. We're going to do an entsel and extract out the entity name. That's what we're used to in LISP. Right? And you'll see that looks probably familiar. Maybe you've probably seen that before. I'm going to convert that entity name to an VLAX style object.
It's like the entity name. Is just what the VBA style, the Active X style of LISP needs to look at. So I can convert that entity name to that.
Here's my get length. Here's the object. That's how long that line is. I don't have to go and do an entget. You know, I don't have to extract the group, look for the DXF codes to pull out the start and end point and add them together, or do the math. I can just get the length. Is that easy? It's not too bad. It just takes a while to get used to translating the language back and forth.
So what are we going to do? No lines selected. So I need something that's not a line. There's some text. What's the length of text? It's probably not going to be-- I'm hoping it doesn't have a length property.
Again, I don't need to call load com anymore, but it never hurts to put it there. And I've got it there just in case that's where you start. Select an object. I can convert it to the Active X name.
Is this property available, the length? No. So I can say, if it's not available, tell me no lines selected. If it is available, it's going to get the length.
So let's do this again and select it all. This time we're going to select the line. And sometimes Visual LISP Editor gets a little wonky on you.
So I'm going to load that, select the line, convert it to the Active X object, and now because it's a line and that property was available, that's how you do some of the error checking on this side for the Active X.
Eight minutes. So we've still got some time. This stuff is actually not too bad.
Let's set the layer. You know, so again, here's a property layer. Put object, the layer I want. So the property's available, but what it's not checking is to see is if the layer exists.
So I'm going to make a layer. I'm going to make it match what my LISP code is looking for. And if I would take the time and look, I probably already have it as a sample drawing.
I'm going to go back to LISP Editor. Again, I can come here. I'm going to grab the object, convert it to the Active X object name, and if the layer is a property and it's right enabled, I'm going to change the layer. And now it's green like I set up.
What else we got in here? You'll notice sometimes it jumps back like that.
Here's an add line. Now there's a few parts to this. This one I need to know where to put it. So I've got to get the AutoCAD object. That's essentially the entity name of AutoCAD.
Now I need to get the entity name-- well, it's actually an object-- of the active document I'm in. And now I'm getting the object name of model space, or I could put all that together and do this in a single line. That's fine. Either way works.
So one of the things I do is see how the points are structured. You know, if we're going to draw a line, we've got to see. I already told you, the points are different. And now here's my object name. And I'm going to set this variable by-point to the get start point. And you'll see now here's this variant.
I'm going to inspect that. That variant is a safe array of doubles, and there's my point. It's nested in there a little bit deeper, isn't it?
So here's how I can make a new point. I'm just going to get point. And I can do a make safe array of doubles. It's a two-element array, x and a y. And I'm going to save that to my Start. I'm going to fill that array, and now I'm going to make that start variable, again with the variant.
Now that was the first point. That's how to do it manually. I could do it this way. I could do get point, and there's a function that converts that 3D point to what Active X wants to see. There's my start point. And now I'm going to make the line.
Add line. There's the object. There's the start point. There's the end point. And then I come back here. I should have a line.
Make sense kind of? Again, you know, you've got to play with it a little bit. We've got about four minutes or so left. It's really all I've got to show. I'm happy to take questions. I can't stay really after the class. I'm already 15 minutes late for an Autodesk session where I have to yell at them for how they're destroying our productivity with some of their software plans. But you can always email me, or if you see me, grab me.
Like I said, I've got another five minutes yet. I'm not going to leave early. So if you do have questions, come up. But it's one of the things you just kind of got to play with it an get comfortable with it. But it's not that hard. Just dig in and have fun. But thanks for coming. I've got cards up here if you need any.
[APPLAUSE]
Downloads
Etiquetas
Producto | |
Sectores | |
Temas |