Friday, January 05, 2007

Need a new command?

A quick end of week freebie. Here is an example of a really useful program that a person could think themselves justified in griping that it doesn't exist in Vr. Emailing someone and asking for it, looking in each beta release hoping that a life of clean living and good fortune deems that your suggestion is incorporated. OR...... learn a little python and spend 5 minutes writing it yourself. Sure we could each come up with a hundred examples of tools we would like to see, the problem is that half the suggestions on each list would be unique, to which each would say, "How can you want that, this idea is much more important" while at the same time the poor beleaguered programmers struggle to keep up with dumb questions ( note: comic aside which I only mention because I have a string of about 3 for 6 that were total time wasters on the order of "what do I do with the 3 prong cord hanging out the back", to which the answers were still gracious and helpful)

User question: What would it take to write a command that would essentially be insert line in which you ID a line to inherit properties from then start digitizing with the those properties?

How this works is fairly obvious, let me just explain what I think the more elegant points of python are.

Line = PyVrLine ()
Gui=PyVrGui()
Line.Id()
lay,gp,wid=Line.GetLayer(),Line.GetGpoint(),Line.GetWidth()
Gui.PushKeyin ('inslin,lay=%d,grp=%d,wid=%d'%(lay,gp,wid))

We're going to need a Line(), and a Gui() object, then grab the line to inherit from using Id(). What I love is that on the next line we are declaring 3 variables and setting them to the proper values at the same time without ever worrying what kind of variable they are. Then sending the inslin command and all the keyins on one line using python text formatting. So the answer to "what would it take?", not much, cool eh.


No comments:

For anyone interested in trying VrPython for the first time or if you are early in the game, I suggest going to the earliest posts and working forward. I use VrPython every day for many wonderful things, needless to say it will change and could potentially damage a file. Any risk associated with using VrPython or any code or scripts mentioned here lies solely with the end user.

The "Personal VrPython page" in the link section will contain many code examples and an organized table of contents to this blog in a fairly un-attractive (for now) form.