![]() |
【转帖】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 |
所有的时间均为北京时间。 现在的时间是 09:51 AM. |