几何尺寸与公差论坛------致力于产品几何量公差标准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-12, 06:56 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】macro to update dimension has an error message

macro to update dimension has an error message
i wonder if somebody can help to find out how to solve an error message.
i have the an excel spreadsheet with a macro that update circle's dimensions solidworks part.
basically, i have typed the following data in the excel spreadsheet:
1.- in the cell "a1" i have the "angle" description in the cell "b1" i have the "angle" value.
2.- in the cell "a2" i have the "distance" description in the cell "b2" i have the "distance" value.
the excel macro that reads this data and update the part's dimension in sw is:
' &&& start macro &&&&
sub circle_dimensions()
dim swapp as object
dim part as object
dim boolstatus as boolean
dim longstatus as long, longwarnings as long
dim featuredata as object
dim feature as object
dim component as object
set swapp = createobject("sldworks.application")
set part = swapp.activedoc
boolstatus = part.extension.selectbyid("d1@revolve1@part1.sldprt", "dimension", -0.09850135091876, -0.1943853516059, 0.08935038736053, false, 0, nothing)
part.parameter("<A href="mailto:d1@revolve1").systemvalue">d1@revolve1").systemvalue = excel.range("b1") / 0.57
boolstatus = part.extension.selectbyid("d2@sketch1@part1.sldprt", "dimension", -0.03077633012788, -0.11670139381, 0.09386013938138, false, 0, nothing)
part.parameter("<A href="mailto:d2@sketch1").systemvalue">d2@sketch1").systemvalue = excel.range("b2") * 0.0254
part.clearselection2 true
part.editrebuild
part.viewzoomtofit2
end sub
'&&& end macro &&&&
when i run the macro i got the following error message:
run-time error "91":
object variable or with block variable no set
after i click "debug" it is highlighting at the following statement:
boolstatus = part.extension.selectbyid("d1@revolve1@circle.sldprt", "dimension", -0.09850135091876, -0.1943853516059, 0.089350387
could you please tell me what is the object variable i have to set?
thanks in advance.
maperalia
it probably means the active document (so the part variable) is set to nothing, so the .extension part causes the error. either add a watch to the part object and debug it, or try this code in place of the error line and see what line it errors on:
dim ext as modeldocextension
set ext = part.extension
boolstatus = ext.selectbyid("d1@revolve1@part1.sldprt", "dimension", -0.09850135091876, -0.1943853516059, 0.08935038736053, false, 0, nothing)
luke;
thanks for your quick response. i placed the code as you advised me. however, after i run it i got the same error message:
run-time error "91":
object variable or with block variable no set
then after i click "debug" it is highlighting at the following statement:
set ext = part.extension
what does it mean please?
kind regards.
maperalia
it means that your set part = swapp.activedoc line is returning nothing, meaning the instance of sw that your program is hooking to has no open/active document. change createobject() to getobject() to hook to an active sw not create a new instance
luke;
i changed the statement
from:
set swapp = createobject("sldworks.application")
to:
set swapp = getobject("sldworks.application")
however, when i run it got the following error message:
run-time error '-2147221020(800401e4)':
automation error
invalid syntax
after i click "debug" it is highlighting at the following statement:
set swapp = getobject("sldworks.application")
could you please tell me what is the syntax error i have?
thanks in advance.
maperalia
set swapp = getobject(, "sldworks.application")
luke;
thank you very much.. it is working perfectly!!!!!
i really appreciatte your helping me with this matter.
kind regards.
maperalia
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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



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


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