phuckel Posted November 10, 2022 Share Posted November 10, 2022 Hello, I have just started using Vectorscript and I would like to create a Dialog Box to enter a specific length (:real that is positive to go in 1 direction or negative go in the other direction) and the number of duplicates (:integer) so that only the selected 2D or 3D object (eg. fence picket) is duplicated with identical spacing between each duplicate within the specific length (eg. pickets along a fence line). I would sincerely appreciate any help in completing this script - thank you. eg. Procedure Duplicate_By_Length; Var Num: Integer; {No. of duplicates} dLength: Real; (Set overall distance for all duplicates to span} dOffset: Real; {Offset from previous duplicate} Height1, Width1, Depth1: Real {Dimensions for selected object in 2D or 3D so assume Width1 is the width that will alter the offset} Begin "Show Dialog box to ask for Number of Duplicates and the Overall Length that store the values in Num and dLength" {I do not know how to do this} For Duplicates: 1 to Num DO BEGIN "Create Duplicate" {I do not know how to do this} dOffset:= dLength/((Num - 1)*Width1); "Create Duplicate at the specified offset (dOffset) from the previous duplicate" {I do not know how to do this} END End Run(Duplicate_By_Length); Thank you to anyone who can provide the necessary scripting commands to complete this script. Quote Link to comment
michaelk Posted November 10, 2022 Share Posted November 10, 2022 Try this. I put in the super simple dialog calls. You can do more complicated dialogs, but it requires many more lines :-). I'm sure you will have more questions. Post back! PROCEDURE Duplicate_By_Length; VAR Num,i : Integer; {No. of duplicates} dLength : Real; {Set overall distance for all duplicates to span} dOffset : Real; {Offset from previous duplicate} Height1, Width1, Depth1 : Real; {Dimensions for selected object in 2D or 3D so assume Width1 is the width that will alter the offset} h,hh : HANDLE; Begin h := FSActLayer; Num := IntDialog('How many of these things would you like?','2'); {"Show Dialog box to ask for Number of Duplicates and the Overall Length that store the values in Num and dLength" I do not know how to do this} dLength := DistDialog('What''''s the total distance?','10'); FOR i:= 1 to Num DO BEGIN; {I do not know how to do this} { dOffset:= dLength/((Num - 1)*Width1); } hh := HDuplicate(h,dlength/(Num)*i,0); { "Create Duplicate at the specified offset (dOffset) from the previous duplicate" } {I do not know how to do this} END; End; Run(Duplicate_By_Length); 1 Quote Link to comment
phuckel Posted November 10, 2022 Author Share Posted November 10, 2022 (edited) Thank you very much MichaelK for your script - I sincerely appreciate how quickly you created it. It was almost perfect - The width of the last duplicate exceeded the overall length by its width so I used HWidth(h) in the calculation of the offset distance to make it work perfectly. eg. hh := HDuplicate(h,(dlength - HWidth(h))/(Num)*I,0); Thank you again for providing the script so quickly - you're a wiz! Edited November 10, 2022 by phuckel I found a solution to make the script work 100% Quote Link to comment
michaelk Posted November 10, 2022 Share Posted November 10, 2022 Take a look at GetBBox With the variables h : Handle; p1X, p1Y, p2X, p2Y : Real; The function GetBBox(h,p1X, p1Y, p2X, p2Y); will set the values for the Real variables. p2X-p1X should be the width of your object. If you've been trying to find VS functions at the developer website: https://developer.vectorworks.net/index.php/Main_Page then I recommend you try using the local version. You will find it in the applications folder: /Applications/Vectorworks 2023/VWHelp/Script Reference/ScriptFunctionReference.html You can open it in your browser. It's organized better (or at least differently) than the online version. 1 Quote Link to comment
michaelk Posted November 10, 2022 Share Posted November 10, 2022 I probably should have mentioned that I added two variables to your script - h, hh : HANDLE; A handle variable is a way of referring to objects in VW. (or classes or layers or resources - but let's stick with objects for now.) h := FSActLayer; is a line you will type over and over. It means the variable h is the First Selected object on the Active Layer. Every time you think, "I wonder if this is possible" you will start with that line :-). If nothing is selected then h is NIL and the script does little or nothing. 2 Quote Link to comment
phuckel Posted November 10, 2022 Author Share Posted November 10, 2022 Thank you MichaelK - I understood the operation of the handles and the need to use FSActLayer command to manipulate the selected objects. After I added the HWidth(h) command inside the Offset calculation, everything worked perfectly with any 2D or 3D shape so I will not need to use the GetBBox command but thank you for suggesting it. One day I may even learn to create a more-complex dialog box that allow multiple entries (no. of duplicates, horizontal offset and vertical offset). Thanks again for all of your advice and suggestions - I truly appreciate them. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.