几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-04-13, 08:37 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】a little help with rounding

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
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 04:19 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多