CoCreate User Forum  

Go Back   CoCreate User Forum > Support > Customization

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 09-03-2008, 01:58 PM
Dave Nowak Dave Nowak is offline
Registered User
 
Join Date: Apr 2008
Location: Stoughton, Wisconsin USA
Posts: 20
Change dimension value via dialog

I want to add a command to Annotation that will change the size, color and main value of a highlighted (currently selected) dimension. We use charted drawings and I want a dialog to come up and prompt the user for an alpha character (e.g. "A") that will be the main value for the dimension.


I can get the currently selected dimension (the one that is highlighted) by using this code

PHP Code:
(setf temp_val (car (get-matching-preselected-objects))) 
and this is my dialog

PHP Code:
(oli:sd-defdialog 'sto_charted_dim
:dialog-title "Charted Dimension"
:toolbox-button nil
:variables
'
((sto_dim_value
:value-type :string
:title "Charted Dim"
:initial-value nil
)
)
:
ok-action
'(am_dim_props
temp_val
:main_value (format nil "~:@(\"~a\"~)" sto_dim_value) ;"\"S\""
:text_abs_size 0.1
:text_color white
:done cancel)

They both work, but they work separately, I can highlight a dimension and set the temp_val with setf and then at the command line type sto_charted_dim and the dialog appears and I’m able to supply a alpha character and the dimension changes (size, color and main value).

But…..
I can not seem to put the two together, such as in a lisp file.


Such as this in a lisp file that I load.

PHP Code:
(setf temp_val (car (get-matching-preselected-objects)))
sto_charted_dim 
this gives an error "Charted Dim is not specified"


I tried the precondition parameter in the dialog e.g.

PHP Code:
:precondition 
'(progn
(setf temp_val (car (get-matching-preselected-objects)))
:ok

but the selected dimension does not seem to be available for the setf

Perhaps there are other methods to get user feed back, such as the read command in Me10.

Thanks for any suggestions.

Dave Nowak
Reply With Quote
  #2  
Old 09-04-2008, 01:14 PM
Wolfgang's Avatar
Wolfgang Wolfgang is offline
Registered User
 
Join Date: Nov 2002
Location: ... near Sindelfingen near Stuttgart, Germany
Posts: 754
Re: Change dimension value via dialog

I did not try, but it should work similar to this:
PHP Code:
(oli:sd-defdialog 'sto_charted_dim
  :variables
   '
(sto_dim       :selection *sd-anno-dimension-seltype*
                   :
toggle-type :invisible
                   
)
    (
sto_dim_value :value-type :string
                   
:title "Charted Dim"
                   
:initial-value nil
                   
)
     ) ;; 
end variables
  
:ok-action
   
'(am_dim_props
      sto_dim    ;; instead of temp_val
      :main_value ...... 
the dialog var sto_dim, will catch the preselected dimension. The method is: the first unsatisfied variable with a value-type / select focus matching the preselected element will get this element(s). It's important that a selection is required. In your original code the dialog expected a string, but not a selection. Therefore the function you figured out did not return anything any more (when called within the dialog).

With the code above you don't need the (setf temp_val ..) at all. For test/Debug purpose, make the sto_dim variable visible again or/and do a print in its :after-input.
Reply With Quote
  #3  
Old 09-05-2008, 08:14 AM
Dave Nowak Dave Nowak is offline
Registered User
 
Join Date: Apr 2008
Location: Stoughton, Wisconsin USA
Posts: 20
Re: Change dimension value via dialog

Thanks for the reply Wolfgang


Your code does work. I’m having problems posting a reply on this forum; don’t know why but as soon as I can I’ll give more details.
Thanks

Dave Nowak
Reply With Quote
  #4  
Old 09-10-2008, 09:44 AM
Dave Nowak Dave Nowak is offline
Registered User
 
Join Date: Apr 2008
Location: Stoughton, Wisconsin USA
Posts: 20
Re: Change dimension value via dialog

I'm back

So..

Wolfgang,
your code does work, if I first select a dimension and then select Sto_charted_dim from the toolbox area.

This is good, now I’ve made a slight change to the dialog, here is the code

