几何尺寸与公差论坛

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

【转帖】custom property macro bugging ou

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

本版积分规则

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

GMT+8, 2024-12-24 09:24 , Processed in 0.036903 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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