Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

API Help - Deleting Block Definition?

Status
Not open for further replies.

8Complex

Mechanical
Jan 28, 2004
38
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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor