PDA

View Full Version : Solved: insert autocad drawing according to cordiantes



shamsam1
09-18-2008, 09:37 PM
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

Tommy
09-19-2008, 05:21 AM
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?

shamsam1
09-19-2008, 06:44 AM
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

Tommy
09-19-2008, 08:20 AM
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. :yes

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. :banghead:

shamsam1
09-19-2008, 09:18 PM
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...

Tommy
09-20-2008, 09:16 AM
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.

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

Tommy
09-20-2008, 09:17 AM
I didn't close acad or excel.

shamsam1
09-22-2008, 09:28 PM
hi tommy

it working perfectly

:friends:

Tommy
09-25-2008, 04:31 AM
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.

shamsam1
09-25-2008, 06:14 AM
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...

shamsam1
09-25-2008, 06:23 AM
hi tommy

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

just hanged with my method of working

Tommy
09-25-2008, 06:59 AM
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.

shamsam1
09-25-2008, 08:54 AM
hi tommy

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

thanks for guiding me .....:bow:

Tommy
09-25-2008, 02:20 PM
No problem, as always if you need more help ask I'm around here somewhere.:ack: