SW VBA
SW VBA
(OP)
How can i delete my 'sheet format' with VBA ?!?
When was the last time you drove down the highway without seeing a commercial truck hauling goods?
Download nowINTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS Come Join Us!Are you an
Engineering professional? Join Eng-Tips Forums!
*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting GuidelinesJobs |
|
RE: SW VBA
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group
RE: SW VBA
i have a vba routine for it, but something strange happens ..
When i manually throw away the sheet format and then undo it ... after that it works ... when i just run the macro . it doesnt ..
Here's some code:
sub justdoit()
Dim MswApp As Object
Dim MPart As Object
Dim MSelMgr As Object
Dim Mboolstatus As Boolean
Dim Mlongstatus As Long, Mlongwarnings As Long
Dim MFeature As Object
Dim Sheet As Object
Set MswApp = Application.SldWorks
Set MPart = MswApp.ActiveDoc
Set Sheet = MPart.GetCurrentSheet
shtnaam = Sheet.GetSheetFormatName
Set MSelMgr = MPart.SelectionManager
Mboolstatus = MPart.Extension.SelectByID2(shtnaam, "SHEET", 0, 0, 0, False, 0, Nothing, 0)
MPart.EditDelete
end sub
RE: SW VBA
RE: SW VBA
Look into these commands to get the active sheet and format:
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: SW VBA
RE: SW VBA
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group
RE: SW VBA
didnt work
too bad didnt get the correct answer yet :(
RE: SW VBA
Ken
CODE
'DeleteSheetFormat
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim swSelMgr As SldWorks.SelectionMgr
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim bStatus As Boolean
Dim nDeleteOption As Long
Dim nStatus As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If (swModel Is Nothing) Then
MsgBox "Must have a Drawing document open." & Chr(13) & "Routine Ending.", vbExclamation, "DeleteSheetFormat"
End
End If
If (swModel.GetType <> swDocDRAWING) Then
MsgBox "Must have a Drawing document open." & Chr(13) & "Routine Ending.", vbExclamation, "DeleteSheetFormat"
End
End If
Set swModelDocExt = swModel.Extension
Set swDraw = swModel
Set swSheet = swDraw.GetCurrentSheet
swModel.ClearSelection2 True
Set swSelMgr = swDraw.SelectionManager
bStatus = swModelDocExt.SelectByID2(swSheet.GetSheetFormatName, "SHEET", 0, 0, 0, False, 0, Nothing, 0)
If bStatus Then
' To delete absorbed features, use enum SwConst.swDelete_Absorbed
' To delete children features, use enum SwConst.swDelete_Children
' To keep absorbed features and children features, set DeleteOption = 0
'nDeleteOption = SwConst.swDelete_Absorbed
'nDeleteOption = SwConst.swDelete_Children
'nDeleteOption = 0
nDeleteOption = SwConst.swDelete_Absorbed + SwConst.swDelete_Children
nStatus = swModelDocExt.DeleteSelection2(nDeleteOption)
If (nStatus = 1) Then
swModel.ClearSelection2 True
swModel.ForceRebuild3 (False)
Else
MsgBox "Delete Sheet Format failed." & Chr(13) & "*Delete* function failed.", vbExclamation, "DeleteSheetFormat"
End If
Else
MsgBox "Delete Sheet Format failed." & Chr(13) & "Unable to *select* Sheet Format", vbExclamation, "DeleteSheetFormat"
End If
End Sub
RE: SW VBA
RE: SW VBA
33456 ... just in case you are unaware of this feature; clicking the link awards a star to the poster. The stars are counted toward the MVP listing for the forum.
RE: SW VBA
Cool code. Do you think I can post it on my resource site (in my signature)?
Also, one thing to look at for future versions (if forecoming) is that the code currently ignores inserted objects (such as images of company logos) on the sheet format.
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group
RE: SW VBA
Whatever you want to do with the code is fine with me.
Ken