Consulting

Results 1 to 14 of 14

Thread: Solved: insert autocad drawing according to cordiantes

  1. #1
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location

    Solved: insert autocad drawing according to cordiantes

    I have excel in which i have drawing details with x,y,coordinates.
    using vb i need to insert part drawings in autocad according to coordinates...can any 1 help me in this regard
    Last edited by shamsam1; 09-19-2008 at 01:57 AM.

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Can you post a sample excel file?
    Do you have the full path to the blocks?
    Is Acad open?
    Is Excel Open?
    DO you have anything as in code yet?

  3. #3
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    i have attached sample excel sheet

    from vb i just need to call the particular excel then part drawings short be placed according to the cordinates in autocad.

    autocad will be running..
    still i don't have code..still dotn know how to start with

  4. #4
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    OK I have the sample sheet. What I need to know now is are you using VBA from Excel or Acad or are you actually using VB (as in a stand alone program). I ask these questions because it will make a difference on how I code it.

    You will need the path to the blocks. If the path is not there it will look for the block in the directory that the program is working in. If it doesn't find the block there it will throw errors and will not work.

  5. #5
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    hi tommy
    i will use vb.6 from that i wll communicated with autocad.
    from vb i wll call excel sheet based on drawing,all the part drawing will be already there in the drawing .i need need to call excel sheet and assemble the drawings arrording to the cordianes in autocad.like intraction bettwen vb ,excel and autocad
    ..from vb i wll call excel sheet the palce drawings according to the coordinatesin autocad...

  6. #6
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    The path must be included for the blocks if they are not already in the drawing. The path to the main drawing must be include. As you should be able to tell the path I used for testing is "C:\Testing". If you know fro a fact that the main drawing will have all the blocks inbedded in the drawing then the path MAY not be required.
    [vba]
    Sub Main()
    Dim AcadApp As AcadApplication, WrkBk As Workbook, WrkSh As Worksheet
    Dim ExcelApp As Excel.Application, Dwg As AcadDocument, mI As Long
    Dim Blk As String, X As Double, Y As Double
    GetAcad AcadApp
    OpenDWG AcadApp, "C:\Testing\Drawing1.dwg", Dwg
    GetExcel ExcelApp
    OpenXls ExcelApp, "C:\Testing\block.xls", WrkBk
    ActivateSh1 WrkBk, WrkSh
    mI = 5
    While CStr(WrkSh.Cells(mI, 2).Value) <> "-"
    Blk = CStr(WrkSh.Cells(mI, 2).Value)
    X = CDbl(WrkSh.Cells(mI, 3).Value)
    Y = CDbl(WrkSh.Cells(mI, 4).Value)
    InsBlk Dwg, Blk, X, Y
    mI = mI + 1
    AcadApp.ZoomExtents
    Wend
    AcadApp.ZoomAll
    End Sub
    Sub InsBlk(iDWG As AcadDocument, iBlock As String, iX As Double, iy As Double)
    Dim pts(0 To 2) As Double
    pts(0) = iX: pts(1) = iy: pts(2) = 0
    iDWG.ModelSpace.InsertBlock pts, "C:\Testing\" & iBlock & ".dwg", 1#, 1#, 1#, 0#
    End Sub
    Sub OpenDWG(iAcadApp As AcadApplication, iDwgNm As String, ioDWG As AcadDocument)
    Dim mI As Long, IsThere As Boolean
    For mI = 0 To iAcadApp.Documents.Count - 1
    If iAcadApp.Documents(mI).Name = Right(iDwgNm, Len(iDwgNm) - InStrRev(iDwgNm, "\")) Then
    IsThere = True
    Set ioDWG = iAcadApp.Documents(mI)
    End If
    Next
    If Not IsThere Then
    Set ioDWG = iAcadApp.Documents.Open(iDwgNm)
    ioDWG.Activate
    End If
    End Sub
    Sub ActivateSh1(ioWrkBk As Workbook, iActSht As Worksheet)
    ioWrkBk.Worksheets("Sheet1").Activate
    Set iActSht = ioWrkBk.Worksheets("Sheet1")
    End Sub
    Sub OpenXls(iXlApp As Excel.Application, iWrkBkNm As String, ioWrkBk As Workbook)
    Dim mI As Long, IsThere As Boolean
    For mI = 1 To iXlApp.Workbooks.Count
    If iXlApp.Workbooks(mI).Name = Right(iWrkBkNm, InStrRev(iWrkBkNm, "\")) Then
    IsThere = True
    Set ioWrkBk = iXlApp.Workbooks(mI)
    End If
    Next
    If Not IsThere Then
    Set ioWrkBk = iXlApp.Workbooks.Open(iWrkBkNm)
    End If
    End Sub
    Sub GetAcad(iAcadApp As AcadApplication)
    On Error Resume Next
    Set iAcadApp = GetObject(, "AutoCAD.Application")
    If Err.Number > 0 Then
    Err.Clear
    Set iAcadApp = CreateObject("AutoCAD.Application")
    End If
    iAcadApp.Visible = True
    On Error GoTo 0
    End Sub
    Sub GetExcel(iExcelApp As Excel.Application)
    On Error Resume Next
    Set iExcelApp = GetObject(, "Excel.Application")
    If Err.Number > 0 Then
    Err.Clear
    Set iExcelApp = CreateObject("Excel.Application")
    End If
    iExcelApp.Visible = True
    On Error GoTo 0
    End Sub

    [/vba]

  7. #7
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I didn't close acad or excel.

  8. #8
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    hi tommy

    it working perfectly


  9. #9
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Dwg.ModelSpace.InsertBlock pts, iBlock, 1#, 1#, 1#, 0#
    The first 1 is the X scale factor, the second 1 is for the Y scale factor, the third 1 is for the Z scale factor, and the 0 is the rotation.

    When it says object required this means that Dwg is not defined correctly.

    The include zip file has all of the drawings I used for testing. I have a directory on the hard drive called testing ("C:\Testing") where all of the drawings are filed. This is in acad 2007 version. I have references for acad and excel set in the project.

  10. #10
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    hi tommy

    for testing i was using autocad2006..also i have created part1.dwg ,part2.dwg in main drawings1file. i mean i have place this drawings in layer ..and name the layer part1,part2,part3..
    i was trying this method...

    in main drawing1.dwg file only i will be having all part drawings ..i need to place that part drawings according to cordinates.

    i will install acotcad2007 soon and will test...

  11. #11
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    hi tommy

    i have tested by ur method..and its working fine.......

    just hanged with my method of working

  12. #12
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Sam I believe the only problem with your method is you didn't have the folder correct in the code. At least that is what it sound like to me. The version of acad shouldn't make a difference. I would advise for you to use late binding due to it would most likely be version independant.

  13. #13
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    hi tommy

    i didn't had part drawings in the folder...as i was trying with drawing1.dwg only..

    thanks for guiding me .....

  14. #14
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    No problem, as always if you need more help ask I'm around here somewhere.

Posting Permissions

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