×
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

SW VBA

SW VBA

(OP)
How can i delete my 'sheet format' with VBA ?!?

RE: SW VBA

I imagine you can use VBA to make sure you are in Sheet Format mode, then have a routine that finds all entities on the sheet format and then a routine that deletes all of those entities.

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group

RE: SW VBA

(OP)
Thnx for reply ...

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

Instead of deleting it, could you not just change it to a blank one?

cheers

RE: SW VBA

The problem is with your selection process.  All you have is a macro-recorded process for selecting and deleting a format.  Macro-recorded selections rarely work well.

Look into these commands to get the active sheet and format:
  • DrawingDoc::GetCurrentSheet
  • Sheet::SheetFormatVisible
  • Sheet::GetName
  • Sheet::GetProperties
  • Sheet::GetSheetFormatName
  • Sheet::SetSheetFormatName

batHonesty may be the best policy, but insanity is a better defense.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: SW VBA

(OP)
Perhaps ... i turned it off first, but on the dxf it was still visible ...

RE: SW VBA

You could make the macro reload the sheet with the sheet format hidden.  I don't know which processes would do this in API though.

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group

RE: SW VBA

(OP)
I tried that with a forcerebuild

didnt work

too bad didnt get the correct answer yet :(

RE: SW VBA

Here you go.
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

(OP)
thnx dude, works great !!

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.

cheers

RE: SW VBA

KenBolen,

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

fcsuper,

Whatever you want to do with the code is fine with me.

Ken

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