MaxStudio Posted November 17, 2008 Share Posted November 17, 2008 I have written a script which asks a user to enter some real numbers to create an object. The user will use the script multiple times during a drawing. Lets say the user is going to create a door in a wall. The script has the default for the wall set at 4.5". The problem is the walls of the house are 5.5". Everytime the user runs the script they have to change the 4.5" to 5.5" My question. Is there a way I can script the default variable so it remembers the 'real number' that was used the last time the script was run? So the first time the user runs the script they will change the wall thickness from 4.5" to 5.5". The second time the script is run it remembers that the walls are 5.5". So the new default setting for the wall is 5.5". I hope thats clear. thanks Quote Link to comment
ccroft Posted November 18, 2008 Share Posted November 18, 2008 Assuming a menu command, you create parameters in script editor. Then use SetRField and GetRField to read and write to the parameter record. You get a handle to the parameter record by calling GetPluginInfo(menuName,hRec). It's a storage area that remains in the document. It's in VectorScript language guide in Help...somewhere. Hope that helps, Charles Quote Link to comment
Miguel Barrera Posted November 19, 2008 Share Posted November 19, 2008 Assuming also that you have to click where the door is going to be placed, you can get a handle to the wall that was clicked and then get its width. You can then change your variable on the fly without needing input from the user. If the objective of the script is to create doors, would it not be better handled as a plugin? you can get a handle to the wall from FUNCTION GetCustomObjectInfo(VAR objectName :STRING; VAR objectHand, recordHand, wallHand :HANDLE) :BOOLEAN; Quote Link to comment
MaxStudio Posted December 2, 2008 Author Share Posted December 2, 2008 Hey folks thanks a lot. I haven't been able to get to this yet but I will definitely look into your advice in the future. Miguel, my scripts are for 2D drawing exclusively (our office draws mostly in 2D). Is there an advantage to creating a Plugin? I've never created one. Do you know of any good and simple examples I could take a look at? or tutorials? Quote Link to comment
Miguel Barrera Posted December 2, 2008 Share Posted December 2, 2008 Plugins can be 2D only and examples of that are notation objects such as north arrow, id labels, callout text, etc. The user can change the look of the object by selecting options and entering values in the object info palette. Example scripts can be found in the Vectorscript examples page Quote Link to comment
MaxStudio Posted December 2, 2008 Author Share Posted December 2, 2008 thats great! I can't seem to install the plugin examples though. I normally create a script pallete, create a new script, paste my script, then compile. How do I go about installing the plugin? and then how do I run it? Quote Link to comment
Miguel Barrera Posted December 2, 2008 Share Posted December 2, 2008 And to answer your original question about default values, you can try Charles suggestion although, I have tried that before and could only get the values but not modify them. Since I have not tried this again since VW11, it may work now in VW 2008. If that does not work, my advise would be to create text files that hold the information. Such default text files usually have the "*.ini" extension in many programs and more recently, ".xml" files are used for defaults and preferences as well. Quote Link to comment
Miguel Barrera Posted December 2, 2008 Share Posted December 2, 2008 Plugins first have to be copied to the VW Plug-Ins folder. You would need to restart VW if currently running so that it can read the installed plugins. You then add the plugin to your workspace which should be listed in the tools pane. You can create a new tool palette with the examples or add them to an existing palette. To access the code, you need to click on the Tools>Scripts>Vectorscript Plug-in Editor submenu. You will then get a list of all plugins installed including NNA's which you will notice are locked. Scroll down to the one just installed and you will be able to access the script, parameters, etc. If you have not done so, there is a plugins section in the VW help that you can use as a reference. Quote Link to comment
Pat Stanford Posted December 2, 2008 Share Posted December 2, 2008 thats great! I can't seem to install the plugin examples though. I normally create a script pallete, create a new script, paste my script, then compile. How do I go about installing the plugin? and then how do I run it? Plug-ins are a special type of Vectorscript. Rather than use the regular VS Editor, you use the Vectorscript Plug-In Editor available from the Tools:Scripts menu. If you create a Command PIO, you will get a command that can be added to any workspace. To do this, copy and the script from your Script Editor. Go the the PIO editor and create a new command. Click the Script button at the bottom of the window and then paste the text into the window. Your command will be saved in your Users data folder User:Library:Application Support:Vectorworks:2009:Plug-ins When you create a PIO Point or Line object, you will get Parameters. These are values that show up in the Object Info Palette but that you can use as variables in your script. You can also add additional parameters by clicking the Parameters button. This is very rough, but hopefully will give you some idea of how to get started. Pat Quote Link to comment
ccroft Posted December 3, 2008 Share Posted December 3, 2008 Hi Folks, What I alluded to only works with menu command plug-ins, and it worked for me in 11 and 2009. It's the same as reading and writing to any record. After re-visiting this post though, I think that a menu command might not be the best choice for a script to draw something. In that case command parameter records are useless. For a pallette script, I suppose you could (thru script) attach a record to the object being produced, and read and write the values from the dialog to that. Not sure how you manipulate defaults with an Object tho... Later Charles 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.