Block not being redefined

Discussion in 'AutoCAD' started by Dale Levesque, Jun 1, 2004.

  1. I'm using the following code to create a block. My problem is that no matter
    what I pass in my selection set, If a block named "Custom Brick" exists the
    original block definition is used. How can I get the block definition to be
    overwritten by the entities I pass.


    Best regards,

    Dale


    Dim lo_BlkRef As AcadBlockReference

    Set lo_BlkRef = g_fn_CreateBlock(mvarInsertionPt, "Custom Brick",
    lo_Drawing, lo_PL_SSet)


    Public Sub AddObjectsToBlock(ao_Drawing As AcadDocument, blkRef As
    AcadBlockReference, entArray() As AcadEntity, Optional delObj As Boolean =
    True)

    Dim blkDef As AcadBlock
    Dim origin(0 To 2) As Double
    Dim I As Long

    origin(0) = 0: origin(1) = 0: origin(2) = 0

    Set blkDef = ao_Drawing.Blocks(blkRef.Name)

    If blkDef.Count < 1 Then
    For I = LBound(entArray) To UBound(entArray)
    entArray(I).Move blkRef.InsertionPoint, origin
    Next
    ao_Drawing.CopyObjects entArray, blkDef
    End If

    If delObj Then
    For I = LBound(entArray) To UBound(entArray)
    entArray(I).Delete
    Next
    End If

    End Sub
    Public Function g_fn_CreateBlock(av_InsPt As Variant, as_BlockName As
    String, ao_Drawing As AcadDocument, ao_SSet As AcadSelectionSet) As
    AcadBlockReference


    Dim lo_BlockDefinition As AcadBlock
    Dim lo_BlockReference As AcadBlockReference
    Dim la_Entities() As AcadEntity
    Dim ld_TempInsPt(0 To 2) As Double

    ld_TempInsPt(0) = 0#: ld_TempInsPt(1) = 0#: ld_TempInsPt(2) = 0#

    Set lo_BlockDefinition = ao_Drawing.Blocks.Add(ld_TempInsPt,
    as_BlockName)

    Set lo_BlockReference = ao_Drawing.ModelSpace.InsertBlock(av_InsPt,
    as_BlockName, 1#, 1#, 1#, 0#)

    la_Entities = ssArray(ao_SSet)

    AddObjectsToBlock ao_Drawing, lo_BlockReference, la_Entities, True



    Set g_fn_CreateBlock = lo_BlockReference

    End Function

    Public Function ssArray(ss As AcadSelectionSet) As Variant

    Dim retVal() As AcadEntity
    Dim I As Long

    ReDim retVal(0 To ss.Count - 1)

    For I = 0 To ss.Count - 1
    Set retVal(I) = ss.Item(I)
    Next

    ssArray = retVal

    End Function
     
    Dale Levesque, Jun 1, 2004
    #1
  2. The Blocks.Add method creates the Block definition in the blocks table. Then
    the InsertBlock method then adds a reference to that block in the drawing.

    I geuss what I really want to do is delete the definition from the blocks
    table first after getting rid of the old references. I sure hope I can get
    away without doing that.

    Dale
     
    Dale Levesque, Jun 2, 2004
    #2
  3. Dale,

    Does this sample help you?

    Sub Test()
    Dim blkName As String
    blkName = "Test"
    MakeABlock blkName
    Dim pt0(0 To 2) As Double
    ThisDrawing.ModelSpace.InsertBlock pt0, blkName, 1, 1, 1, 0
    AcadApplication.ZoomExtents
    ThisDrawing.Regen acAllViewports
    MsgBox "I'm just waiting on you."
    ModifyThatBlock blkName
    ThisDrawing.Regen acAllViewports
    End Sub

    Private Sub MakeABlock(Name As String)
    Dim pt0(0 To 2) As Double
    Dim myBlk As AcadBlock
    Set myBlk = ThisDrawing.Blocks.Add(pt0, Name)
    myBlk.AddCircle pt0, 1
    End Sub

    Private Sub ModifyThatBlock(Name As String)
    Dim myBlk As AcadBlock
    Set myBlk = ThisDrawing.Blocks.Item(Name)
    Dim aObject As AcadEntity
    For Each aObject In myBlk
    aObject.Delete
    Next aObject
    Dim pts(0 To 7) As Double
    pts(0) = -1
    pts(1) = -1
    pts(2) = 1
    pts(3) = -1
    pts(4) = 1
    pts(5) = 1
    pts(6) = -1
    pts(7) = 1
    Dim myPLine As AcadLWPolyline
    Set myPLine = myBlk.AddLightWeightPolyline(pts)
    myPLine.Closed = True
    End Sub


    --
    R. Robert Bell


    "Dale Levesque" <dale at dynamicwindows.com> wrote in message
    The Blocks.Add method creates the Block definition in the blocks table. Then
    the InsertBlock method then adds a reference to that block in the drawing.

    I geuss what I really want to do is delete the definition from the blocks
    table first after getting rid of the old references. I sure hope I can get
    away without doing that.

    Dale
     
    R. Robert Bell, Jun 2, 2004
    #3
  4. Dale Levesque

    Mark Propst Guest

    why are you inserting it before defining it?
    that will prevent redefining I would think
    just a guess
     
    Mark Propst, Jun 2, 2004
    #4
  5. Very nicely Robert, Thank you.

    Best regards,

    Dale Levesque
     
    Dale Levesque, Jun 2, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.