Message 1 of 5
Insert Raster image-VBA-AutoCAD-Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi. I have this code:
Private Sub CommandButton1_Click()
Dim imgInsertionPoint(0 To 2) As Double
Dim img As AcadRasterImage
Dim xmlDoc As MSXML2.DOMDocument60
Dim xmlHttp As MSXML2.XMLHTTP60
Dim fso As New FileSystemObject
Dim folderPath As String, filePath As String, imageUrl As String
Dim Lat As Double, lng As Double
imgInsertionPoint(0) = 0: imgInsertionPoint(1) = 0: imgInsertionPoint(2) = 0
' Pedir al usuario las coordenadas de latitud y longitud
Lat = -6.323831: lng = -51.14445
' Descargar imagen del mapa en línea
Set xmlDoc = New MSXML2.DOMDocument60
Set xmlHttp = New MSXML2.XMLHTTP60
xmlHttp.Open "GET", "http://maps.google.com/maps/api/staticmap?center=" & Lat & "," & lng & "&zoom=16&size=640x480&maptype=satellite&sensor=false", False
xmlHttp.send
xmlDoc.LoadXML xmlHttp.responseText
' Crear carpeta temporal
folderPath = "C:\Users\PC\Desktop\Temp\"
If Not fso.FolderExists(folderPath) Then
fso.CreateFolder folderPath
End If
' Guardar imagen en carpeta temporal
filePath = folderPath & "imagen.png"
Dim outputStream As Object
Set outputStream = CreateObject("ADODB.Stream")
outputStream.Type = 1 ' Tipo binario
outputStream.Open
outputStream.Write xmlHttp.responseBody
outputStream.SaveToFile filePath, 2 ' 2 = ADODB.StreamSaveMode.adSaveCreateOverWrite
' Insertar imagen en AutoCAD
Set img = ThisDrawing.ModelSpace.AddRaster(filePath, imgInsertionPoint, 1, 0)
MsgBox "listo"
End Sub
but "filepath" is a invalid input. Can you help me?
jefferson