Tuesday, February 20, 2007

I can already do that

Why are there 4672 different word processors or hundreds of CAD programs available (I made the numbers up)? Because somewhere, sometime, a programmer was sitting at his keyboard whacking away on something he felt was truly important and when someone said "I can already do that", the first words out of the programmers mouth were "yeah, but....". I am today formally proposing that this be adopted as the official motto of petty programmers everywhere. For example there are at least two perfectly good ways to remove the arc codes from a Vr line entity. If you want to clear entire layers of the pesky point flags, delarc is the ticket. For a single line or two edilin has the ever popular B6,B6 combo that will do the same thing for any line you latch on to. "Yeah, but" what if I want clear 5 individual lines in a point and click method where each line identified is cleared of arc codes (or any other flags which is part of the moral of this post). How about clear_arc.py?

As a whole it looks like.

Ws=PyVrWs()
Line=PyVrLine()
WsNum=Ws.Aws()

while Line.Id() != -1:
..Ws.UndoBegin(WsNum,"clear_arc")
..for PointNum in range (0, Line.GetNumXyz()):
....p, a, c, f, m = Line.GetPointFlags (PointNum)
....Line.SetPointFlags (PointNum,p,0,c,f,m)
..Line.ReRec ()
..Line.SetWidth(2)
..Line.Plot()
..Ws.UndoEnd(WsNum)


Taken apart.

Ws=PyVrWs()
Line=PyVrLine()
WsNum=Ws.Aws()
Initialize what will be needed.

while Line.Id() != -1:
Been a while since we've used the Id() function, remember that it returns an open object, ready to interact with.

..Ws.UndoBegin(WsNum,"clear_arc")
This time the undo points are set inside the Id() loop so if the wrong one is identified the user could just exit and undo the last modification while anything else would remain cleared.

..for PointNum in range (0, Line.GetNumXyz()):
For every point on the identified line.

....p, a, c, f, m = Line.GetPointFlags (PointNum)
Get the existing point flags.

....Line.SetPointFlags (PointNum,p,0,c,f,m)
Set them all back as they were except for the arc flag which will be set to 0.

..Line.ReRec ()
Re-record the line that is loaded.

..Line.SetWidth(2)
..Line.Plot()
Change the graphics as a verification and plot it (after the ReRec so graphic changes aren't stored).

..Ws.UndoEnd(WsNum)
Set the undo endpoint for each line identified.

Note that point flags are documented in the VrPython documentation as follows.

p, a, c, f, m Flags

p-Pen code (0=None 1=Up 2=Continue 4=End)
a-Arc flag (0=None 1=Beginning, end or PRC 2=Mid point 3=Point on arc)
c-Code (0-255)
f-Bit encoded flag (0-255)
m-Mosaic width (0-255)

If a parameter is passed as –1 then the original number is not changed

Example Line.SetPointFlags (PntNum, PenCode, ArcFlag, Code, BitFlags, MosaicWidth)

The bit encoded flag isn't used much that I know of and can be a handy way to mark a point for further consideration, Always check with someone at Cardinal Systems before using this flag because if it is implemented for something then there could be conflicts between a python program and Vr functions that use the same bit. A good example of this is to run batnod, id a line that was noded, move to a node point, and look at the f display in the menukeys dialog.

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.