PHP Code:
;**************** Change dim to alpha
(oli:sd-defdialog 'sto_charted_dim
  :dialog-title "Charted Dimension"
  :toolbox-button nil
  :variables
 '
((sto_dim_selected :selection oli:*sd-anno-dimension-seltype
    :
toggle-type :invisible
    

    (
sto_dim_value
      
:value-type :string
      
:title "Charted Dim"
      
:initial-value nil
    
)
  )
  :
ok-action
    
'(am_dim_props
    sto_dim_selected
    :main_value (format nil "~:@(\"~a\"~)" sto_dim_value)
    :text_abs_size 0.1
    :text_color white
    :done cancel)

and added functionality to the Preselection Dimension (Annotation) popup by adding a new button e.g. "Change Dim to Alpha" (see screen01),
the code for Change Dim to Alpha button is

PHP Code:
sto_charted_dim 
So now the user can have the right mouse button functionality when a dimension is highlighted. We will probably use the same technique with other objects in Modeling and Annotation.

You supplied the crucial piece of code (getting the highlighted dimension), and thanks for the explanation supplied with your code.

Thanks again

Dave Nowak
Attached Thumbnails
Click image for larger version

Name:	screen01.PNG
Views:	292
Size:	9.0 KB
ID:	1341  
Reply With Quote
  #5  
Old 09-10-2008, 10:24 AM
Wolfgang's Avatar
Wolfgang Wolfgang is offline
Registered User
 
Join Date: Nov 2002
Location: ... near Sindelfingen near Stuttgart, Germany
Posts: 754
Smile Re: Change dimension value via dialog

Hi Dave,

thanks for your feedback! :-)

2 points:

If you would have written a straight forward dialog, **with** select dimension, the string for the charted value and the ok action, the pre selection would have worked immediately. But the magic function name get-matching-preselected-objects you have found in a recorder file I guess pushed you to the wrong direction. So your curiousness got punished

keep in mind: a have normal selection in dialog (so you can use it interactively as usual) and the preselection method will try to do it's best by filling this variable if possible. YOU don't have to take care on pre selection itself.

Making the select variable invisible is just cosmetic for UI.

your :Ok-action
a) wrap a sd-call-cmds arround (I forgot it)
b) the cancel at the end.. remove it! (funny that it doesn't hurt)
Reply With Quote
  #6  
Old 09-10-2008, 12:33 PM
Andy Poulsen Andy Poulsen is offline
Administrator
 
Join Date: Apr 2003
Location: Fort Collins, Colorado
Posts: 273
Re: Change dimension value via dialog

Hi Dave,

Here's yet another version that might help you:
PHP Code:
(in-package :mypackage)
(use-
package :oli)

;**************** 
Change dim to alpha
(sd-defdialog 'sto_charted_dim
  :dialog-title "Charted Dimension"
  :toolbox-button nil
  :variables
  '
((sto_dim_selected :selection *sd-anno-dimension-seltype
                      :
title "Dimension"
                      
:next-variable :sto_dim_value
                      
)
    (
sto_dim_value :value-type :string
                   
:title "Charted Dim"
                   
:initial-value nil
                   
)
    (
"-")  ;; spacer in the dialog layout
    
(Next  :push-action (chart-dim)
           :
next-variable :sto_dim_selected)
    ) ;; 
end of variable definitions
  
:local-functions
  
'((chart-dim ()
      (sd-call-cmds (am_dim_props
                     sto_dim_selected
                     :main_value (format nil "~:@(\"~a\"~)" sto_dim_value)
                     :text_abs_size 0.1
                     :text_color 16777215 ; white
                     )))
    ) ;; end of local function definitions
  :ok-action '
(chart-dim)
  ) 
A couple of comments on what's different here:
1) I'm sure you're already doing this, but it's always a good idea to put your customizations in their own lisp package (helps to prevent unexpected errors!) -- that's what (:in-package :mypackage) line does, and (:use-package :oli) tells the lisp reader that you may be using exported functions from the :oli package (such as sd-defdialog, etc).
2) As Wolfgang mentioned, making the field for the selected dimension invisible is just cosmetic, and making it just a normal selection variable as above will allow it to work with any preselection, if applicable. Also, if you make it visible, you can then process multiple dimensions one after another (using the "Next" button that is in the code above). This was easily done by moving the ok-action code (wrapped in sd-call-cmds, as Wolfgang suggested) into a separate function that can be called either by the ok-action or by pressing the "Next" button. Also note the use of the :next-variable that tells the dialog which variable to make active after the currect selection or action is complete.

I hope this helps! Please post back if you have any further questions.

Good luck!

andy
__________________
Andy Poulsen
AI MAXTools: Dream. Design. Done. It's that easy!
Add-ins bringing new functionality and speed to Creo Elements/Direct and CoCreate products. Now available for v17-v20+!
See them in action at www.ai-maxtools.com and then try them for yourself -- FREE!
Reply With Quote
  #7  
Old 09-11-2008, 06:50 AM
Dave Nowak Dave Nowak is offline
Registered User
 
Join Date: Apr 2008
Location: Stoughton, Wisconsin USA
Posts: 20
Re: Change dimension value via dialog

Thanks to both of you

A few comments
If I wrap the OK in the sd-call-cmds then I do need to remove the cancel at the end, Wolfgang your suspicion was right.

The color white, Andy you put a number instead, which I guess is the same as white (whether a RGB value or a Hue-Saturation-Luminosity value); is this the preferred method to indicate color ?

