Thursday, November 01, 2007

Inherit everything but the kitchen sink.

Back when I was just a young map maker, I was actually fairly sharp, and had a memory that was quite useful. I worked on a CAD system that until VrOne came along seemed like one of the fastest, most practical, easy to use map collection systems around. It used a numeric command set that allowed you to set any combination of insert parameters to a 3 digit code. Alas you were limited to 120 codes which seemed like plenty and were quickly memorized. Of course now I can't remember what I had for breakfast (I did have breakfast didn't I), but I can remember all 120 of those codes. The flexibility of Vr allowed me to easily make macros that do those 120 tasks, but over the years we continued to add things. Now I know there is a function key that will put in a double yellow road centerline, but what combination of letters did we use for the function key (there are 26 letters and 5 unique words in that description). Sometimes when I'm collecting I think good grief, there is what I want right there, it sure would be nice to just change my current parameters to match that existing entity. Well, back in January I added a quick command that came in handy more often than I thought and has grown up since then. The premise was simple, a command that allowed you to Id a line, then start digitizing using the attributes of that line. Remember it looked something like this

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))

It was so handy that I made one that did the same thing for fly-lines, and symbols. This way when I'm tying to an edge or come across something I forgot, and can't remember the function key, all I need is the short mnemonics for my inhlin, inhfly, and inhsym commands. Then I got thinking, what if I'm already digitizing a line or symbol and want to match something I happen upon? Well here is my inhent.py which some folks might find a bit odd but it also gives examples of a couple of useful Vr Objects

print 'inhent.py Inherit From Entity modified 8:52 AM 10/31/2007'
'''
Copyright 2007 Dennis Shimer, M.A.N. Mapping Services Inc.
Vr Mapping copyright Cardinal Systems, LLC
No warranties as to safety or usability expressed or implied.
Free to use, copy, modify, distribute with author credit.

Asks user to identify an entity, then sets certain
parameters inherited from the identified entity.

'''

Line=PyVrLine()
Sym=PyVrSym()
Text=PyVrText()
Gui=PyVrGui()

Ws=PyVrWs()
# There are a couple of times we'll need to multiply by the scale because ground
# units are returned, and we'll need to set based on map units.
Scale=PyVrWs().GetTargetScaleIn(Ws.Aws())

EntWs,EntNum,EntType,LinePtNum,x,y,z=Ws.IdEnt(-1,-1,-1,-1)
# Man I love IdEnt, it isn't in the documentation yet but by using
# -1 in the SeaEnttype spot, it remembers the last state.
if EntType==1:
# If it's a line grab the appropriate settings
...Line.Load(EntWs, EntNum)
...Layer,Graphic,Width=Line.GetLayer(),Line.GetGpoint(),Line.GetWidth()
# This line is left over from when I forced the user to hit end after
# identifying the entity, which was useful if you grabbed the wrong one
# but I found I liked it this way better, so the following line doesn't
# really matter because it just does it after you id something.
...Gui.DspMsg0 ('lay=%d, grp=%d, wid=%d'%(Layer,Graphic,Width))
...Type='Line'
if EntType==3:
# Ditto if it's a symbol.
...Sym.Load(EntWs, EntNum)
...Layer,Graphic,Radius,Rotation=Sym.GetLayer(),Sym.GetGpoint(),(Sym.GetRad()/Scale),Sym.GetRot()
...Gui.DspMsg0 ('lay=%d, grp=%d,rad=%.3lf,rot=%.3lf'%(Layer,Graphic,Radius,Rotation))
...Type='Symbol'
if EntType==4:
# or even a piece of text.
...Text.Load(EntWs, EntNum)
...Layer,Font,Height,Width,Rotation,Label=Text.GetLayer(),Text.GetFontNum(),(Text.GetHgt()/Scale),(Text.GetWdt()/Scale),Text.GetRot(),Text.GetText()
...Gui.DspMsg0('lay=%d,fnt=%d,hgt=%.3lf,wdt=%.3lf,rot=%.3lf,txt=%s'%(Layer,Font,Height,Width,Rotation,Label))
...Type='Text'

# Once you grab the settings desired, the only thing left to do is
# push the proper key-ins.
if Type=='Line':
...Gui.PushKeyin ('lay=%d,grp=%d,wid=%d'%(Layer,Graphic,Width))
elif Type=='Symbol':
...Gui.PushKeyin ('lay=%d,grp=%d,rad=%.3lf,rot=%.3lf'%(Layer,Graphic,Radius,Rotation))
elif Type=='Text':
...Gui.PushKeyin ('lay=%d,fnt=%d,hgt=%.3lf,wdt=%.3lf,rot=%.3lf,txt=%s'%(Layer,Font,Height,Width,Rotation,Label))

Given that there probably aren't 3 people in the world that read this on a regular basis, I'll probably hit it about once a month from now on. Don't forget to contribute to the forum.

Happy coding.

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.