AnsweredAssumed Answered

Deleting Sheet and Inserting Model View in Invisible / Hidden Drawing

Question asked by Weston Schiltz on Jun 7, 2019
Latest reply on Jun 7, 2019 by Weston Schiltz

I am creating a drawing from a model view, deleting the first sheet then inserting a model in an existing view. Right now my program wont delete the sheet and it crashes if I try to insert the model while document is hidden. The code works without it being hidden but it takes a very long time. 

 

Dim swApp As Object
Dim Part As Object
Dim myModelView As Object
Dim myView As SldWorks.View
Dim path As String
Dim filename As String
Dim boolstatus As Boolean
Dim swDrawing As DrawingDoc
Dim confignames() As String
Dim config As String
Dim swSheet As sheet
Dim longstatus As Long, longwarnings As Long

 

Sub main()

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
path = Part.GetPathName
confignames = Part.GetConfigurationNames

 

'Go through each configuration create drawing, save as ai file, and close

For i = 0 To UBound(confignames)

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc

 

'Display current configuration name
configname = confignames(i)
Part.ShowConfiguration2 (configname)
Debug.Print configname

swApp.DocumentVisible False, swDocumentTypes_e.swDocDRAWING

 

' New Document
Set Part = swApp.NewDocument("P:\SolidWorksFiles\Settings\templates\epdm\template.drwdot", 12, swSheetWidth, swSheetHeight)
Set swDrawing = Part
Set swSheet = swDrawing.GetCurrentSheet()
swDrawing.ActivateSheet ("Sheet1")
swDrawing.Extension.SelectByID2 "Sheet1", "SHEET", 0, 0, 0, False, 0, Nothing, 0
swDrawing.DeleteSelection False

 

'Inserts part drawing
swDrawing.InsertModelInPredefinedView path
Set myModelView = Part.ActiveView

'Selecting drawing view and remove center marks
boolstatus = Part.ActivateView("Drawing View7")
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDetailingAutoInsertCenterMarksForHoles, 0, False)
boolstatus = Part.Extension.SelectByID2("Drawing View7", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)

 

'Calls ChangeView program for showing hidden lines, rotating drawing, and removing tanget edge
Call ChangeView.main

 

'Add front view
boolstatus = Part.Extension.SelectByID2("Drawing View7", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set myView = Part.CreateUnfoldedViewAt3(0.225, 0.129458589191605, 0, False)

 

'Deselect part
Part.ClearSelection2 True

 

' Save
longstatus = Part.SaveAs3("savelocation" & configname & ".ai", 0, 2)
filename = swDrawing.GetTitle
' Close Document
Set swDrawing = Nothing
Set Part = Nothing


swApp.CloseDoc filename
Debug.Print i
Next i

End Sub

Outcomes