Sam Jones Posted March 10, 2022 Share Posted March 10, 2022 I want to get a handle to the command that is running within the command's code, so that I can store date in the parameters of the command with GetRField(commandHandle, commandName, parmeterName); SetRField(commandHandle, commandName, parmeterName, newValue); I am trying to get the handle with these lines in the commands code: PIORecName := 'AP Make Jumper Cable Chain'; PIORecHdl := GetObject(PIORecName); PIORecHdl always returns NIL. Why is this happening, and what method should I use to get the handle of the currently running command? TIA, Sam PIORecName is the name of the running command Quote Link to comment
JBenghiat Posted March 10, 2022 Share Posted March 10, 2022 At one point I found the menu command or tool's parameters unreliable for storing data, so I've looked to other methods. It might not even still be supported. Options are: Set/GetSavedSetting() if you want the date to persist between sessions. The Rpstr_ commands for sorting temporary data (it persists per session, so you can pass between commands or runs of a command) Create a hidden record for storing data to the file. You would want custom get/set commands that create the record if it doesn't exist. Quote Link to comment
Sam Jones Posted March 10, 2022 Author Share Posted March 10, 2022 I suspected this. I've been punting to Set/GetSavedSetting() and Rpstr commands, but I had a little time and wanted to nail down the status of using command parameters. Thx Quote Link to comment
Vectorworks, Inc Employee klinzey Posted March 10, 2022 Vectorworks, Inc Employee Share Posted March 10, 2022 It should work, or at least it used to. (I haven't tested this in a long time.) When you create the command in the plug-in manager you should add the parameter fields you need. If the command name is "AP Make Jumper Cable Chain" then PIORecName := 'AP Make Jumper Cable Chain'; PIORecHdl := GetObject(PIORecName); Should work. Even if PIORecHdl returns NILL using NILL should work and access the default record since only one can exist in the document. GetRField(NILL, PIORecName, parmeterName); SetRField(NILL, PIORecName, parmeterName, newValue); The better way to do it is to use Set/GetSavedSetting() if you want to settings to apply across documents, especially because the user can reset them, and Rpstr if you want them to apply to just the document. Quote Link to comment
Sam Jones Posted March 11, 2022 Author Share Posted March 11, 2022 1 hour ago, klinzey said: When you create the command in the plug-in manager you should add the parameter fields you need. If the command name is "AP Make Jumper Cable Chain" then PIORecName := 'AP Make Jumper Cable Chain'; PIORecHdl := GetObject(PIORecName); Should work. Unfortunately, it doesn't. Sometimes, with some commands, it does. Using the NIL handle returns bad handle error. 1 hour ago, klinzey said: The better way to do it is to use Set/GetSavedSetting() if you want to settings to apply across documents, especially because the user can reset them, and Rpstr if you want them to apply to just the document. I know how to do this. I do it often. I have gotten into the habit of making the subroutines to do all this when I create the SetupDialogC case statement of any dialog that might want set and retrieve defaults. I am somewhat unreasonably gunshy on piling on the XML file that holds these settings. Thanks Kevin and Josh in confirming what I suspected. As an aside, Kevin, are the bad handle errors ignorable? 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.