PDA

View Full Version : Program does not work if units are changed


VINIT
12-21-2005, 12:31 AM
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

clausb
12-21-2005, 03:53 AM
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

VINIT
12-21-2005, 07:24 PM
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.?

clausb
12-21-2005, 11:08 PM
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

stefano_ME30
12-21-2005, 11:19 PM
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.

VINIT
12-22-2005, 12:20 AM
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

clausb
12-22-2005, 12:27 AM
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

VINIT
12-22-2005, 02:22 AM
Dear Claus,
My program accepts following inputs in annotation module
Edge1 <*sd-anno-line-seltype*>
Edge2 <*sd-anno-line-seltype*>
CircleDia <positive-number>

VINIT
12-22-2005, 02:26 AM
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.

clausb
12-22-2005, 02:26 AM
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

VINIT
12-22-2005, 02:47 AM
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

clausb
12-22-2005, 03:00 AM
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