CoCreate User Forum  

Go Back   CoCreate User Forum > Support > Customization

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 12-21-2005, 12:31 AM
VINIT VINIT is offline
Registered User
 
Join Date: Nov 2005
Posts: 35
Program does not work if units are changed

Dear Claus,

As mention earlier, I have developed a program that draws a circle tangent to two edges. The program dimensions the circle location from selected reference bases.

My problem is, the program works perfectly when units are in mm. But if units are changed to inches, the program does not work. What may be the reason, I am totally blank about it. Can you really tell me where the problem lies?

I will post the code if you want to really have a look at it

Awaiting for your response at earliest.

Regards,
Vinit
Reply With Quote
  #2  
Old 12-21-2005, 03:53 AM
clausb's Avatar
clausb clausb is offline
Registered User
 
Join Date: Nov 2002
Posts: 1,168
Re: Program does not work if units are changed

The most common cause for unit handling problems is the ill-advised attempt to explicitly handle units in user code. This is usually not necessary at all - the user units conversion is a display-only issue, and all internal calculations are assumed to be in standard units (i.e. mm, grams, rad). And usually, the solution is to stop trying to convert units in your own code and rather have OSDM handle it.

Without sample code, that's probably all I can say at this point.

Claus
__________________
CoCreate Modeling FAQ: http://www.clausbrod.de/CoCreateModeling/
Reply With Quote
  #3  
Old 12-21-2005, 07:24 PM
VINIT VINIT is offline
Registered User
 
Join Date: Nov 2005
Posts: 35
Re: Program does not work if units are changed

Dear Claus,

I do agree with your suggestion but here's more to explain.

