Jump to content
Developer Wiki and Function Reference Links ×

How to get handle to command


Recommended Posts

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

Link to comment

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.

Link to comment
  • Vectorworks, Inc Employee

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.

Link to comment
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?

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...