×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

SolidWorks crashes when running Macro on larger assemblies

SolidWorks crashes when running Macro on larger assemblies

SolidWorks crashes when running Macro on larger assemblies

(OP)
Hi



I have a macro running on a BOM table, when I run the macro on small assemblies it works with no problems. But as soon as I have a large assembly (over 50 parts) solidworks stop working and has to be terminated (no error message, just a window popping up saying "Close program" or "Look for solutions on the web"). I am using a Component2 command (ComponentReference). It dies as soon as I enter the Else statement below.. I would appreciate all the help I could get, thanks once again! I am using SW 2012 sp4


Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swBomTbl As SldWorks.BomTableAnnotation
Dim swBalloonOpt As SldWorks.BalloonOptions
Dim TableAnnotation As SldWorks.TableAnnotation
Dim DrawComponent As SldWorks.DrawingComponent
Dim SelMgr, objApp As Object

Sub main()

Dim I As Long
Dim NumOfObj, SelObjType As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set SelMgr = swModel.SelectionManager
NumOfObj = SelMgr.GetSelectedObjectCount

Debug.Print "Number of selected Objects: " & NumOfObj

For I = 1 To NumOfObj

SelObjType = SelMgr.GetSelectedObjectType2(I)
Debug.Print "Type of object selected: " & SelObjType

Select Case SelObjType

Case 98
Set swBomTbl = SelMgr.GetSelectedObject5(I)
Set TableAnnotation = SelMgr.GetSelectedObject5(I)
Debug.Print "BOM Table Selected"

Case 12
' DrawComponent = SelMgr.GetSelectedObject5(I)
Debug.Print "Drawing View Selected"

End Select
Next I

CompRef swBomTbl, TableAnnotation
'AddBalloon DrawComponent

swModel.ForceRebuild3 True
End Sub


Sub CompRef(swBomTbl As SldWorks.BomTableAnnotation, TableAnnotation As SldWorks.TableAnnotation)

Dim Row As Long
Dim WRow As Long
Dim K As Long
Dim MergedCell As Boolean
Dim RowCount, CompCount, ColCount As Long
Dim Component As Component2
Dim CellText As String

RowCount = TableAnnotation.TotalRowCount
ColCount = TableAnnotation.TotalColumnCount

For K = 2 To RowCount - 1

Debug.Print K
Row = K
WRow = K

MergedCell = TableAnnotation.IsCellMerged(Row, 0, WRow, ColCount - 1)
Debug.Print MergedCell

If MergedCell Then

Else

CompCount = swBomTbl.GetComponentsCount(K)
Set Component = swBomTbl.IGetComponents(K, CompCount)
CellText = TableAnnotation.Text(K, 0)

Select Case CellText
Case "--"
MsgBox "Unable to find BOM No. at Row: " & (K + 1)
Case ""
TableAnnotation.DeleteRow (K)
Case Else
Component.ComponentReference = CellText
End Select

End If
Next K
End Sub

//Mattias

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources