View Full Version : Scripting


Klox
05-16-2003, 12:09 PM
Hu,
I have grasp the idea of scripting....eventually (i feel like an idiot confessing this). As i understand scripting is done in Basic. From the posts i've read you wrote about (mostly at the BobCAD support forum) scripting i know you must be a Pro.

Could you give me pointers on books about Basic?

Thanx
Klox

:drowning:

HuFlungDung
05-16-2003, 01:09 PM
(chuckling at the funny little image in your post)

Klox, I'd hate to give you references that wouldn't help you much because Bobcad's scripting language is ......homemade ;)
I guess the general rules of logic apply, but when unknown traps are lurking under the surface of what should be straight-forward, it can be frustrating.

I've picked up so many bits of info from all over, that I really couldn't point to any book and say: "This is what I used". Studying scripts that other people wrote (ie., scripts that came with Bobcad, plus other cool people that took the time to help me out, like James Bond0h) is where I learned to do it.

The basic principles of what they call Boolean logic, I think, is sort of the starting point: how to work with IF THEN statements, how to make loops, use AND and OR, and ELSE and ELSEIF. Then you have the different types of variables, and how to set them up and call them, how to use a debug tool to test your logic.

I poured over the vb scripting manual that came with Bobcad a lot, trying to understand the rules of syntax (the exact way of writing a command). A bit of study conducted on the internet on unknown terms revealed a lot of material to help clue me on on what I wasn't familiar with.

But, by far, learning by studying other scripts is by far the best tool to learn with. I usually pursued specific ideas that I wanted to encapsulate in a script, and in doing that, went down lots of dead ends of course, but even those teach you something. What do they say: "If you've made a lot of mistakes in a given field, you gain experience, but if you make all the mistakes, then you are an expert" I'm getting close :D

hardmill
05-16-2003, 11:45 PM
Originally posted by HuFlungDung
(chuckling at the funny little image in your post)


But, by far, learning by studying other scripts is by far the best tool to learn with. I usually pursed specific ideas that I wanted to encapsulate in a script, and in doing that, went down lots of dead ends of course, but even those teach you something. What do they say: "If you've made a lot of mistakes in a given field, you gain experience, but if you make all the mistakes, then you are an expert" I'm getting close :D

Well said Hu !!

Klox
05-17-2003, 03:48 AM
Thanx for your quick replies. The one thing life taught me is that humor takes the bumpiness out of every road we might take.
I try doing some scripts on my own, i'll either swim or drown!!!

Enjoy your weekend!

Klox

sorincnc
06-23-2003, 12:42 PM
Originally posted by Klox
.I try doing some scripts on my own, i'll either swim or drown!!!

Enjoy your weekend!

Klox

Klox,
What do you have to loose???? Remember, nothing is lost as long you learn something. What I tell all the guys thatt I train is to print as much scripts as possible and the take them one at the time and read them over and over until things seem to make sense when they try to run them. If you go to the "Special\scripts" comand you will be able to select a script and then "execute" it. On the bottom of the script selection window there is a box that you can check called "STEP". This will take through the script step by step (kind like single block on a CNC machine). This is especially good when running a script for the first time because you will find out where the mistake is (most of the time).
Hope this helps,
Sorin

Kookaburra
07-07-2003, 11:53 PM
Everyone,

I must add that experience is the best way. I also must add on BobCAD's behalf that their manual shows in great detail how to get from drawing to g-code, well done BobCAD!!! Scripting is a very advanced option and I must admit a very nice option indeed, I use it all the time to create my own drawing and g-code programming facilities and I have found that if you know the fundamentals of basic programming and how scripting works, then most of the information you need to have success is in the BobCAD Manual. I must ask this question, when you buy a car you are given a manual that explains where all of the buttons are and what they do but author of the manual will expect that you at least know how to drive the car.

Klox
07-08-2003, 02:05 AM
Kookaburra,
Nice to hear from you!
I'm actually a BobWIRE user and i haven't had the need for scripting in BobWIRE yet. The guys i am competing against in my neighbourhood either uses PEPS, MasterCAM, HCAM or even Cameo (can you believe it!).

I got myself BobCAD V18 a while ago and being inquisitive by nature i am checking out scripting. I must admit that i am using V18 a lot as a vehicle to import DXF and IGES files from other packages as it is more powerfull as V16.

I do not have much time to play around with scripting, i have done one experimental script and i see that it would take time to get the hang of it. I must say that it is very interesting!

See you,

Klox

Kookaburra
07-08-2003, 02:24 AM
Klox,

