Results 1 to 2 of 2

Thread: Excel to Autocad. AttachExternalReference

  1. #1
    Member
    Join Date
    2014-05
    Posts
    14
    Login to Give a bone
    0

    Default Excel to Autocad. AttachExternalReference

    Hi to all
    My name is Luigi
    I would like to excel by pasting a block in a drawing autocad.
    Using the manual ActiveX and VBA for autocad (200 I found this code, but it returns an error dialog at the end
    I use Excel 2012 (32bit) - Autocad Electrical 2015 (64bit) - Windows 7 (64bit)
    AutoCAD 2015 Type Library is included in the references
    I should have the opportunity 'to choose the block via a combobox, and paste the block in the current drawing
    I enclose the code that tells me error

    Module
    Code:
    Sub Ch10_AttachingExternalReference()
        On Error GoTo ERRORHANDLER
        Dim InsertPoint(0 To 2) As Double
        Dim insertedBlock As AcadExternalReference
        Dim tempBlock As AcadBlock
        Dim msg As String, PathName As String
        ' Define external reference to be inserted
        InsertPoint(0) = 1
        InsertPoint(1) = 1
        InsertPoint(2) = 0
        PathName = "C:/Autodesk/Smoke/E20.dwg"
        ' Display current Block information for this drawing
        GoSub ListBlocks
        ' Add the external reference to the drawing
        Set insertedBlock = ThisDrawing.ModelSpace.AttachExternalReference(PathName, "XREF_IMAGE", InsertPoint, 1, 1, 1, 0, False)
        ZoomAll
        ' Display new Block information for this drawing
        GoSub ListBlocks
        Exit Sub
    ListBlocks:
        msg = vbCrLf ' Reset message
        For Each tempBlock In ThisDrawing.Blocks
            msg = msg & tempBlock.Name & vbCrLf
        Next
        MsgBox "The current blocks in this drawing are: " & msg
        Return
    ERRORHANDLER:
        MsgBox Err.Description
    End Sub
    Button un form
    Code:
    Private Sub CommandButton2_Click()
    Ch10_AttachingExternalReference
    End Sub
    Error

    excel.PNG
    necessary object

    Can you help me solve this problem?
    thanks

  2. #2
    Member
    Join Date
    2014-05
    Posts
    14
    Login to Give a bone
    0

    Default Re: Excel to Autocad. AttachExternalReference

    For the error message I solved so

    Code:
    Sub lc_attach1()
        On Error GoTo ERRORHANDLER
        Dim Acad As AcadApplication
        Dim ThisDrawing As AcadDocument
        Dim InsertPoint(0 To 2) As Double
        Dim insertedBlock As AcadExternalReference
        Dim tempBlock As AcadBlock
        Dim msg As String, PathName As String
        ' Define external reference to be inserted
        Set Acad = GetObject(, "Autocad.Application")
        Set ThisDrawing = Acad.ActiveDocument
        InsertPoint(0) = 1: InsertPoint(1) = 1: InsertPoint(2) = 0
        PathName = "C:\Autodesk\Smoke\E20.dwg"
        ' Display current Block information for this drawing
        GoSub ListBlocks
        ' Add the external reference to the drawing
        Set insertedBlock = ThisDrawing.ModelSpace.AttachExternalReference(PathName, "XREF_IMAGE1", InsertPoint, 1, 1, 1, 0, False)
        ZoomAll
        ' Display new Block information for this drawing
        GoSub ListBlocks
        Exit Sub
    ListBlocks:
        msg = vbCrLf ' Reset message
        For Each tempBlock In ThisDrawing.Blocks
            msg = msg & tempBlock.Name & vbCrLf
        Next
        MsgBox "The current blocks in this drawing are: " & msg
        Return
    ERRORHANDLER:
        MsgBox Err.Description
    End Sub
    I explain why in the message of the references I also displays objects that are no longer 'in the drawing?

Similar Threads

  1. Replies: 11
    Last Post: Yesterday, 03:18 PM
  2. Replies: 5
    Last Post: 2013-10-16, 05:39 PM
  3. Replies: 1
    Last Post: 2012-08-08, 05:50 PM
  4. Replies: 1
    Last Post: 2009-04-29, 11:03 AM
  5. AttachExternalReference
    By cll in forum VBA/COM Interop
    Replies: 5
    Last Post: 2004-10-08, 08:57 AM

Posting Permissions

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