I have a macrofeature that run a code on every rebuilt. Quickly I check if for sheetmetal and assign some property if sheetmetal or not. I So, I loop tree feature and check for the cutlist folder and if its empty then :
1- its an empty folder so sheetmetal have been deleted so I need to delete this folder to clean
2- I m inside the sheetmetal function (the rebuilt run twice, when the function start and when the ok button is clicked) so inside the function in the first run.
So, if I try to delete the folder it wont and its what I want but it keeps crashing. So, I use the creation date to check if its 10 seconds from now, if not older then that do not delete...
Then, for the second run, I still wont to delete the folder but this time I cannot check the creation time, but since the ok button is pushed, metalsheet feature appears so I check this time for FlatPattern, SolidToSheetMetal or SheetMetal feature.
Its working great, except this:
If the function takes too much time (I think its when I takes more then the 25 second creation date (I test it and really linked to the dateadd() time...) but looks not related in the code, it just skip that line...) then those sheetmetal function are not there in the feature loop. Its created like normal but not in the loop...
Pretty weird! Is anyone know the reason of this? Here the code:
Function GetCutLists(model As SldWorks.ModelDoc2, boundingBox As Boolean, epaisseurCube As Double, ReturnLength As Variant, DelFolder As Boolean) As Variant Dim swCutLists() As SldWorks.Feature Dim swFeat As SldWorks.Feature Dim swSelMgr As SldWorks.SelectionMgr DelFolder = True 'this boolean tells in other function to delete or not Set swSelMgr = model.SelectionManager boundingBox = True Set swFeat = model.FirstFeature While Not swFeat Is Nothing If swFeat.GetTypeName2 = "BoundingBoxProfileFeat" Then boundingBox = True If swFeat.GetTypeName2 = "CutListFolder" Then If swFeat.DateCreated > DateAdd("s", -25, Now) Then DelFolder = False If swFeat.GetTypeName2 = "FlatPattern" Or swFeat.GetTypeName2 = "SheetMetal" Or swFeat.GetTypeName2 = "SolidToSheetMetal" Then DelFolder = False 'MsgBox swFeat.GetTypeName2 'MsgBox swFeat.Name If swFeat.GetTypeName2 = "Extrusion" Or swFeat.GetTypeName2 = "Boss" Then 'find length in dimenssion and store value Dim swDispDim As SldWorks.DisplayDimension Set swDispDim = swFeat.GetFirstDisplayDimension While Not swDispDim Is Nothing Dim swDim As SldWorks.Dimension Set swDim = swDispDim.GetDimension2(0) 'MsgBox swDim.Name If UCase(swDim.Name) = "LENGTH" Then ReturnLength = swDim.Value If UCase(swDim.Name) = "EPAISSEUR" Then epaisseurCube = swDim.Value Set swDispDim = swFeat.GetNextDisplayDimension(swDispDim) Wend End If If swFeat.GetTypeName2 <> "HistoryFolder" Then ' MsgBox swFeat.GetTypeName2 ProcessFeature swFeat, swCutLists TraverseSubFeatures swFeat, swCutLists End If Set swFeat = swFeat.GetNextFeature Wend GetCutLists = swCutLists End Function