Calc & Autocad

Java, C++, C#, Delphi, ??? - Using the UNO bridges

Calc & Autocad

Postby PieroRa » Fri Sep 11, 2020 12:10 am

Hi to Everybody,
I'm trying to have access to Autodesk Autocad Application trough Calc, passing to Autocad some coordinates in order to drawn a simple rectangle just for test.
The below procedure has been developed inside CALC macro area but I have some problem, receiving an error messagge.
Here attached the code, and msg error window.

Code: Select all   Expand viewCollapse view
Sub Main
  Dim AutocadApp As Object
  Dim AutocadDoc As Object
  Dim RectArray(0 To 9) As Double
  Dim Rectangle As Object
  Dim oFactory, oApp, oSess, oFolder
  Dim oSheet As Object
  '****** Launch Autocad application****

  oSheets = ThisComponent.getSheets()
  oSheet = oSheets.getByIndex(0)
  oCell = oSheet.getCellByPosition(2, 5)
  oCell1 = oSheet.getCellByPosition(2, 6)
  Q=oCell.getValue()
  R=oCell1.getValue()
 
''****Point 1****
   RectArray(0) = 0
   RectArray(1) = 0
''****Point 2****
   RectArray(2) = Q
   RectArray(3) = 0
''****Point 3****
   RectArray(4) = Q
   RectArray(5) = R
''****Point 4****
   RectArray(6) = 0
   RectArray(7) = R

''****Point 5****
   RectArray(8) = 0
   RectArray(9) = 0
   
   oFactory = createUnoService("com.sun.star.bridge.oleautomation.Factory")
   oApp = oFactory.createInstance("Autocad.Application")
     oApp.Visible = True
''****Draw rectangle****
     Set AutocadDoc = oApp.ActiveDocument
    Set Rectangle = AutocadDoc.ModelSpace.AddLightWeightPolyline(RectArray)

End Sub

The application will be opened without problems, and seems that the empty drawing object retrieved but I have no confirmation of this.
The procedure hangs on " Set Rectangle = AutocadDoc.ModelSpace.AddLightWeightPolyline(RectArray) " even if syntax it's correct.
Here below the error message.
Attachments
error.jpg
Error Message
error.jpg (25.09 KiB) Viewed 823 times
OpenOffice 3.1 on Windows
PieroRa
 
Posts: 7
Joined: Tue Sep 08, 2020 7:53 pm

Re: Calc & Autocad

Postby JeJe » Fri Sep 11, 2020 1:43 am

Interesting code - adapting slightly it will launch and control Microsoft Word.

Unless someone here has Autocad they're not going to be able to look at the bit you have a problem with. I see you've been posting in the Autocad forum as well and this may be more a problem for there,

https://forums.autodesk.com/t5/vba/inte ... 71#M104257

All I can think of is have you tried testing the Polyline code in Autocad Basic? And then making sure the arrays of double data type in OO and Autocad are compatible?

Edit: And try cdbl in lines like here to ensure the data type isn't being changed to a variant or something else:
RectArray(2) = cdbl(Q)
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1498
Joined: Wed Mar 09, 2016 2:40 pm

Re: Calc & Autocad

Postby PieroRa » Fri Sep 11, 2020 7:15 am

Hi @JeJe thank you for reply, really the link you indicated it's the same project, always with Autocad by me.
On the opposite that code has been developed inside Autocad VBA, and it's working perfectly, opening a Calc Sheet, getting coordinates and drawn a rectangle.

What I'm trying to do now it's the opposite, developing the same procedure inside CALC with BASIC. The customer has already developed a lot of CALC functions so he prefer to use CALC, instead Autocad VBA,
Due to I'm not able to debug objects created (see oApp, main Autocad Application, and/or AutocadDoc which should be the empty drawing opened at the application start-up) I tried to use MRI but seems not working, probably I'm not able to use, or it could be not applicable in this case.

By the way, starting from the above error message and forgetting Autocad, and thinking as an OLE Object, are somebody able to give me some indication about the error message showed? Just to have an idea of where could be and what argument search.

Thank you
OpenOffice 3.1 on Windows
PieroRa
 
Posts: 7
Joined: Tue Sep 08, 2020 7:53 pm

Re: Calc & Autocad

Postby JeJe » Fri Sep 11, 2020 9:35 am

Once MRI is installed:

Code: Select all   Expand viewCollapse view
Globalscope.BasicLibraries.LoadLibrary( "MRILib" ) 'make sure the MRI library is loaded - you only need to do this once.

mri yourobject 'then put a line like this anywhere in your code
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1498
Joined: Wed Mar 09, 2016 2:40 pm


Return to External Programs

Who is online

Users browsing this forum: No registered users and 3 guests