when you get into scripting and get good at it, it veryyyyy hard to
stop thinking about all the possibilities, the fact that you can manipulate both the nc code and the geometry is beautiful. To get a handle on it first have a look at the sample scripts issued with BCC V18 and work out how the dialogue and variables work then do some script recording eg: set record on and draw a line, then open the script and edit the actual values to be variables, set your code to bring up a pop up window to ask you the values that will be assigned to the variables you have stipulated and see how you go. Once you have the basics it it not a hard climb from there. If you wish you can contact me and I will be happy to help you get started.

Klox
07-08-2003, 05:14 AM
Kookaburra,
Thanks for the generous offer. First question: Scripting does it "happen" in Basic or Virtual Basic?

Please type a teeny weeny bit slower the next time as i am a slow reader! LOL

Just pulling your leg!!!

Klox

Kookaburra
07-08-2003, 06:06 PM
Klox,

I would suggest you would call it virtual basic because you are dealing with a piece of software that houses its own library of required statements for calling on functions within the software itself and there are some minor differences in how you arrange the whole program to best work. But if a basic programmer had to learn the scripting environment within BobCAD it would not take much time to get a grasp of what is going on.

For example, in a script you can automatically create a layer, select a line, divide a line, create an arc, etc. These are special cad functions that have to align with a piece of software that can interperet them and perform an on-screen outcome. So I guess BobCAD to a certain extent had to change the "so called normal" to make things work.

Typed slower this time by holding a coffee in one hand and typing with the other.

Clear as Mud ? :D

Jennifer
07-14-2003, 06:00 PM
Hey Guys!

Every time I try to get into this scripting thing my computer freezes up. I've got the "Intro to BOBCAD Basic..." and following along, doing nothing more than the first exercise (rectangle w/circle) to record a script...I try to play it back...computer rigor mortise. Doesn't make it seem too friendly.

Any thoughts?

Jen

Kookaburra
07-14-2003, 06:18 PM
Jen,

Did you edit the script to define all of the variables, popup window, etc. If so, can you give me a better description of what the PC is doing. Are there any error messages or does it just sit there in crash land. Usually this comes from a slight glitch in the scripting code. I will be happy to look at it for you. Feel free to e-mail me the *.bas file for some trouble shooting. A small problem it will be. :idea:

HuFlungDung
07-14-2003, 06:26 PM
Hi Jennifer,

Bobcad is object-action, so this requires that you have whatever objects you want to operate on, selected before the script runs.

Keep in mind that there are some things you can do while recording a script that you cannot play back. Generally, anything that you do with the mouse is recorded by the script recorder, but will not work when played back. This means you have to figure out the "menu method" of doing whatever it is you are going to do. This is the way to make a "good recording".

Generally, mouse actions that are recorded are preceded by the prefix "X", such as XSelect, or XCadlayer, etc. The last patch ( the one that was pulled), if you are running that, happened to screw around with this command structure a little bit, so that "Select Layers" would no longer work, but "XSelect Layers" would.

The menu commands are generally valid commands to run when you try to run a script. You can learn what they are by means of the script recorder, that is the real reason to run it in record mode in the first place.

:)

Jennifer
07-15-2003, 11:03 AM
K -
It just sits there in "crash land" until I "end task" the ol' fella.

H-
"Generally, anything that you do with the mouse is recorded by the script recorder, but will not work when played back. "

So, everything has to be done from the last command? This must be why the auto preselect has to be on...

I'll have to mess with this a bit more and get back to you guys.
Thanks for the prompt replies.

Jen

