Draw lines in AutoCAD since LibreOffice Calc

asked 2020-09-08 18:45:11 +0100

jtm2020hyo gravatar image

Hello, I am trying to use a VBA for create lines since LibreOffice Calc to AutoCAD, I already tested the module in Excel and work perfectly, but now I want to try to run same VBA since LibreOffice Base, but I just have errors, Can someone help me to translate the VBA to Base please?

VBA module:

Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Option Explicit

Sub DrawRectangle()
  Dim AutocadApp As Object
  Dim AutocadDoc As Object
  Dim RectArray(0 To 9) As Double
  Dim Rectangle As Object

  '****** Launch Autocad application****
  On Error Resume Next
  Set AutocadApp = GetObject(, "Autocad.application")
  On Error GoTo 0

  If AutocadApp Is Nothing Then
  Set AutocadApp = CreateObject("Autocad.application")
  AutocadApp.Visible = True
  End If

 ''****Point 1****
   RectArray(0) = 0
   RectArray(1) = 0
 ''****Point 2****
   RectArray(2) = ActiveSheet.Range("C6")
   RectArray(3) = 0
 ''****Point 3****
   RectArray(4) = ActiveSheet.Range("C6")
   RectArray(5) = ActiveSheet.Range("C7")
 ''****Point 4****
   RectArray(6) = 0
   RectArray(7) = ActiveSheet.Range("C7")
 ''****Point 5****
   RectArray(8) = 0
   RectArray(9) = 0

 ''****Draw rectangle****
  On Error Resume Next
  Set AutocadDoc = AutocadApp.ActiveDocument
  On Error GoTo 0

  If AutocadApp Is Nothing Then
  Set AutocadDoc = AutocadApp.Document.App
  End If

  Set Rectangle = AutocadDoc.modelspace.addlightweightpolyline(RectArray)
    AutocadApp.ZoomExtents

Set Rectangle = Nothing
Set AutocadApp = Nothing
Set AutocadDoc = Nothing

End Sub

error:

BASIC runtime error. '1'

Type: com.sun.star.lang.WrappedTargetRuntimeException Message: [automation bridge] unexpected exception in IUnknownWrapper::invoke ! Message : [automation bridge]:
edit retag flag offensive close merge delete

Comments

The "IUnknownWrapper" part of the error message suggests to me that there is not any established connection between LibreOffice software and AutoCAD.

The logical path in my mind would be to do the programming in AutoCAD, and use the LibreOffice file as a data source only. Depending on context (which is not provided in the question), this may not be a viable path for the situation at hand. Please provide detail.

keme gravatar imagekeme ( 2020-09-09 07:56:29 +0100 )edit

@keme

I need an I/O data exchange between both, my first step is to translate thus vba to base and UNO, this vba just draw a rectangle with number in C6 and C7 cell...

If my request can not be possible, then how can I draw a line in AutoCAD since LibreOffice Calc?

jtm2020hyo gravatar imagejtm2020hyo ( 2020-09-09 10:33:59 +0100 )edit