×
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

API Help - Deleting Block Definition?

API Help - Deleting Block Definition?

API Help - Deleting Block Definition?

(OP)
Hi all. I've got a macro laid out for auto-inserting blocks into our drawings that works perfectly. The challenge I am having is to delete the block definitions in the drawing before the new definitions/instances are inserted.

There is a set number of blocks that I am checking for and am wanting to delete, so I've got a simple select case running through them, I just need to know how to use "swModel.Extension.SelectByID" and "swModel.Extension.DeleteSelection2" in order to get the job done. I am also open to other suggestions.

Here is a summarized section of my code, there is a form working as an interface, but anyone experienced should be able to tell that.

CODE

    Public swApp                        As Object
    Public swSheet                      As Object
    Public MyDoc                        As Object
    Public vSheetProps                  As Variant
    Public bGen                         As String
    Public bApp1                        As String
    Public bApp2                        As String
    Public bRaw                         As String
    Public bPath                        As String
    Public bTP                          As String
    Public SheetSize                    As String
    Public JunkVar                      As Object

----- cut out code to shorten post -----

Private Sub cmdInsert_Click()
 
    Dim vBlockDef                       As Variant
    Dim swBlockDef                      As SldWorks.BlockDefinition
    Dim vBlockInst                      As Variant
    Dim swModel                         As SldWorks.ModelDoc2
    'Dim swDocExt                        As Object
    Dim bRet                            As Boolean
    Dim i                               As Long

    Set swApp = Application.SldWorks
    Set MyDoc = swApp.ActiveDoc
    Set swSheet = MyDoc.GetCurrentSheet
    'Set swDocExt = swModel.Extension
 
 'Delete old blocks already in drawing
    vBlockDef = MyDoc.GetBlockDefinitions
    
    If Not IsEmpty(vBlockDef) Then
        For i = 0 To UBound(vBlockDef)
            Set swBlockDef = vBlockDef(i)
            
            vBlockInst = swBlockDef.GetBlockInstances

            Select Case swBlockDef.Name
                Case "Raw finish"
                'bRet = swModel.Extension.SelectByID(swBlockDef.Name, "BLOCKDEF", 0#, 0#, 0#, False, 0, Nothing)
                'bRet = swModel.Extension.DeleteSelection2(swDelete_Children)
                Case "x general finish"
                Case "y general finish"
                Case "z general finish"
                Case "Raw appears in drawing"
                Case "x appears in drawing"
                Case "y appears in drawing"
                Case "z appears in drawing"
                Case "Touches Product"

            End Select

        Next i
    End If


 'Insert new blocks in place in drawing
----- cut out code to shorten post -----
WriteGeneral
WriteAppears1
WriteAppears2
WriteRaw
WriteTP

MyDoc.GraphicsRedraw2
frmBlockSelection.Hide
End
End If

End Sub

As you can see, I've been trying different ways to get it done, but have them commented out since they were all throwing errors.

Please let me know if more information is needed, I will gladly post up more, or even email the code to someone to check out more fully if they think they can help.

Thank you!

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