Jump to content

MullinRJ

Member
  • Posts

    2,007
  • Joined

  • Last visited

Everything posted by MullinRJ

  1. Giovanni, It's been 5 months, and you may already have the answer, but for those that don't... This is not a Python problem, but rather a quirk of the AlrtDialog() call, and possibly its Modern Dialog underpinnings. Use two ampersands '&&' to show a single ampersand in an Alert Dialog string. Use a single ampersand '&' in Message() command strings and in normal string use. This holds true for both Python and VectorScript when using AlrtDialog(). Examples: 1) vs.AlrtDialog('Watch out for Alligators && Snakes!!!') vs.Message('Good luck avoiding Death & Taxes!!!') 2) forAlrt = True S = "Your Appetizer: {} {} {}".format('Cheese', '&&' if forAlrt else '&' , 'Crackers') vs.AlrtDialog(S) forAlrt = False S = "Your Appetizer: {} {} {}".format('Cheese', '&&' if forAlrt else '&' , 'Crackers') vs.Message(S) HTH, Raymond
  2. I am getting frequent errors that do not clear after I edit the module. Python continues to present the error at the end of the Error Output file after the error has been corrected. The errors are in modules I've written that I am importing into a larger program. How can I reset the Python engine to move past this? Example: aVar = Tuple1 - Tuple2 Error received: TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple' So I change the operator to "+": aVar = Tuple1 + Tuple2 but on the next execution I get the same error: TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple' This seems to happen with any "TypeError" I get in an imported module. They do not clear unless I restart VW. I have tried: import Polys from imp import reload reload (Polys) to no avail. Also, turning ON and OFF the "Run scripts in developer mode" pref has no effect. The only thing I have found to work is restarting VW. There has got to be a simple way I am unaware of. TIA, Raymond
  3. VG, PIO code executes multiple times when placing an object. If you put an AlrtDialog() call in your event loop at the very top, you can count how many times it actually goes through. The count may differ between object creation and object regeneration, but I'm not sure anymore. I've forgotten more than I currently remember on this topic. I know on one loop through your code, VW builds the gray outline that shows on the screen before you click to place it. Another loop actually builds your object. If you want to see how many times VW thinks your object is new, change your Message() to an AlrtDialog() and count. This is all part of the fun of figuring out how things really get done. Please be careful and avoid having too much fun at one time. It could drive you to drink (or worse). Good luck, Raymond
  4. Bill, You can test CW / CCW 'ness with the CrossProduct() function. If the CrossProduct's Z component is positive, the angle turns one way. If it is negative it turns the other way. If it is 0, the lines are collinear. The sign of the Z component is determined by the Right-Hand-Rule, which is well documented online. The magnitude of the CrossProduct's Z component is not important in this test, just its sign. If your lines always have a left/right angle between them the following code will test for CW/CCW: This should be easy to follow: function isCCW(P1, P2, P3 :Vector) :Boolean; { Return TRUE if the angle at P2 is CCW, FALSE if it is CW (or straight). } Var V1, V2, CP :Vector; Begin V1 := P2 - P1; { first line } V2 := P3 - P2; { second line } CP := CrossProduct(V1, V2); isCCW := CP.z > 0; End; { isCCW } If you are interested in more compact code (like me), then here's the same routine squished: function isCCW(P1, P2, P3 :Vector) :Boolean; { Return TRUE if the angle at P2 is CCW, FALSE if it is CW (or straight). } Var CP :Vector; Begin CP := CrossProduct(P2-P1, P3-P2); isCCW := CP.z > 0 ; End; { isCCW } HTH, Raymond
  5. As long as you have not converted the Solid Subtraction to a Generic Solid, you can reverse the addition/subtraction process by ungrouping the Solid. One UNGROUP per step. Then subtract again by selecting the other object for the subtraction. HTH, Raymond
  6. Yes. I'm sure it could be done with supplied nodes, but there is little support for vector math in the current set of nodes I searched, so the easiest way I found was to roll a custom node. Here's my stab at one that answers your question. If it's not exactly what you need, try tweaking the code inside, but if you do, please post back your changes. HTH, Raymond
  7. Hello Mark, Looking at your file's resources I was able to find the 41 colors you cannot delete. I selectively deleted groups of resources and purged the colors after each deletion. When the total color count dropped I knew there were color assignments in that batch of resources. I closed the file without saving and reopened it, looking more closely at individual resources. One of the colors (Center Line Red) is in your hatch "Unused Lights ". I assume you want to keep this. Three colors are in your Line Types, "RGB" and "RGBW". Check the geometry. I assume you want to keep these as well. The rest are in the objects of your symbols. I got the count down to 23, minus the four colors mentioned above, leaving 19 in your symbol library. I am not sure where these reside, defined inside PIO's or set in a PIO's instance, perhaps. You may have better insight than I. When you set an object to use class colors, the object still retains its original colors. I modified the script above to remove individual object colors in addition to setting all symbol objects to use class colors. It should be possible to search for objects using non-B&W colors. If you'd like to pursue that avenue, please contact me offline. I hope this gets you back on track. PROCEDURE MakeAllBW; { Set ALL Class Colours to B&W. } { Set ALL objects in symbols to accept colour attributes by class. } { 21 Mar 2016 - Raymond J Mullin } { Updated to also set symbol objects to B&W for their default colours. } { ***** ALWAYS use this script on a COPY of your data! ***** } VAR I :Integer; ClassName :String; function SetColourByClass(H :Handle) :Boolean; { Set Fill and Pen Colours to be "ByClass", and reset each object's default colours to B&W. } Begin { Set each object's default colours to B&W. } SetFillFore(H, 0, 0, 0); { black } SetFillBack(H, 65535, 65535, 65535); { white } SetPenFore(H, 0, 0, 0); { black } SetPenBack(H, 65535, 65535, 65535); { white } { Set each object to use class colours. } SetFillColorByClass(H); SetPenColorByClass(H); End; { SetColourByClass } BEGIN { Change colour attributes of all classes to use Black & White. } for I := 1 to ClassNum do begin ClassName := ClassList(I); SetClFillFore(ClassName, 0, 0, 0); { black } SetClFillBack(ClassName, 65535, 65535, 65535); { white } SetClPenFore(ClassName, 0, 0, 0); { black } SetClPenBack(ClassName, 65535, 65535, 65535); { white } end; { for } { Change all objects in Symbol Defs to accept colour attributes "By Class" } ForEachObjectInList(SetColourByClass, 0, 2, FSymDef); { 0=All objects, 2=Deep } SysBeep; { sound off when done } END; Run(MakeAllBW); All the best, Raymond
  8. Sure. I love a good puzzle. Glad I could help. I was trying to send you my email address offline, but my outgoing mail server is bottled-up just now. Try using the AOL address in my profile. Raymond
  9. Mark, This should do what you described. Make sure you try it on a test file first. PROCEDURE MakeAllBW; { Set ALL Class Colours to B&W. } { Set ALL objects in symbols to accept colour attributes by class. } { 21 Mar 2016 - Raymond J Mullin } { ***** ALWAYS use this script on a COPY of your data! ***** } VAR I :Integer; ClassName :String; function SetColourByClass(H :Handle) :Boolean; { Set Fill and Pen Colours to be "ByClass". } Begin SetFillColorByClass(H); SetPenColorByClass(H); End; { SetColourByClass } BEGIN { Change colour attributes of all classes to use Black & White. } for I := 1 to ClassNum do begin ClassName := ClassList(I); SetClFillFore(ClassName, 0, 0, 0); { black } SetClFillBack(ClassName, 65535, 65535, 65535); { white } SetClPenFore(ClassName, 0, 0, 0); { black } SetClPenBack(ClassName, 65535, 65535, 65535); { white } end; { for } { Change all objects in Symbol Defs to accept colour attributes "By Class" } ForEachObjectInList(SetColourByClass, 0, 2, FSymDef); { 0=All objects, 2=Deep } SysBeep; { sound off when done } END; Run(MakeAllBW); All the best, Raymond
  10. Yes, I appreciate your problem, and this is exactly what scripting can address. Back shortly, Raymond
  11. So, it seems not all objects are set to have their attributes to "Set by Class". If you have your classes set the way you like them, then all you need is a script to set all objects to "attributes by class". Do you want ALL attributes controlled by class, or just the color attributes? Raymond
  12. Are you setting your colors by class, or individual object attributes? A script would be pretty easy, but one needs to know which set of colors to change. Raymond
  13. I'd like to see a field that tags a post with the current or relevant version of VW that applies at the time of posting. It should default to the current version, but the poster could select an older version or versions relevant to the version he/she is currently using. When reading through older posts it's not always obvious which version is being discussed. It might also be useful to have a way to flag a post as still relevant in future versions, since issues don't always get resolved by the next release. Thanks, Raymond
  14. Hello LarryO, 175 is the preference number you need. However, to set Pref 175 to TRUE, Preference 168 must already be set to TRUE. So, try this two line script to return VW to the way you like: SetPref(168, True); { Rounding Style: Fractional } SetPref(175, True); { Exact as Fractions / Non-Exact as Decimals } Raymond
  15. Halloo, Mr. Do, Late to the party am I, but I want to proffer some alternate algebra to your question. You almost had your answer in your first post. See the following code to see what was missing. And though your trigonometry is spot on, there are some handy vector functions built into VectorScript that make life a little easier once you get familiar with how they work. Again, see following code. To use this script, draw an arc on a design layer, leave it selected and run the script. The script will deselect the arc and place a locus on the arc's mid point. All the best, Raymond (vector junkie) PROCEDURE Main; { St. Patrick's Day 2016 - Raymond Mullin } VAR h : HANDLE; StartAng, SweepAng, ArcRadius, MidAng : REAL; P1, P2 : VECTOR; { ARC Start and Stop points respectively } Pcen, Pmid : VECTOR; { ARC Center and Mid points } Vchord : VECTOR; { line between arc endpoints } BEGIN h := FSActLayer; if (h <> nil) do begin { Get arc data } GetSegPt1 (h, P1.x, P1.y); { start point } GetSegPt2 (h, P2.x, P2.y); { stop point } hCenter (h, Pcen.x, Pcen.y); { center point } GetArc (h, StartAng, SweepAng); { These all yield the same radius value, the } { distance between the arc center and a point on the arc } { Norm() always returns a positive value. } ArcRadius := Distance (Pcen.x, Pcen.y, P1.x, P1.y); ArcRadius := Distance (Pcen.x, Pcen.y, P2.x, P2.y); ArcRadius := Norm(P1-Pcen); ArcRadius := Norm(Pcen-P1); ArcRadius := Norm(P2-Pcen); ArcRadius := Norm(Pcen-P2); { Your 1st expression was almost correct } { you needed the mid angle, not just 1/2 the sweep and } { the new vector needed to be added to the arc's center point } Pmid := Pcen + Ang2Vec (StartAng+SweepAng/2, Distance (Pcen.x, Pcen.y, P1.x, P1.y)); { Another way to express it using vector functions } MidAng := StartAng + SweepAng/2; Pmid := Pcen + Ang2Vec (MidAng, ArcRadius); { Another way using only vector functions. } Vchord := P2 - P1; ArcRadius := Norm(P1-Pcen); Pmid := Pcen + UnitVec(Perp(Vchord)) * ArcRadius; { mark the center point of the arc } DSelectAll; Locus(Pmid.x, Pmid.y); end; { if } END; RUN (Main);
  16. I'm not sure where you are trying to set keyboard shortcuts for Classes and Layers dialogs. You might try describing your problem with more details. However, you can access the Navigation Palette with CMD-SHIFT-N, and the Organization Palette with Cmd-SHIFT-O. Both palettes let you access and change Classes and Layers, among other things. If the "Organization..." menu is not in your workspace (It wasn't in any of mine) you can add it manually using the Workspace Editor. I used the "All menus" category to find it. When I added it I didn't assign a hotkey, but after I closed the Workspace Editor it automatically adopted CMD-SHIFT-O for the hotkey. That's new to me. HTH, Raymond
  17. Somewhere along the way Apple messed with the UI and futzed up the Green button again. Between 10.8 (good) and 10.10 (bad). If you hold the Option key down when you click on the Green button you'll get the legacy performance you remember. HTH, Raymond
  18. 16bitColor = 8bitColor * 257 And conversely, 8bitColor = 16bitColor / 257 0 <-> 0 255 <-> 65535 values in between are evenly distributed between the two end values. Raymond
  19. Years ago I grew tired of asking for this, but since it is again brought up, I'll chime in. This wish should extend to ALL Lines, Polygons/Polylines, in addition to Line Styles. Line End Cap, or Linecap, control has been lacking for more that two decades. It would be a HUGE graphical improvement over the current Round Linecap, which was a huge improvement over the original Square Pen. Actually, there should be three options for the Linecap: None, Square, and Round. NONE would terminate a line with a square end, ending exactly at the endpoint of the line. SQUARE would terminate a line with a square end (where side length = line width) that extends past the endpoint by 1/2 the width of the line. ROUND would terminate a line with a circular end (where diameter = line width) that extends past the endpoint by 1/2 the width of the line. (Currently Implemented) Additionally, the Linecap for each end of a line should be able to be set independently. Thanks for posting this. I feel better already. Raymond
  20. { Toggle "Display Screen Objects" when Unified View (Stack-Layers) is ON. } SetPref(95, not GetPref(95)); { Stack-Layers option to create 2D objects } SetPrefInt(506, GetPrefInt(506)); { set Layer Options to same value. Needed for screen redraw. } Here's a shortened version of the same script. Nice find, Marcus. Raymond
  21. Actually, multiply RGB values (0..255) by 257. This will map RGB=255 to 65535 and RGB=0 to 0. The shades in-between will be evenly distributed. For the non-picky person the difference is mostly negligible, but you can probably tell, I am not a non-picky person. HTH, Raymond
  22. Bill, There is definitely a change between VW 2014 and VW 2015. Pref 94 toggles Stacked Layers (Unified View) Pref 95 toggles Display Screen Objects (when Unified View is ON) I tried your script in VW 2014 and saw how it toggles, and it does not toggle the same (or at all) in VW 2015. I'd say it's broken in 2015. I'll submit a bug and reference this thread. If I find a workaround, I'll post back here, but I didn't see anything obvious offhand. Raymond
  23. The name method will work if you only want to associate pairs of objects. You could also attach a record with an ID field to your associated objects. To find associates, search for objects with records having the same ID. This would allow you to associate objects on different layers, which you cannot do with Groups. You can also associate multiple objects this way. You would not need AddAssociation, but you could still use it if you wanted. Raymond
  24. Bill, Try pref# 94 instead of 95. It will work the way you describe, and you won't need the RedrawAll command. Raymond
×
×
  • Create New...