Lastly, an odd thing; wrapping the OK in the sd-call-cmds makes the size (text_abs_size) of the dimension very small 0.003937 We use inches as our unit of measure, I suspect that there is a conversion issue. If I make the size of the dimension (text_abs_size) 2.54 instead of 0.1 then the Abs Size of the dimension ends up being 0.1 which is what I want. This is alright as long as I know what’s happening


Dave Nowak
Reply With Quote
  #8  
Old 09-11-2008, 07:25 AM
Andy Poulsen Andy Poulsen is offline
Administrator
 
Join Date: Apr 2003
Location: Fort Collins, Colorado
Posts: 273
Re: Change dimension value via dialog

Quote:
Originally Posted by Dave Nowak View Post
The color white, Andy you put a number instead, which I guess is the same as white (whether a RGB value or a Hue-Saturation-Luminosity value); is this the preferred method to indicate color ?
Good question. In this case, white is defined as a constant with the number value shown (the number comes from the RGB components of the color -- in this case the hex value #FFFFFF, which is FF (maximum value) for each of Red, Green, and Blue). This can be useful in the event that for some reason the constant doesn't get evaluated properly, using the number will always work. Using a number will also allow you to use other color variations if you so desire...
Quote:
Originally Posted by Dave Nowak View Post
Lastly, an odd thing; wrapping the OK in the sd-call-cmds makes the size (text_abs_size) of the dimension very small 0.003937 We use inches as our unit of measure, I suspect that there is a conversion issue. If I make the size of the dimension (text_abs_size) 2.54 instead of 0.1 then the Abs Size of the dimension ends up being 0.1 which is what I want. This is alright as long as I know what’s happening
Yes, you've discovered one of the pitfalls (and benefits!) of the way Modeling handles units. Internally, Modeling keeps track of all lengths in millimeters. This can cause some confusion at first (as you noticed), but is actually very nice once you understand it since everything is internally consistent. There are a couple of functions to help with converting values -- sd-sys-to-user-units and sd-user-to-sys-units (and they work with different types of conversion, which is very nice). In this case, instead of hardcoding the value 2.54 (which is a trivial case), you could use (sd-user-to-sys-units :length .1).

One other note: in your :variables section, if you create a variable of type :length, it will automatically convert the values for you, allowing you to type in the value in whatever units you are using. In this particular case, it's not likely to be worth the trouble, but for future use, you might find it to be very useful.

I hope this helps -- if there's anything that's not clear, just ask!

andy
__________________
Andy Poulsen
AI MAXTools: Dream. Design. Done. It's that easy!
Add-ins bringing new functionality and speed to Creo Elements/Direct and CoCreate products. Now available for v17-v20+!
See them in action at www.ai-maxtools.com and then try them for yourself -- FREE!
Reply With Quote
  #9  
Old 09-11-2008, 10:07 AM
Wolfgang's Avatar
Wolfgang Wolfgang is offline
Registered User
 
Join Date: Nov 2002
Location: ... near Sindelfingen near Stuttgart, Germany
Posts: 754
Re: Change dimension value via dialog

Hi Andy,

nice code. Fine.


Quote:
Originally Posted by Andy Poulsen View Post
.....In this case, instead of hardcoding the value 2.54 (which is a trivial case), you could use (sd-user-to-sys-units :length .1).
Uhh.. don't do so. What will happen when the USER is NOW changing the units to um, or mils ??? You will get funny results! -->> when ever coding use :MM units for length values. So highly recommended is using 2.54 (mm) in this case !! Be aware that sd-user-to-sys-units is executed at RUN time. So it will use the *current* user units.

[ detailed user guidance ]
But another issue on your code with the local-function. What will happen now if user opens the dialog (via icon on toolbar, via toolbox, via command line) and simply press APPLY? We will get a lisp error now!

What will happen when just entering the string and pressing apply. -> LISP error.

a) disable the apply on dialog open
b) enable apply button ONLY if dim and string are defined.
or
c) a little bit easier:
wrap arround the sd-call-cmd with a when
PHP Code:
  :local-functions
  
'((chart-dim ()
     (when (and sto_dim_selected sto_dim_value)
      (sd-call-cmds (am_dim_props
                     sto_dim_selected
                     :main_value (format nil "~:@(\"~a\"~)" sto_dim_value)
                     :text_abs_size 0.1
                     :text_color 16777215 ; white
                     ))))
    ) ;; end of local function definitions 
that way pressing 'apply' too early would not hurt: just nothing happens.

Well these are the trivia making the dialog/user interface more safe and the code bigger.
Reply With Quote
  #10  
Old 09-11-2008, 10:12 AM
Wolfgang's Avatar
Wolfgang Wolfgang is offline
Registered User
 
Join Date: Nov 2002
Location: ... near Sindelfingen near Stuttgart, Germany
Posts: 754
Lightbulb Re: Change dimension value via dialog

PHP Code:
(format nil "~:@(\"~a\"~)" sto_dim_value
use
PHP Code:
(format nil "~:@(~S~)" sto_dim_value
instead. That's easier to read and you don't have to puzzle with back slashes
Reply With Quote
  #11  
Old 09-11-2008, 10:24 AM
Andy Poulsen Andy Poulsen is offline
Administrator
 
Join Date: Apr 2003
Location: Fort Collins, Colorado
Posts: 273
Re: Change dimension value via dialog

Quote:
Originally Posted by Wolfgang View Post
[ commenting on using (sd-user-to-sys-units with a fixed value) ]
Uhh.. don't do so. What will happen when the USER is NOW changing the units to um, or mils ??? You will get funny results! -->> when ever coding use :MM units for length values. So highly recommended is using 2.54 (mm) in this case !! Be aware that sd-user-to-sys-units is executed at RUN time. So it will use the *current* user units.
you're absolutely right, of course -- what I was meaning to emphasize was just how to use the sd-user-to-sys-units, not that it should be used in that specific case -- it's definitely not generally useful (or predictable!) to use that function with a fixed value! (but I certainly did not explain it clearly!)
Quote:
Originally Posted by Wolfgang View Post
[ detailed user guidance ]
But another issue on your code with the local-function. What will happen now if user opens the dialog (via icon on toolbar, via toolbox, via command line) and simply press APPLY? We will get a lisp error now!

[ removed code showing how to use (when ....) to ensure all variables are defined before proceeding ]
Again, good point (and good practice as well) -- no one likes to see the lisp errors! Again, just a very quick, simple example that I should have tidied up before posting it... )

andy
__________________
Andy Poulsen
AI MAXTools: Dream. Design. Done. It's that easy!
Add-ins bringing new functionality and speed to Creo Elements/Direct and CoCreate products. Now available for v17-v20+!
See them in action at www.ai-maxtools.com and then try them for yourself -- FREE!
Reply With Quote
  #12  
Old 09-11-2008, 10:35 AM
Wolfgang's Avatar
Wolfgang Wolfgang is offline
Registered User
 
Join Date: Nov 2002
Location: ... near Sindelfingen near Stuttgart, Germany
Posts: 754
Smile Re: Change dimension value via dialog

Quote:
Originally Posted by Andy Poulsen View Post
... no one likes to see the lisp errors! Again, just a very quick, simple example that I should have tidied up before posting it... )
No, no it's okay as we're doing. I like that thread! It's a little bit like a training, titled:

"My Third LISP"

It's a good example for LISP learners IMHO. Doing one step after the other, learning one thing after the previous.
Reply With Quote
  #13  
Old 09-11-2008, 10:56 AM
Andy Poulsen Andy Poulsen is offline
Administrator
 
Join Date: Apr 2003
Location: Fort Collins, Colorado
Posts: 273
Re: Change dimension value via dialog

Quote:
Originally Posted by Wolfgang View Post
No, no it's okay as we're doing. I like that thread! It's a little bit like a training, titled:

"My Third LISP"

It's a good example for LISP learners IMHO. Doing one step after the other, learning one thing after the previous.

Indeed! Since we're in the training mode, one other thing that is probably worth pointing out is that the code shown wouldn't actually generate a lisp error when the OK button is pressed -- rather it would not even get to the ok-action since the two variables are both required. Instead, an error message that one or both of the variables is not specified will be displayed (thanks to the nice error checking of the dialog generator).

However, clicking the Next button has no such safety net, and will definitely cause unexpected results (in this case, it doesn't actually cause a lisp error either since the error happens in the call to am_dim_props, which appears to have some built-in error checking rather than just throwing an error). So you're *definitely* better off being safe and wrapping the (when ...) around your execution function as Wolfgang described. Alternatively, the execution function could be left as-is, and you could provide the safety in the push-action of the next button as follows:
PHP Code:
(Next    :push-action (when (and sto_dim_selected sto_dim_value)
                        (
chart-dim))) 
or perhaps
PHP Code:
(Next    :push-action (if (and sto_dim_selected sto_dim_value)
                           (
chart-dim)
                       (
sd-display-message 
                           
"Please enter data for all required fields"))) 
(are we getting too crazy with all of this???? )

andy
__________________
Andy Poulsen
AI MAXTools: Dream. Design. Done. It's that easy!
Add-ins bringing new functionality and speed to Creo Elements/Direct and CoCreate products. Now available for v17-v20+!
See them in action at www.ai-maxtools.com and then try them for yourself -- FREE!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 02:58 PM.



Hosted by SureServer    Forums   Modeling FAQ   Macro Site   Vendor/Contractors   Software Resellers   CoCreate   Gallery   Home   Board Members   Regional User Groups  By-Laws  

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.