几何尺寸与公差论坛------致力于产品几何量公差标准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, 10:09 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】custom property macro bugging ou

custom property macro bugging out
i have a custom property macro i developed for my current employer and it works 99% of the time. below is the kind of process that causes the error:
1) make new part.
2) open macro & fill out description.
3) save & close.
4) make 2nd new part.
5) open macro & fill out description (different than step #2).
6) save & close.
7) open part from step #1.
8) open macro (everything is ok).
9) open macro 2nd time & brings in description from step #5.
i haven't personally seen it overwriting with a different description but i have seen it clear all of the properties to blank after using the macro 10+ times in succession. one of my coworkers had a lot of problems with this while everyone else has had zero problems over the last 6 months.
i tracked down part of the problem to my coworker changing some material properties (turning off advanced graphics) and having sw glitch out (check mark to exit materials editor would go away, and the macro would screw up every time he did this). i tried the same on my pc and no glitch, no error. i advised him to not make the changes he was doing, and everything has seemed hunky dory till he mentioned it happened again this morning.
please see my macro at
without looking into the macro i have one suggestion. look at your form handling to make sure it is unloaded/loaded correctly.
matt lorono
solidworks 2007 sp3.1
cad engineer/ecn analyst
this is what's at the end of the apply & close click
' refresh document and unload form
currentdoc.editrebuild ' rebuild document
custprop.hide 'hide dialog box
unload custprop 'removes macro from memory on end sub
this is what's at the end of the cancel/exit click
private sub cancel_click()
end ' quit macro
end sub
some observations:
you call "unload custprop" from within the custprop form. don't do that.
if a property already exists but is a different type, you may have issues overwriting.
sometimes it helps to load a form and then force an intializing routine to start. sometimes i do this by having an "initialize" flag and set it to fasle when i first load the form but before i activate it.
also, sometimes i write initialization in a separate sub and call that sub from both the initialize and activate events of the form. the call is also conditional, i.e. "if initflag = false then myinitsub".
sounds like you probably set global variables in your code, but at the start of the process you are not clearing them, so if the macro does not get completely unloaded from memory then the variables will still be set to the previous value, and if for some reason your code does not overwrite them all the time, the last set values will be used instead.
roland,
i don't really understand in theory what you're saying. from what i understand my form code & object are named custprop, and after i've added, and pulled the custom properties from solidworks i:
unload custprop
load custprop
does that "unload custprop" need to be moved to the begining of my main sub so it works right off before anything else? would that unload the information correctly then? or are you implying that i need to move most of my code out of the form and call it from the module? i'm kind of confused how this would clear the variables, or in theory resolve whatever conflict is happening.
-----------------------
in response to luke,
the variables are set on the module level and not on the procedure level.
is there some kind of vb command to automatically clear a set of module level variables when i click to use my macro? or is there another way to organize/code everything to do it? or say to delete the variables completely after i've saved them over to solidworks so it forces them clear 100% of the time?
i really appreciate the comments guys!
thanks,
james
unfortunately vba classes all variables as global for integrity and only the scope is affected by its location, so if a macro does not unload from memory all variables will still be set in every scope level.
as for clearing them, no i'm afraid not, manual is the only way
well i don't mind if i have to manually clear 20+ variables at the end of my macro.
what's the vb command to release/erase/clear a single variable?
is it as simple as using:
set= nothing
wherewould be a variable i'm using, and just copy that for all variables.
edited: 06/17/2008 at 10:22 am by james spisich
just clear a variable like you said yes:
myvar = nothing
i tested the following:
added "string" = vbnullstring & "variant" = empty to clear out strings and variants in the code after i was done with them. didn't see any positive or negative effect of this. also tried this with adding all of the leftover variables having a seperate clear on the save click, but that didn't work.
also tried revised my save click to:
currentdoc.editrebuild ' rebuild document
custprop.hide 'hide dialog box
unload custprop 'removes form object from memory on end sub
set custprop = nothing 'remove form code from memory on end sub
i still didn't see any positive or negative effect of setting the form to nothing.
lastly i added a new sub on the module level for exitting the macro with the above save click info to move the form reference out of the form itself. still saw no effect.
with all of this i'm still at square one where the macro will randomly clear all variables (by clear i mean set them to "") at some point between exiting the macro and the form loading the property text into the form textboxes.
it's probably something simple i'm missing that will make me feel say "i told you so" to myself after.
scratch that, i think it may be working as intended now.
i guess i'll know soon enough if my coworker continues to have problems.
tried opening/closing the macro between 2 test parts, with randomly saving and no glitch.
i think the key was cleanup, i noticed a couple variables i set, but didn't use, and also cleaned up the save & cancel click to call a sub in my module that cleared the remaining string variables, and the form, and set the form = nothing.
thanks!
james
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
Scheme 程序语言介绍之一 huangyhg 专家系统 6 2010-02-18 01:22 PM
【转帖】macro for inserting and mating a new part in an assembly yang686526 SolidWorks二次开发 0 2009-04-12 09:38 PM
【转帖】macro for adding custom property yang686526 SolidWorks二次开发 0 2009-04-12 09:36 PM
【转帖】linked sketch text now possible1 9sort of0 yang686526 SolidWorks二次开发 0 2009-04-12 09:34 PM
【转帖】copy an existent sketch into a macro yang686526 SolidWorks二次开发 0 2009-04-12 08:31 PM


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


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