几何尺寸与公差论坛

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

【转帖】macro to update dimension has an error message

[复制链接]
发表于 2009-4-12 18:56:48 | 显示全部楼层 |阅读模式
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("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("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("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("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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-22 18:57 , Processed in 0.037368 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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