insertBlock

Discussion in 'AutoCAD' started by rajeswararaop, Feb 24, 2004.

  1. Hi all,
    How to insert a specified block, which is in the another drawing.
    Thanks in advance
    Rajesh
     
    rajeswararaop, Feb 24, 2004
    #1
  2. rajeswararaop

    Bill Wright Guest

    Are you trying to "Insert" a Wblock drawing or copy a block from one
    open document to another?

    to Insert a Wblock I use:

    ThisDrawing.ModelSpace.InsertBlock(.......)

    You should include the ".dwg" extension in the Name argument.

    For copying from one doc to another I do something like:

    Dim ObjCollection(0) As Object
    Dim NewPart As Variant
    PartCopy As Object

    'copy the part to create the view from
    Set ObjCollection(0) = mPsPart

    NewPart = CurrentDocument.CopyObjects(ObjCollection,
    ThisDrawing.ModelSpace)

    Set PartCopy = NewPart(0)
    .......
    ......

    the objects can be anything not just blocks.

    Hope this helps
    Bill
     
    Bill Wright, Feb 25, 2004
    #2
  3. rajeswararaop

    johnbarton Guest

    An old method is inserting the entire drawing then deleting the inserted block. This will also import all the blocks that were in that drawing as well. So you then use the block that was needed and purge all unused blocks. Does anyone know if you can move a block definition from one open drawing to another? That may be a better solution if you can get it to work.
     
    johnbarton, Feb 25, 2004
    #3
  4. rajeswararaop

    Mark Propst Guest

    to another?

    check out the CopyObjects method
     
    Mark Propst, Feb 26, 2004
    #4
  5. rajeswararaop

    allfro Guest

    This is from the Code A Day Archives at vbdesign entitled
    2000-10-18.

    '//Begin Code Block //Place in a standard module

    Public Sub Copy_Insert()
    Dim strName As String
    Dim strTitle As String
    Dim strDefault As String
    Dim strPrmt As String
    strTitle = "Extract and Count"
    strPrmt = "Enter Name of block"
    strName = InputBox(strPrmt, strTitle)
    If Len(strName) > 0 Then
    If CopyBlocks(strName) Then
    'You can specify arguments by name
    'VBD_InsertBlock strName, dblScale:=2
    'The only required argument is the block name
    VBD_InsertBlock strName
    End If
    End If
    End Sub

    '@~~~~~~~~~~~~~~ CopyBlocks ~~~~~~~~~~~~~~~~~~~~~~~@
    'Copy A Block from current drawing to New Drawing
    'AutoCAD must be in MDI (multiple document mode)
    '@~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@

    Public Function CopyBlocks(strBlkName As String) As Boolean
    Dim objSource As AcadDocument
    Dim objDest As AcadDocument
    Dim objBlk As AcadBlock
    Dim objEnts(0) As Object
    Dim varEnts As Variant
    Dim intCnt As Integer
    On Error GoTo Err_Control
    If ThisDrawing.GetVariable("SDI") = 0 Then
    Set objBlk = ThisDrawing.Blocks(strBlkName)
    Set objEnts(0) = objBlk
    Set objSource = Application.ActiveDocument
    Set objDest = Application.Documents.Add
    varEnts = objSource.CopyObjects(objEnts, objDest.Blocks)
    CopyBlocks = True
    End If
    Exit_Here:
    Exit Function
    Err_Control:
    MsgBox Err.Description
    Resume Exit_Here
    End Function

    '@~~~~~~~~~~~~~~ VBD_InsertBlock ~~~~~~~~~~~~~~~~~~@
    'Insert a block with attributes and allow the user
    'To enter the attribute values.
    '@~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@

    Public Function VBD_InsertBlock(strBlkName As String, _
    Optional varInsert As Variant, Optional dblScale As Variant = 1, _
    Optional dblRotation As Variant = 0) _
    As AcadBlockReference
    Dim objTemp As AcadBlockReference
    Dim objBlk As AcadBlock
    Dim colBlks As AcadBlocks
    Dim strPrompt As String
    Dim strReply As String
    Dim varAtts As Variant
    Dim intCnt As Integer
    On Error GoTo Err_Control
    Set colBlks = ThisDrawing.Blocks
    Set objBlk = colBlks.Item(strBlkName)
    If IsMissing(varInsert) Then
    varInsert = ThisDrawing.Utility.GetPoint(Prompt:=vbCrLf & _
    "Select Insertion Point: ")
    End If
    If ThisDrawing.ActiveSpace = acModelSpace Then
    Set objTemp = ThisDrawing.ModelSpace.InsertBlock(varInsert, _
    strBlkName, dblScale, dblScale, dblScale, dblRotation)
    Else
    Set objTemp = ThisDrawing.PaperSpace.InsertBlock(varInsert, _
    strBlkName, dblScale, dblScale, dblScale, dblRotation)
    End If
    If objTemp.HasAttributes Then
    varAtts = objTemp.GetAttributes
    ThisDrawing.Utility.Prompt vbCrLf & _
    "Enter Attribute values" & vbCrLf
    For intCnt = LBound(varAtts) To UBound(varAtts)
    strPrompt = vbCr & "Enter <" & _
    varAtts(intCnt).TextString & "> "
    strReply = ThisDrawing.Utility.GetString(1, strPrompt)
    If strReply <> "" Then
    varAtts(intCnt).TextString = strReply
    End If
    Next
    End If
    Set VBD_InsertBlock = objTemp
    Exit_Here:
    Exit Function
    Err_Control:
    MsgBox Err.Description
    Resume Exit_Here
    End Function

    '//End Code Block


    --
    allfro - Chaos Coder Extraordinaire

    'site index' (http://www.vbdesign.net/) | please use [ vbcode]
    \"your_code_here\" [/vbcode ] code tags | be nice | 'augi'
    (http://tinyurl.com/ytk37) |'go babelfish' (http://tinyurl.com/2j7df)
     
    allfro, Feb 26, 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.