HuFlungDung
07-15-2003, 11:31 AM
Ah, yes, I knew there was something about "auto-preselect". It may need to be on for scripts (I'm not positive what happens when it is off) but auto-preselect needs to be off for trim2 to work correctly.

Actually, with the script recorder, you could also record the commands in the environment settings change required to turn auto preselect on and off. Then you could incorporate these commands at the beginning and end of a script. I never thought of doing that before, but it is feasible.

Good luck!

Jennifer
07-15-2003, 12:00 PM
Here's what I'm trying to do...

I draw a line...put end pts on it...another parallel to it......3 pt arc using the end pts and the parallel line...When I play it back I get no arc...Is this because I have to deselect between commands? How would I do this otherwise?

HuFlungDung
07-15-2003, 12:17 PM
Post your sample script here so it can be discussed.

Hint: you cannot actually use the "LineParallel" command in your script because it requires mouse interaction to work, unless you had some way of knowing which side you wanted the offset line on.

You would be best to create the two lines from coordinates, or you could copy and move a line that you create from coordinates.

Part of the trick of scripting is figuring out a way to do something without using all the mouse shortcuts that you are accustomed to using. This sometimes involves writing quite a bit of code just to do a simple thing, but if that is what it takes for the script to execute, you are pretty much committed to doing things the long way.

Kookaburra
07-15-2003, 05:24 PM
HF & Jen,

I have found that offset works much better that lineparallel. Lineparallel is a workable function given the right circumstances but I never usually worry about when is right and when is not I just use the offset function.

Jen, I will have a go at what you are trying to do and get back to you.

Kookaburra
07-15-2003, 11:54 PM
Jen,

I hast completeth thy task. I will work out how to get it over to you. Maybe I should post it up as a technical article, or both, let me know. I have set it out as a step by step description of what code is doing what and where. The script would normally be very short but I have filled it full of remmed comments to make it easier to follow. I used script recording just to get some basics into it then did a final edit. I could have done it in a quicker way but I chucked a few extra steps in there to give you a better understanding of how scripting works. Hope it is OK.

Jennifer
07-16-2003, 10:06 AM
Kookaburra - (would that be "Kook" for short? :) )

That sounds great! I think you should post it both here and in the technical articles - I'm sure lots of others would appreciate it.

Thanks a bunch!

Jen

Kookaburra
07-16-2003, 09:13 PM
No Worries Jen

I made a monumental mistake. I did the article on line and submitted it before I copied and pasted what I had done into a file that I could post up here. As soon as Paul views the tecko article I will be able to access it again and post it up here as well.

No word from Paul yet on when it will be released but I am sure he will let me know soon.

Hang In There. In the mean time do you want me to e-mail you the raw script? It has some comments through it explaining things.

Let me know, it is only a small file.

Kook

Kookaburra
07-16-2003, 10:03 PM
Hi All,

I just noticed that the tecko article is up there now. Man where did all of the carridge returns go? It looks like a jumble of letters in a scrabble box. I appologise for that. I did have it set out so it was actually easy to read, 100 points to those who can not follow it. Not even I can. I will get it sorted somehow.

Jen I have done up a nice little word doc if you want it, I have attached a zip file with the script together with instructions and also the raw script full of handy comments to help you through, that offer is for anybody else as well.

Patience please while I get tech article sorted.

Kook

HuFlungDung
07-16-2003, 10:18 PM
Heheh Kook, that's why we call 'em technical articles.

Just the hard data ma'm, just the data :D

Kookaburra
07-16-2003, 10:25 PM
HF,

You hit the nail on the head "HARD DATA" is an abreviated version of "HARD to read this junk DATA"

Kook

Jennifer
07-17-2003, 10:07 AM
K -

I'd printed out the "technical article" for some light reading ( :D )...this is much much better.

Jen

Kookaburra
07-17-2003, 03:21 PM
Jen,

Did you try running the script?

Kook

Klox
07-18-2003, 02:57 AM
I downloaded it too. It's with shame that i have to admit i haven't even unzipped it (welcome to Africa!).

I'll let you know what i understand about the script...

Klox

Kookaburra
07-18-2003, 04:52 PM
Guy's,

I am working on a beauty at the moment. The next posting will take you from the initial creation of the script right through to making it a perminant part of your BobCAD Menu System. I have chosen an application for cad drawing that you will all find handy to have as part of you BobCAD system. Remember, scripting is a powerful tool. If there is some function that you wish BobCAD had as part of it's drawing facilities, let's use this scripting thread to all get together and work on creating it.

I should have it up early next week, "I hope". I still have to build CNC Controllers somewhere in amongst it all. I will take my laptop home over the weekend and work on it over a beer or 10 , I will probably have to stop after the 10th beer or I will start slurring my typing. Hopefully, I won't be interupted by anoying visitors and screaming babies.

:cheers:

Kook

Kookaburra
09-12-2003, 03:54 AM
Hi all,

Sorry for the delay on the above mentioned article, I have been pounded with a whole lot of stuff that has prevented me from doing fun stuff like this, I am back on it now and hope to have something for you all soon.

The One
10-02-2003, 11:11 PM
Guess What!!!

I have figured out the little quirk in the scripting engine. I know how to do VB, I started with database applications, but BobCAD's scripting is funky.

I am so full of spunk I am taking 3 requests this weekend and this weekend only. Do you need a drawing script, how about a G-Code editor script (Associative toopathing not allowed, I am still working on that one). Post the request and I will get it to you by Tues. Again, 3 requests. I will post them for everyone to see!!!

Regards
The One