Author Topic: Block can not be exploded  (Read 4415 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
Block can not be exploded
« on: April 14, 2006, 03:17:08 PM »

I was wondering if someone can help me.
We have some blocks in work that should not be exploded under any circumstances. I am trying to write some code using the begin command event that will recognize the block if someone tries to explode it and prevent it from being exploded. Any help would be appreciated. Here is what I have so far

Thank you
Mark

-----------------------

Dim blkref As AcadBlockReference


On Error Resume Next

For Each blkref In ThisDrawing.ModelSpace
If blkref.Name = ("xarw") Then
If CommandName = ("EXPLODE") Then
MsgBox "This item can not be exploded"
End If
End If
Next

ThisDrawing.SendCommand ("undo") & vbCrLf

End Sub

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Block can not be exploded
« Reply #1 on: April 14, 2006, 03:21:44 PM »
Take advantage of block MINSERT

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Block can not be exploded
« Reply #2 on: April 14, 2006, 03:26:58 PM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Block can not be exploded
« Reply #3 on: April 14, 2006, 03:29:17 PM »
maybe use AcadDocument.BeginCommand
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Block can not be exploded
« Reply #4 on: April 14, 2006, 05:03:55 PM »
Ml, below seems to work. I both love and hate begincommand, the escape sequences are tricky,
 but this doesn't seem to have that problem.
Explode deletes the blockref at some point as shown by
Private Sub AcadDocument_ObjectErased(ByVal ObjectID As Long)
   MsgBox ObjectID
End Sub

So perhaps there is an efficient way to use that useless now defunct objectid
but selectionsets are fast
so below may be your best shot.

Code: [Select]
Option Explicit


Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
    Debug.Print CommandName
    If CommandName = "EXPLODE" Then
        Dim SStart As AcadSelectionSet
        Set SStart = sset(2, "xarw", "SStart")
    End If
End Sub



Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
If CommandName = "EXPLODE" Then
    Dim SEnd As AcadSelectionSet
    Set SEnd = sset(2, "xarw")
    If ThisDrawing.SelectionSets("SStart").Count > SEnd.Count Then
        MsgBox "Behave"
        ThisDrawing.SendCommand "Undo 1 "
    End If
End If

End Sub


Public Function sset(Optional FilterType, Optional FilterData As Variant, Optional ssName As String = "SS") As AcadSelectionSet
   
    Dim oSSets As AcadSelectionSets
    Set oSSets = ThisDrawing.SelectionSets
    For Each sset In oSSets
        If sset.Name = ssName Then
            sset.Delete
            Exit For
        End If
    Next
   
    Set sset = ThisDrawing.SelectionSets.Add(ssName)
    If IsMissing(FilterData) Then
        sset.Select 5
        Exit Function
    End If
   
    Dim FType() As Integer
    Dim FData() As Variant
    Dim I As Integer
    If IsArray(FilterType) = False Then
        If IsArray(FilterData) = False Then
            ReDim FType(0)
            ReDim FData(0)
            FType(0) = FilterType
            FData(0) = FilterData
        Else
            Exit Function
        End If
    Else
        If UBound(FilterType) <> UBound(FilterData) Then
            Exit Function 'They must be pairs
        End If
       
        ReDim FType(UBound(FilterType))
        ReDim FData(UBound(FilterType))
        For I = 0 To UBound(FilterType)
            FType(I) = FilterType(I)
            FData(I) = FilterData(I)
        Next
    End If
     
        sset.Select 5, FilterType:=FType, FilterData:=FData

End Function

Sdoman

  • Guest
Re: Block can not be exploded
« Reply #5 on: April 14, 2006, 06:38:38 PM »

I was wondering if someone can help me.
We have some blocks in work that should not be exploded under any circumstances. I am trying to write some code using the begin command event that will recognize the block if someone tries to explode it and prevent it from being exploded. Any help would be appreciated. Here is what I have so far

Thank you
Mark

<clip>


Mark,

What version of AutoCAD are you running?  Beginning with AutoCAD 2005 ( i think ? ), you can make blocks unexplodeable by checkmarking a box inside the block command dialogue.

Probably a way to do the same via code.   But I don't know VBA, and haven't tried with lisp.






Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Block can not be exploded
« Reply #6 on: April 14, 2006, 07:04:00 PM »
Probably a way to do the same via code.   But I don't know VBA, and haven't tried with lisp.
From the Autdesk DevHelp this is a property of the BLOCK object, so setting it to false for this one Block definition should make all insertions of it unexplodable...
Quote from: AcadDevHelp
Explodable Property
 


Specifies whether the block can be exploded.

Signature

object.Explodable

object

Block
The object or objects this property applies to.

Explodable

Boolean; read-write

TRUE: The block can be exploded.

FALSE: The block cannot be exploded.

Remarks

Note To access this property, use the IAcadBlock3 interface.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Block can not be exploded
« Reply #7 on: April 14, 2006, 07:23:23 PM »
Nice work, too easy.