If a line is drawn 10 units long (let's assume no units). This line will measure 10 mm if units are in metric, (10 / 25.4) if units are in inches and so on...but the line length remains same - 10 units. The lisp code would return a distance of 10 units if length of segment is to be retrieved (I do not know units at this stage).

The problem starts now - If I have to take input from user which does some operation based on length of line and the constraint restricts such that input value should not be greater than line length(let's assume 5 as input value). If the units were metric - value 5 is less than length of line so it's ok. But if current system settings->units were inches then the input 5 would evalute to 5*25.4=127 which is not acceptable. So how to handle this situation regardless of whatever units may be set by user.?
Reply With Quote
  #4  
Old 12-21-2005, 11:08 PM
clausb's Avatar
clausb clausb is offline
Registered User
 
Join Date: Nov 2002
Posts: 1,168
Re: Program does not work if units are changed

You're assuming that the user changes the unit settings, and then you get different values from the dialog. However, my understanding is that if you use dialog value types such as :length, :positive-length, or :raw-length, OSDM does the unit conversion for you, and your dialog always receives the input values converted into standard/system units (mm in this case), no matter what the current user unit settings are. So if you have some other code which measures the length of an existing line, and that code returns the length in system units, you can compare those values directly. At least this is what I learn from reading the documentation on sd-defdialog.

So this is why I said earlier that the best way to handle user units is not to handle them at all - because OSDM takes care of this stuff for you already.

If you're really in a situation where for some reason you cannot benefit from the automatic unit conversion services of the dialog generator, you can still call IKIT functions such as sd-inq-length-units to find out about the current unit settings, or sd-sys-to-user-units/sd-user-to-sys-units for explicit conversion.

Claus
__________________
CoCreate Modeling FAQ: http://www.clausbrod.de/CoCreateModeling/

Last edited by clausb; 12-21-2005 at 11:27 PM.
Reply With Quote
  #5  
Old 12-21-2005, 11:19 PM
stefano_ME30's Avatar
stefano_ME30 stefano_ME30 is offline
Registered User
 
Join Date: Oct 2002
Location: Italy
Posts: 169
Re: Program does not work if units are changed

I think that if constraint restricts is the lenght of the line (like in your example) it is ever 5 units, the system will convert metric and inches input request from the user before to pass it to the system.
So if you have a line of 10 units the limit will be 10mm in metric and fraction of inche, don't ask me to calcute it, in inches side.
The system will show different limit value to users.
Reply With Quote
  #6  
Old 12-22-2005, 12:20 AM
VINIT VINIT is offline
Registered User
 
Join Date: Nov 2005
Posts: 35
Re: Program does not work if units are changed

Dear All,

I tried and got the solution using sd-sys-to-user-units function. If this function is not used, especially when retrieving lengths, angles and 2D points from geometry objects, you may get different results for same line when set with different units and measure angles.

Thanks to all
Vinit

Last edited by VINIT; 12-22-2005 at 12:26 AM.
Reply With Quote
  #7  
Old 12-22-2005, 12:27 AM
clausb's Avatar
clausb clausb is offline
Registered User
 
Join Date: Nov 2002
Posts: 1,168
Re: Program does not work if units are changed

My understanding is that you should not need to do your own conversion IF you are using one of the dialog value types which does the conversion for you, such as :length. Which value types are you using in your dialog?

Claus
__________________
CoCreate Modeling FAQ: http://www.clausbrod.de/CoCreateModeling/
Reply With Quote
  #8  
Old 12-22-2005, 02:22 AM
VINIT VINIT is offline
Registered User
 
Join Date: Nov 2005
Posts: 35
Re: Program does not work if units are changed

Dear Claus,
My program accepts following inputs in annotation module
Edge1 <*sd-anno-line-seltype*>
Edge2 <*sd-anno-line-seltype*>
CircleDia <positive-number>
Reply With Quote
  #9  
Old 12-22-2005, 02:26 AM
VINIT VINIT is offline
Registered User
 
Join Date: Nov 2005
Posts: 35
Re: Program does not work if units are changed

Dear Claus,
My program accepts following inputs in annotation module
1)Edge1 <*sd-anno-line-seltype*>
after-input get endpoints of line, compute line length by distance formula
2)Edge2 <*sd-anno-line-seltype*>
after-input get endpoints of line, compute line length by distance formula
3)CircleDia <positive-number>
After -input draw a circle tangent two edges whose dia is not greater than length of either of selected edges. If diameter is bigger, display error and force the user to renter the diameter.
Reply With Quote
  #10  
Old 12-22-2005, 02:26 AM
clausb's Avatar
clausb clausb is offline
Registered User
 
Join Date: Nov 2002
Posts: 1,168
Re: Program does not work if units are changed

Well, :positive-number values are inherently unitless, so OSDM will not try to convert the input. If, however, you simply change the type of CircleDia to :positive-length, you should get the units conversion for free. See also section 4.1.1.2 in the documentation on sd-defdialog.

Claus
__________________
CoCreate Modeling FAQ: http://www.clausbrod.de/CoCreateModeling/
Reply With Quote
  #11  
Old 12-22-2005, 02:47 AM
VINIT VINIT is offline
Registered User
 
Join Date: Nov 2005
Posts: 35
Re: Program does not work if units are changed

Well Claus,

Thanks for the update. Another question here

is the following command syntax arguments correct ?
(sd-call-cmds (AM_DIM_SET_ARROW_LINE :BROKEN_LINE :OFF))

I want to set it to "OFF" if it is on.

Regards
Vinit
Reply With Quote
  #12  
Old 12-22-2005, 03:00 AM
clausb's Avatar
clausb clausb is offline
Registered User
 
Join Date: Nov 2002
Posts: 1,168
Re: Program does not work if units are changed

Sorry, I never used that command, so I can only refer you to the general notes on how to find out the syntax for commands in OSDM:

http://www.clausbrod.de/Osdm/OsdmFaqCustomization#CommandSyntax

Claus
__________________
CoCreate Modeling FAQ: http://www.clausbrod.de/CoCreateModeling/
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 03:07 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.