Author Topic: Checkbox value  (Read 4146 times)

0 Members and 1 Guest are viewing this topic.

tdaniel14

  • Guest
Checkbox value
« on: July 21, 2006, 01:57:45 PM »
I'm trying the Extend Tabs example. How can I tell if a checkbox is checked or unchecked? If the box is checked i want to run this code in autocad, if not I want to run different code. Please remember that I'm not experienced in ARX.  Thanks

Bob Wahr

  • Guest
Re: Checkbox value
« Reply #1 on: July 21, 2006, 02:02:26 PM »
Here's how you would do it in VBA, I'm assuming it's the same but with differing syntax for ARX
Code: [Select]
If CheckBox1.Value = True Then
  Do A
Else
  Do B
End If

uncoolperson

  • King Gator
  • Posts: 4430
  • Doing everything in metric inches!
Re: Checkbox value
« Reply #2 on: July 21, 2006, 02:22:26 PM »
Code: [Select]
If CheckBox1.Value Then
MsgBox ("true")
Else
MsgBox ("not true") 'could be a three state checkbox
End If
when all else fails On Error Resume Next
-----------------------
Livin like I'm on borrowed time
-----------------------
Searching for the Ballmer Peak

Bob Wahr

  • Guest
Re: Checkbox value
« Reply #3 on: July 21, 2006, 02:38:12 PM »
UCP, the checkbox will always have a value so there's no reason for the if, that will always return true.
Code: [Select]
msgbox checkbox1.value

Bob Wahr

  • Guest
Re: Checkbox value
« Reply #4 on: July 21, 2006, 02:43:23 PM »
Mebbe not.  With a three state checkbox, the value is True, False, or Null.  A click setting it to Null won't fire a form click event and will also toss the binky if you do the above.  Well double crap.  Tested what you posted and it works as you said it would.  I take it back.  Triple crap, looking at it and thinking it's obvious, my head is just too far up today.

LE

  • Guest
Re: Checkbox value
« Reply #5 on: July 21, 2006, 02:46:31 PM »
Are you doing an ARX/MFC solution?
Where is your Dialog code?

You need to have your variables as part of the dialog class & and add event handlers to your checkbox controls, you can have the returned values to be saved as static variables or in the registry.

In example inside of the ::OnBnClickedOk() event you can do:

Code: [Select]
CString css;
int value;
value = pBtn_Internal.GetCheck();
int genoptInt, genoptExt;
if(value  == 1) {
        css = "Internal";
genoptInt = 1;
}
else {
        css = "NoInternal";
genoptInt = 0;
}

SetDialogData("GENERATEINT" , css);

value = pBtn_External.GetCheck();
if (value == 1) {
css = "External";
genoptExt = 1;
}
else {
css = "NoExternal";
genoptExt = 0;
}

SetDialogData("GENERATEEXT" , css);

Then simple in the same event you run your function base on the checkbox status:

Code: [Select]
if ( (genoptInt == 1) && (genoptExt == 1))
{
YourFunctionGoesHere();
}



tdaniel14

  • Guest
Re: Checkbox value
« Reply #6 on: July 21, 2006, 03:25:17 PM »
Thanks for the replies!  I'll play with this some this weekend. 

You seem to be experience in ARX!  What would you recommend I do to learn more about ARX.  I don't really know ARX or C++.  I use it for setups and context menu customization.  I'm more of an example/trial and error type person but I haven't been able to find many examples on ARX.  I can't see learning everything about both because  I will not use it everyday.  I used the same approach with VBA and Lisp.  Granted there is a tremendous amount that I don't know but the stuff I'm interested in, I know a lot.

LE

  • Guest
Re: Checkbox value
« Reply #7 on: July 23, 2006, 12:25:47 AM »
No, I do not have that much....

To learn ARX you have to learn the basics of C++ and after that, go to the www.arxdummies.blogspot.com by Fernando Malard

Here are some small tips about MFC, about this there are a lot of stuff on the web...

Follow this steps:

1. Go to the resource section and open the IDD_TAB2
2. Add a new CheckBox control
3. Right click on the control and add a new event - BN_CLICKED
4. In the CTab2::OnInitDialog() add the following code:

Code: [Select]
BOOL CTab2::OnInitDialog()
{
CAcUiTabChildDialog::OnInitDialog();

// the new code starts here
CButton* m_variableOne = (CButton*) GetDlgItem(IDC_CHECK1);
CString css;
if(GetDialogData("CHECKBOXVAL1" , css) && css == "Value1")
m_variableOne->SetCheck(1);
else
m_variableOne->SetCheck(0);
// and ends the new code here

return TRUE;  // return TRUE unless you set the focus to a control
              // EXCEPTION: OCX Property Pages should return FALSE
}

5. In the function CTab2::OnBnClickedCheck1() do the following:

Code: [Select]
void CTab2::OnBnClickedCheck1()
{
// TODO: Add your control notification handler code here
CButton* m_variableOne = (CButton*) GetDlgItem(IDC_CHECK1);
int value = m_variableOne->GetCheck();
CString css;
if (value == 1)
css = "Value1";
else
css = "Value0";
SetDialogData("CHECKBOXVAL1" , css);
}

Now "Build" the ExtendTabs C++ solution, load the ARX in any drawing, call the command EXTENDTABS, then OPTIONS command, select the TAB2, click on the added checkbox control, click out of the OPTIONS command, and call it again, and now you have the ON and OFF status for the checkbox.

All of the above is one way as can be other alternatives on how to do it...

HTH.

tdaniel14

  • Guest
Re: Checkbox value
« Reply #8 on: July 24, 2006, 11:35:59 AM »
LE, Thanks so much for your help.  That is exactly what I wanted!  I have already checked out that link.  I am looking at about.com's C++ tutorials for beginners.  Hopefully this will shed some light on the subject for me.  If you know of anything better than the above on learning C++, please let me know.  Once again, thanks for your help.

tdaniel14

  • Guest
Re: Checkbox value
« Reply #9 on: July 25, 2006, 08:58:53 AM »
LE, that code worked great!  Is it possible to store the checkbox values so that when autocad is restarted it remembers whether the checkbox was checked or not?

LE

  • Guest
Re: Checkbox value
« Reply #10 on: July 25, 2006, 09:47:21 PM »
Sorry do not have time to play with this right now... This issue is more about MFC not ObjectARX, I think there are very good tutorials in www.functionx.com

HTH
« Last Edit: July 25, 2006, 09:49:30 PM by LE »

MickD

  • Gator
  • Posts: 3289
  • (x-in)->[process]->(y-out)
Re: Checkbox value
« Reply #11 on: July 25, 2006, 09:54:48 PM »
You could store this and other dialog set up variables in the registry or an 'ini' or xml file to manage the settings you want to be persistent over different sessions. I have to implement something like this myself soon and I'll probably use xml to store standard layer settings along with dialog settings etc.
Debugging:
Being the detective in a crime movie where you're also the murderer.

“Someone's sitting in the shade today because someone planted a tree a long time ago.”
- Warren Buffet