Jump to content

AEChadwick

Member
  • Content Count

    30
  • Joined

  • Last visited

Everything posted by AEChadwick

  1. Hello friends I have long desired an extensible way to add automatic ID numbers to my custom PIOs, and finally took a day to cobble one together. I am submitting it here for perusal, please offer suggestions. (caveat: I know am a hack coder, please don’t be unkind.) (also, i try to name variables knowing that my future self will never remember what “wBpstXX” was ever supposed to mean.) I wanted a system that would simply start from 1 and count up, nominatively to the number of [same objects]. I wanted it to store each number so existing objects would not change their identification--but I wanted the system to fill in available numbers, like if an object got deleted the next object would re-use the available number. This example is built off a rectangle object, purely for demonstration; in addition to LineLength and BoxWidth, the script expects a parameter called __SpecialID of type Text. This is purely to store the ID (the preceding underscore makes the parameter invisible to the user). This script will draw a box and slug the number inside. (the copy-or-new routine is simply the code example from isNewCustomObject) Some nice improvements will be an optional prefix or suffix parameter, allowing things like “W11” or “18xSF" for unique reference; and maybe the ability to add trailing or leading numbers, so “4” automatically becomes “04.” But those can all follow once the basic functionality is foolproof. See what you think. —AE PROCEDURE Plugin; VAR x, y, w, h : REAL; boxLeft, boxBottom, boxRight, boxTop : REAL; pioHandle,rh,wh : HANDLE; result, IsThisCopy, WeGotOne : BOOLEAN; NumberOfPIOs : LONGINT; pioName, thisTypeOfPIO : STRING; MySpecialID, theUniqueID : STRING; theNumber : LONGINT; TheStringWeBeChecking, theStringWeNeed : STRING; PROCEDURE GoThroughEveryPIO(EachPIO : Handle); begin theStringWeNeed := GetRField(EachPIO, thisTypeOfPIO, '__SpecialID'); if theStringWeNeed = TheStringWeBeChecking then WeGotOne := FALSE; end; PROCEDURE GenerateUniqueID; Begin theNumber := 1; repeat WeGotOne := TRUE; TheStringWeBeChecking := Num2Str(0, theNumber); ForEachObject(GoThroughEveryPIO, PON=thisTypeOfPIO); if theNumber = NumberOfPIOs then WeGotOne := TRUE else theNumber := theNumber+1; until WeGotOne = TRUE; theUniqueID := TheStringWeBeChecking; IF IsNewCustomObject(pioName) THEN begin MySpecialID := theUniqueID; SetRField(pioHandle, pioName, '__SpecialID', MySpecialID); SetName(pioHandle, MySpecialID); end; IsThisCopy := MySpecialID <> GetName(pioHandle); IF IsThisCopy THEN begin MySpecialID := theUniqueID; SetRField(pioHandle, pioName, '__SpecialID', MySpecialID); SetName(pioHandle, MySpecialID); end; End; BEGIN result:= GetCustomObjectInfo(pioName,pioHandle,rh,wh); thisTypeOfPIO := (GetObjectVariableString(pioHandle,1166)); NumberOfPIOs := Count(PON=thisTypeOfPIO); MySpecialID := p__SpecialID; GenerateUniqueID; boxLeft:=0; boxBottom:=-(PBOXWIDTH/2); boxRight:=PLINELENGTH; boxTop:=(PBOXWIDTH/2); Rect(boxLeft,boxBottom,boxRight,boxTop); TextOrigin((PLINELENGTH/2),0); TextSize(12); CreateText(Concat(MySpecialID, ' of ', NumberOfPIOs)); END; RUN(Plugin);
  2. oh this is lovely! i’m going to play with it right now. Thank you for posting! —Æ
  3. I have finished a couple tools and I want to save them in a manner that will prevent meddling. Does anyone know a simple method to Lock or Encrypt scripts? I cannot find it in the developer reference. Thanks! ?
  4. oh fer dumb. CHR(39) will insert a single quote. hope this saves some other poor bastard a search. ?
  5. I use a little PIO to display scale inside Viewports that includes this... this currently creates 1" = 4'0" or 1" = 23'10" What snippet of code would change that to 1" = 4' or even 1" = 24' (close enough for estimating cable runs, seriously). *would like to do this without changing the Units... of the document; hoping there is something that will round the numbers and drop the inches. Thanks! ??
  6. Going further, here is my sloppy attempt to remove the trailing 0. I am posting this in the hopes that someone might reveal how to use the actual feet character in a string instead of my silly fado-workaround. take pity on my tortured code...
  7. Hmm. Answering my own question, just coerce it out of Num2Str in a different way: ...that's using a fado as feet because I can't figure out how to get a hatch in there; don?t judge me. Of course, that /12 assumes imperial units (which I generally use, but that seems like sloppy code). I?m open to improvement...
  8. I'm trying to economize code, and figured I had a clever solution... But it does not work, my procedures are lacking?I have not been able to ascertain how to simply "duplicate and mirror" a 2D object. To explain, instead of making two, separate draw door by type routines, I figured "if the door is a double, just draw half and mirror it..." the first part checks if it's a double-version and sets a couple variables: the procedure then draws the appropriate door, then duplicates itself... ...but, of course, this just flips the entire PIO, not the door-half. Am I doing the handles wrong, or missing an obvious command? I sure appreciate the help! PS. other code critique welcome, I?m know I'm a n00b, feel free to school me! ?
  9. Miguel, you're fantastic! I had just finished cobbling two routines as "flipmult" variations (had to get out the Pythagorean Theorem for part...), but I instantly abandoned them and plugged in that DSelectAll. It worked perfectly. I had previously avoided DSelect, thunking it would drop the entire PIO... I should have experimented. Looks like everyone is learning valuable lessons today! Thanks to everyone! I absolutely love posting here, everyone is always smart and helpful [unlike most of the rest of the internet]. ?
  10. "FlipMult" is a great idea! I will attempt an implementation. ?
  11. Man, I can always count on Mr Stanford for the Hard Truth. ?
  12. Hey Mr Assembly! Your version looks great too, thank you for the input! I will explore your code, I love learning all of this and I love having options... In my PIO, a easy-access (read: non-modal) list of simple hatch names is the desired outcome?the hatches are fairly uniform, providing only subtle visual difference; the more important factor is the name, and the handle provided by the hatch. (like, a connected database finds everything called "Wallpaper 1" or "Paint White" and provides square footage.) ?
  13. My PIO includes a pop-up to apply a background hatch. Currently, the selections are hard-coded into the Parameter's "choices" (each hatch, by name, really basic). It would be better to populate the info-palette Pop-Up button with a list of all hatches in the document?a dynamic list that shows available hatches (like, including new hatches as they are added). Has anyone achieved this? can you describe the code, or provide a snippet? My searches have been inconclusive, or maybe so far beyond my modest abilities I can't understand them... the most common result, Parametric Custom Shape Pane, is a little erudite for my interpretation. (if anyone could explain-it-like-I'm-5-years-old, I would be grateful!) ?
  14. Holy smokes, you guys are amazing! (Mr Barrera, Mr Dunning, Mr Benghiat, thank you all so much. I was just about to check in with a lame excuse about "got busy on set, still working on script," but you've beaten me to the punch.) I am going to sit and read every line until I can really parse what's happening, it really is much more complex than I allowed (pardon my youthful naivet?). I hope other folks find this as awesome and helpful as I do; thank you again for all your attention. Now: to work! ?
  15. Just to keep everyone up-to-date as I flail along. (This post live from behind Kitchen Stadium as we load in Series 11.) This script compiles but the pop-up is greyed out, useless! Why doesn?t it fill up? Just stubborn is my guess. I?m going to keep trying to comprehend Events as the kitchen comes together. (Note, if some of the lines are inscrutable, I'll admit, it's because copy-pasta... I just keep trying snippets and bits.) I appreciate all the help, and look forward to any more insights! PS. shout out to Mr Joshua, you've offered excellent advice in several threads.
  16. I have been using VectorWorks for years, but I am a dreadful novice at Vectorscript. Here is my attempt to create a title block that auto-updates using information from its own filename. To explain? I always name files in the same format, with all files for a single show living in their own folder. ie., SHOW FOLDER : SET-EPISODE-Name.vwx So a complete string might be DexterS6 : 862-612-Int Modest House.vwx means "Dexter" Set #862 for Episode 612, "Interior Modest House." Sometimes the names vary slightly, like Torchwood : AMORT-ALL EPISODES-FBI Headquarters.vwx means "Torchwood" Permanent (amortized) Set, "FBI Headquarters." But it's always simply strings separated by hyphens. (ie., the set "numbers" are for reference?they are not part of any calculation, so they're not integers.) My title block is a dead simple line of text?really it?s little more than the most essential information, please see the attached file. Below is my attempt to script the named stamps? Needless to say, my work is little better than pseudocode, and does not compile cleanly! I hope some VectorScript genius can lend a hand! I will credit you & praise you in the final script, which will be handed down into posterity. ??
  17. alright?I need to go get lunch (who spends the 4th of July scripting, anyway?!) Current non-functioning code below. (add a head-on-wall when I figured out "oh, right, Parameter Number...") Submitted for review: ***revised again, update below***
  18. Note sure, but it looks like you are missing a space between HatchNumResources and Do. facepalm. ?
  19. Oh Mr Dunning! You posted while I was formatting the post above, so I totally missed your additional advice! I will go incorporate the additional lessons. Thank you for your guidance and patience! ?
  20. Here is a quick attempt to draw a box and fill it with a dynamically selected hatch. It does not work! I am confident an {Addict} can explain it to me {Greenhorn}. (I swear this is just my programming experiment, you're not doing my homework assignment for me.) ?? ***several dummy mistakes in this, please ignore it, update below***
  21. Hey Mr Dunning! Right ON! That looks deceptively simple; I shall attempt an implementation immediately. {This space reserved for possible subsequent "omg help" messages TBD} ?
  22. An afternoon of digging found a helpful explanation of Events at VectorLab. (Missed this on earlier searches.) Still a chore to relate this to hatch selection, but I am going to win, I swear...
  23. Hello DWorks! Thank you for your assessment! I have implemented both of the "simple" ideas; entering a custom string is fine but problematic, and the hard-coded pop-up choices is very limiting, and a modal dialog box would be intrusive and defeat the intended ease of the tool. (As a certified Lazy Designer I am attempting to make my PIO do as much of the work for me as possible.) The most flexible and desirable solution would be populate the parameter's choices with a list of available hatches. (I can't imagine I'm the only person who has ever wanted a slick dynamic hatch popup...? whoever provides insight/code will be a hero, a hero I tell you!) I am not opposed to the work?I am simply overwhelmed by the obtuseness of the related texts. For example, despite numerous references to "PIO must be event-enabled," I have not actually found a single clear explanation of how to do that; mostly, I just encounter other poor bastards like myself.
  24. Is there a simple way to determine if a number is odd or even? PASCAL math commands include ODD(x), but this appears missing from Vectorscript. I tried ODD anyway, and got this error. [font:Courier New] if ODD(wLights) then [do some stuff based on wLights]; | { Error: Identifier not declared. } | { Error: Expected a string. } | { Error: Expected a Boolean. } | { Error: Did not expect this after end of statement - missing ;? } [/font] (wLights is declared, I think the error is asking about "ODD") Alternately, is there perhaps a way to determine factors? I could simply check if a number is divisible by 2 or 3... I might be missing something obvious, but I have honestly been scouring the language guide and the developer reference. I appreciate any ideas!
  25. AEChadwick

    Is there a simple method to determine Odd/Even Integers?

    Excellent point, Mr Stanford, but I must confess I would not have known to look for MOD regardless of its presence. When I post, it is as much for programming advice as for bibliographic reference?I apologize if that is a misuse of the forum. ?

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×