Results 1 to 2 of 2

Thread: how to create a own block from vba programming

  1. #1
    Login to Give a bone
    0

    Default how to create a own block from vba programming

    Hi,
    I need a program to create a block from my own diagram not from predefined diagrams.
    please give me solution as early as possible

  2. #2
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: how to create a own block from vba programming

    Here is one from my very oldies
    I don't remember how it works
    Code:
    Option Explicit
    
    Public Sub MakeBlockFromSSet()
    
         Dim blkDef As AcadBlock, _
             blkRef As AcadBlockReference, _
             oSset As AcadSelectionSet, _
             insPt As Variant, _
             blkName As String, _
             i As Integer
         On Error GoTo Err_Control
         ' check if named selection set not in use
         For Each oSset In ThisDrawing.SelectionSets
              If oSset.Name = "$MakeBlock$" Then
                   oSset.Delete
                   Exit For
              End If
         Next
         ' create selection set
         Set oSset = ThisDrawing.SelectionSets.Add("$MakeBlock$")
         ThisDrawing.Utility.Prompt (vbCr & "Select objects to make block")
         oSset.SelectOnScreen
         ' pick insertion point of block
         insPt = ThisDrawing.Utility.GetPoint(, vbCr & "Pick insertion point: ")
         ' enter block name
         blkName = InputBox(vbCr & "Enter block name: ", "Block Name")
         ' create block definition
         Set blkDef = ThisDrawing.Blocks.Add(insPt, blkName)
         ' declare array of objects
         ReDim objColl(0 To oSset.Count - 1) As Object
         ' fill array with selected objects
         For i = 0 To oSset.Count - 1
              Set objColl(i) = oSset.Item(i)
         Next
         ' copy array to the newly created block definition
         ThisDrawing.CopyObjects objColl, blkDef
         ' delete selected objects / may to uncomment this line if you need it!
         ' oSset.Erase
         ' insert new block
         Set blkRef = ThisDrawing.ModelSpace.InsertBlock(insPt, blkName, 1, 1, 1, 0)
         Set oSset = Nothing     ' optional
    
    Err_Control:
         MsgBox Err.Description
    End Sub

Similar Threads

  1. Create a block that is not edtitable in block editor
    By vladimir.karatsupa982899 in forum AutoLISP
    Replies: 6
    Last Post: 2014-10-01, 09:48 AM
  2. Programming A Block Checker routine
    By cwal236623 in forum VBA/COM Interop
    Replies: 2
    Last Post: 2007-03-27, 05:51 PM
  3. Programming - Dynamic Block Visibility
    By pangus in forum AutoLISP
    Replies: 3
    Last Post: 2007-03-24, 08:03 AM
  4. Dynamic block fields for programming use
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2006-01-11, 05:42 PM
  5. Create new Dynamic Block via editing a Block within another drawing file
    By pbrumberg in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2006-01-10, 05:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •