How would I group radio buttons together?

Q:

How would I group radio buttons together? I don’t see sample code for this.

A:

You need to group the actual radio button widget annotation together under a single radio button field.

For example, the Python code below will create two radio buttons, one for Yes, and one for No, and sets the No radio button to be on by default. Calling GetValue on the Field object will give you the currently selected one, or Off if none are.

`
def CreateRadioButtonAppearance(
widget, opt):
widget.SetBorderColor(ColorPt(0,0,0),3)
widget.RefreshAppearance() # create default appearance streams, before copying
if(opt):
app_stream = widget.GetAppearance(Annot.e_normal, “Yes”)
widget.SetAppearance(app_stream, Annot.e_normal, opt)
widget.RemoveAppearance(Annot.e_normal, “Yes”)

def main():
PDFNet.Initialize()
doc = PDFDoc()
blank_page = doc.PageCreate()
citizen = doc.FieldCreate(“citizen”, Field.e_radio, “”, “”)
annot1 = Widget.Create(doc.GetSDFDoc(), Rect(50, 550, 100, 600), citizen)
annot2 = Widget.Create(doc.GetSDFDoc(), Rect(50, 450, 100, 500), citizen)

CreateRadioButtonAppearance(annot1, None) # default is Yes
CreateRadioButtonAppearance(annot2, “No”) # set this to No

citizen.SetValue(“No”) #optional: set default radio button

blank_page.AnnotPushBack(annot1)
blank_page.AnnotPushBack(annot2)

doc.PagePushBack(blank_page)
doc.RefreshFieldAppearances()

doc.Save(output_path + “forms_test.pdf”, 0)
doc.Close()
`