几何尺寸与公差论坛

 找回密码
 注册
查看: 639|回复: 0

【转帖】a little help with rounding

[复制链接]
发表于 2009-4-13 08:37:58 | 显示全部楼层 |阅读模式
a little help with rounding ?
i have the following code and i as understand it it should round up if decimal = 5 or greater but it does not, if i have a part that has a thickness of .125 it gives back .12 but it should give back .13. does anybody see what could be wrong ?
function getthickness(thickness as variant)
dim swsheetmetal as sldworks.sheetmetalfeaturedata
dim userunits as variant
dim convfactor as double
set swapp = createobject("sldworks.application")
set part = swapp.activedoc
userunits = part.getunits()
' debug.print "lengthunit = " & userunits(0)
' debug.print "fraction base = " & userunits(1)
' debug.print "fractiondenominator = " & userunits(2)
' debug.print "significantdigits = " & userunits(3)
' debug.print "roundtofraction = " & userunits(4)
select case part.getunits(0)
case swmm
convfactor = 1 * 1000
case swcm
convfactor = 1 * 100
case swmeter
convfactor = 1
case swinches
convfactor = 1 / 0.0254
case swfeet
convfactor = 1 / (0.0254 * 12)
case swfeetinches
convfactor = 1 / 0.0254 ' pass inches through
case swangstrom
convfactor = 10000000000#
case swnanometer
convfactor = 1000000000
case swmicron
convfactor = 1000000
case swmil
convfactor = (1 / 0.0254) * 1000
case swuin
convfactor = (1 / 0.0254) * 1000000
end select
set swfeat = part.firstfeature
while not swfeat is nothing
'debug.print swfeat.name & " - " & swfeat.gettypename
if swfeat.gettypename = "sheetmetal" then
set swsheetmetal = swfeat.getdefinition
thickness = swsheetmetal.thickness
end if
set swfeat = swfeat.getnextfeature
wend
thickness = round(thickness * convfactor, userunits(3))
debug.print (thickness)
end function
solidworks 2006,2007,2008,2009 (office premium.)
core 2 duo e6850 @ 3.00 mhz
window xp pro sp3 32 bit
ati firegl v7350
ben, could it have to do with the fact that the thickness is a linked dimension (as shown in the equations folder) and it may be defaulted to two decimal places, dropping the decimals after? unfortunately, i don't know what the api call is to change that, but that's my guess. it's probably some kind of setuserpreference, but i haven't found anything.
>>wayddaminnit, i just found something else. in the part.getunits function, the fifth parameter, roundtofraction, denotes whether to round something up or not. you may want to setunits and ensure that it is rounding (true) to get the results you want.
let me know what you find out!
to defeat the wheat, go against the grain.
edited: 11/07/2008 at 10:11 am by tom fosler
well, technically, .12 is the correct value since on drawings you should round to the nearest even number.  it frustrates me that sw does not do this automatically.
matt lorono
solidworks 2007 sp3.1
cad engineer/ecn analyst
hmm.. matt, not sure that i agree with you. is the rule not: 5 you always round up ?
solidworks 2006,2007,2008,2009 (office premium.)
core 2 duo e6850 @ 3.00 mhz
window xp pro sp3 32 bit
ati firegl v7350
in normal mathematics, you are normally taught to round up for 5. however, engineering rule of rounding is typically to round to the nearest even number for statistical purposes.
see : astm e 29
no luck yet tom. i am possibly not doing it right yet but i will keep trying thanks for the reply.
solidworks 2006,2007,2008,2009 (office premium.)
core 2 duo e6850 @ 3.00 mhz
window xp pro sp3 32 bit
ati firegl v7350
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-23 23:08 , Processed in 0.034264 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表