Jump to content

Convert VBA Autocad to Autoit


 Share

Recommended Posts

Hi, can anyone help me, please? I need to "translate" this code in vba to autoit!

This is the VBA Code:

Sub Example_AddMtext()
    ' This example creates an MText object in model space.
    
    Dim MTextObj As AcadMText
    Dim corner(0 To 2) As Double
    Dim width As Double
    Dim text As String
    corner(0) = 0#: corner(1) = 10#: corner(2) = 0#
    width = 10
    text = "This is the text String for the mtext Object"

    ' Creates the mtext Object
    Set MTextObj = ThisDrawing.ModelSpace.AddMText(corner, width, text)
    ZoomAll
    
End Sub

I've Tried to do this:

$oAcad = ObjGet("","AutoCAD.Application.20")
If @error Then
    Msgbox(0,"ObjGet","Failed to open AutoCAD.Application.20 Object. Error code: " & hex(@error,8))
    Exit
Endif

_Add_MText($oAcad, 0, 10, "test")


Func _Add_MText($oAcad, $x, $y, $text, $width = 10)
   Local $aCoords[3] = [$x,$y,0]
   $oAcad.AcadMText.ThisDrawing.ModelSpace.AddMText($aCoords, $width, $text)
   Return 0
EndFunc

But i'm getting this error:

$oAcad.AcadMText.ThisDrawing.ModelSpace.AddMText($aCoords, $width, $text)
$oAcad^ ERROR

 

Can anyone give me a light, please?

Thanks a lot

Link to comment
Share on other sites

What is the full error message you see in the SciTE output pane?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

10 minutes ago, water said:

What is the full error message you see in the SciTE output pane?

"C:\Users\admin\Desktop\autocadtest.au3" (13) : ==> The requested action with this object has failed.:
$oAcad.AcadMText($oAcad.ThisDrawing.ModelSpace.AddMText($aCoords, $width, $text))
$oAcad.AcadMText($oAcad^ ERROR
>Exit code: 1    Time: 0.5987

 

 

thanks for your response!

Link to comment
Share on other sites

Maybe

$oAcad.Application.ActiveDocument.Modelspace.AddMTxt($aCoords, $width, $text)

or

$oAcad.ActiveDocument.Modelspace.AddMTxt($aCoords, $width, $text)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

59 minutes ago, water said:

Maybe

$oAcad.Application.ActiveDocument.Modelspace.AddMTxt($aCoords, $width, $text)

or

$oAcad.ActiveDocument.Modelspace.AddMTxt($aCoords, $width, $text)

 

Nothing =/

 

This example code works:

$strActiveDocument = $oAcad.Activedocument.Name
MsgBox(0,"$oAcad.Activedocument.Name",$strActiveDocument)

$iBlocks = $oAcad.Activedocument.Blocks.Count
MsgBox(0,"$oAcad.Activedocument.Blocks.Count",$iBlocks)
For $i = 0 to $iBlocks -1
    $strBlockName = $oAcad.Activedocument.Blocks.Item($i).name
    If $strBlockName = "TITLEBLOCK" Then
        $iAttributes = $oAcad.Activedocument.Blocks.Item($i).GetAttributes()
        MsgBox(0,"GetAttributes()",$iAttributes)
    EndIf
Next

But my code don't work =S

i've tried a lot of combination, but notting

Link to comment
Share on other sites

add COM Error handler and try this:

$oAcad = ObjGet("","AutoCAD.Application.20")
If @error Then
    Msgbox(0,"ObjGet","Failed to open AutoCAD.Application.20 Object. Error code: " & hex(@error,8))
    Exit
Endif

Local $oTest1 = $oAcad.AcadMText
ConsoleWrite('Test1:' & IsObj($oTest1))
ConsoleWrite('Test1:' & VarGetType($oTest1))
ConsoleWrite('Test1:' & ObjName($oTest1))

Local $oTest2 = $oAcad.AcadMText.ThisDrawing
ConsoleWrite('Test2:' & IsObj($oTest2))
ConsoleWrite('Test2:' & VarGetType($oTest2))
ConsoleWrite('Test2:' & ObjName($oTest2))

Local $oTest3 = $oAcad.AcadMText.ThisDrawing.ModelSpace
ConsoleWrite('Test3:' & IsObj($oTest3))
ConsoleWrite('Test3:' & VarGetType($oTest3))
ConsoleWrite('Test3:' & ObjName($oTest3))

_Add_MText($oAcad, 0, 10, "test")


Func _Add_MText($oAcad, $x, $y, $text, $width = 10)
   Local $aCoords[3] = [$x,$y,0]
   $oAcad.AcadMText.ThisDrawing.ModelSpace.AddMText($aCoords, $width, $text)
   Return 0
EndFunc

REMARK: AutoIt code created with forum editor - not tested .....

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

Testing one by one i'm getting the same error:

"C:\Users\rodol\Desktop\Novo(a) AutoIt v3 Script (3).au3" (8) : ==> The requested action with this object has failed.:
Local $oTest1 = $oAcad.AcadMText
Local $oTest1 = $oAcad^ ERROR

""C:\Users\rodol\Desktop\Novo(a) AutoIt v3 Script (3).au3" (10) : ==> The requested action with this object has failed.:
Local $oTest2 = $oAcad.AcadMText.ThisDrawing
Local $oTest2 = $oAcad^ ERROR"

 

 

Link to comment
Share on other sites

The first object after the application object ($oAcad) has to be a document. At least that's how I understand the object model: http://www.afralisp.net/reference/autocad-object-model.php#

So could you please try:

$oAcad = ObjGet("","AutoCAD.Application.20")
$oDoc = $oAcad.ActiveDocument
$oMS = $oDoc.Modelspace
$vTxt = $oMS.AddMTxt($aCoords, $width, $text)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

8 hours ago, water said:

The first object after the application object ($oAcad) has to be a document. At least that's how I understand the object model: http://www.afralisp.net/reference/autocad-object-model.php#

So could you please try:

$oAcad = ObjGet("","AutoCAD.Application.20")
$oDoc = $oAcad.ActiveDocument
$oMS = $oDoc.Modelspace
$vTxt = $oMS.AddMTxt($aCoords, $width, $text)

 

Nothing

I think I'm going to give up, I was wanting to create an autocad UDF but I do not think I'll be able to!

 

Thank you very much for the help

Link to comment
Share on other sites

Nothing? Not even error messages?

Before creating an AutoCad UDF you need to know how the COM object model works. And how this is implemented in AutoIt.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 2 years later...

Reviving this topic, as I'm also trying get AutoCAD communication going.

What I'm stuck with how to define "three-element array of doubles"

Quote

RetVal = object.AddPoint(Point)
object

Type: Block, ModelSpace, PaperSpace

The objects this method applies to.

Point

Access: Input-only

Type: Variant (three-element array of doubles)

The coordinates of the point to be created.

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2019/ENU/AutoCAD-ActiveX-Reference/files/GUID-265E706F-78E4-48C6-B1AB-66FD794BF230-htm.html

VBA:

Sub Example_AddPoint()
    ' This example creates a point in model space.
    Dim pointObj As AcadPoint
    Dim location(0 To 2) As Double
    
    ' Define the location of the point
    location(0) = 5#: location(1) = 5#: location(2) = 0#
    
    ' Create the point
    Set pointObj = ThisDrawing.ModelSpace.AddPoint(location)
    ZoomAll
    
End Sub

Autoit:

Dim $location[3] = [5,5,0]
$oAcad = ObjGet("","AutoCAD.Application")
$oAcad.ActiveDocument.Modelspace.AddPoint($location)

Getting error:

Quote

1.au3" (3) : ==> The requested action with this object has failed.:
$oAcad.ActiveDocument.Modelspace.AddPoint($location)
$oAcad.ActiveDocument.Modelspace^ ERROR

 

Link to comment
Share on other sites

as first step try this:

_Example()
Func _Example()
    Local $location[3] = [5,5,0]
    Local $oAcad = ObjGet("","AutoCAD.Application")
    If @error Then MsgBox($MB_ICONERROR, 'ObjGet', '@error = ' & @error & @CRLF & '@extended = ' & @extended)
    $oAcad.ActiveDocument.Modelspace.AddPoint($location)
EndFunc

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

ObjGet doesn't produce the error, it fails during execution of AddPoint(), therefor no message box shown.

So with error handler I get this:

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Local $location[3] = [5,5,0]
Local $oAcad = ObjGet("","AutoCAD.Application")
$oAcad.ActiveDocument.Modelspace.AddPoint($location)

Func _ErrFunc($oError)
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF)
EndFunc   ;==>_ErrFunc
Quote

1.au3 (5) : ==> COM Error intercepted !
    err.number is:         0x80020009
    err.windescription:    Exception occurred.

    err.description is:     
    err.source is:         
    err.helpfile is:     
    err.helpcontext is:     0
    err.lastdllerror is:     0
    err.scriptline is:     5
    err.retcode is:     0x80070057

 

Again, not much useful information, but definitely correct function name..so it must be wrong datatype of $location variable used with AddPoint() function.

Edited by VAN0
Link to comment
Share on other sites

like this:
 

_Example()

Func _Example()
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

    Local $location[3] = [5,5,0]
    Local $oAcad = ObjGet("","AutoCAD.Application")
    Local $oActiveDocument = $oAcad.ActiveDocument
    If @error Then MsgBox($MB_ICONERROR, '$oAcad.ActiveDocument', '@error = ' & @error & @CRLF & '@extended = ' & @extended)

    Local $oModelspace = $oActiveDocument.Modelspace.AddPoint($location)
    If @error Then MsgBox($MB_ICONERROR, '$oActiveDocument.Modelspace.AddPoint', '@error = ' & @error & @CRLF & '@extended = ' & @extended)

    $oModelspace.AddPoint($location)
    If @error Then MsgBox($MB_ICONERROR, '$oModelspace.AddPoint', '@error = ' & @error & @CRLF & '@extended = ' & @extended)
    
EndFunc

Func _ErrFunc($oError)
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF)
EndFunc   ;==>_ErrFunc

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

You are passing Integers whereas the function expects Doubles.

Global $iInt = 1, $fFloat = 1.0
MsgBox(0, "Integer", "$iInt: " & VarGetType($iInt) & @CRLF & "$fFloat: " & VarGetType($fFloat))

So i think you should use:

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Local $location[3] = [5.0, 5.0, 0.0]
Local $oAcad = ObjGet("","AutoCAD.Application")
$oAcad.ActiveDocument.Modelspace.AddPoint($location)

Func _ErrFunc($oError)
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF)
EndFunc   ;==>_ErrFunc

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@water still same error. So far I've tried send it as text, as autocad "array" - "(5.0,5.0,0.0)" each time same type of error.

@mLipok

Two popups:

image.png.0db04992e0de43b7eb40acd4949cb364.pngimage.png.c4f96a4e22c68b2f5524a9da2e0f3dad.png

 

Quote

1.au3 (11) : ==> COM Error intercepted !
    err.number is:         0x80020009
    err.windescription:    Exception occurred.

    err.description is:     
    err.source is:         
    err.helpfile is:     
    err.helpcontext is:     0
    err.lastdllerror is:     0
    err.scriptline is:     11
    err.retcode is:     0x80070057
1.au3 (14) : ==> COM Error intercepted !
    err.number is:         0x000000A9
    err.windescription:    Variable must be of type 'Object'.
    err.description is:     
    err.source is:         
    err.helpfile is:     
    err.helpcontext is:     
    err.lastdllerror is:     0
    err.scriptline is:     14
    err.retcode is:     0x00000000

 

Link to comment
Share on other sites

Get some more detailed error information by combining what we already have:

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
Local $location[3] = [5.0, 5.0, 0.0]
Local $oAcad = ObjGet("","AutoCAD.Application")
Local $oActiveDocument = $oAcad.ActiveDocument
If @error Then Exit MsgBox(0, "Error", "ActiveDocument returned: @error(hex) = " & Hex(@error) & ", @extended = " & @extended)
Local $oModelSpace = $oActiveDocument.Modelspace
If @error Then Exit MsgBox(0, "Error", "ModelSpace returned: @error(hex) = " & Hex(@error) & ", @extended = " & @extended)
$oModelSpace.AddPoint($location)
If @error Then Exit MsgBox(0, "Error", "AddPoint returned: @error(hex) = " & Hex(@error) & ", @extended = " & @extended)

Func _ErrFunc($oError)
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF)
EndFunc   ;==>_ErrFunc

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@water It doesn't show any more information then the previous attempts. It shows AdPoint failed and that's all.

If I remove everything after it's name

$oAcad.ActiveDocument.Modelspace.AddPoint

it shows this error
 

Quote

 

1.au3 (5) : ==> COM Error intercepted !
    err.number is:         0x8002000E
    err.windescription:    Invalid number of parameters.

    err.description is:     
    err.source is:         
    err.helpfile is:     
    err.helpcontext is:     
    err.lastdllerror is:     0
    err.scriptline is:     5
    err.retcode is:     0x00000000

 

Which, I think, only proves that datatype in $location variable is wrong.

Link to comment
Share on other sites

7 hours ago, VAN0 said:

1.au3 (11) : ==> COM Error intercepted !
    err.number is:         0x80020009
    err.windescription:    Exception occurred.

    err.description is:     
    err.source is:         
    err.helpfile is:     
    err.helpcontext is:     0
    err.lastdllerror is:     0
    err.scriptline is:     11
    err.retcode is:     0x80070057

0x80070057 stands for E_INVALIDARG

I searched the web for "HRESULT 0x80070057 autocad". Got a few hits but nothing seems to describe the problem.
Then i searched the forum for the HRESULT. I think the following post (read the last few lines) describes what goes on. It seems to be an internal conversion problem with AutoIt and AutoCAD expecting a different format. Unfortunately what @LarsJ descibes is way over my head. Maybe he has a solution for this problem.

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Credit for identifying the problem.

AutoIt arrays are internally stored as safearrays of variants where the array type is VT_ARRAY + VT_VARIANT.

If you create an AutoIt array of doubles this way

Local $aDoubles = [ 5.0, 5.0, 0.0 ]

then $aDoubles is stored as a safearray of 3 variants where each variant contains a double. This means that the type of the variant is VT_R8 which is the same as double, and the data of the variant is the value of the double. The type of the safearray is still VT_ARRAY + VT_VARIANT.

But AddPoint method does not take a safearray of variants as input. It takes a safearray of doubles as input. That is a safearray of type VT_ARRAY + VT_R8. That's the reason for the invalid argument error.

Although it is possible to create a safearray of doubles in AutoIt with Windows API functions, it's not possible to pass the array to the AddPoint method because of the internal COM conversions that only work for safearrays of variants.

To avoid the internal COM conversions you can call AddPoint directly with DllCallAddress() through a pointer to the method. You can get this pointer in the VTABLE, and of course you also need a pointer directly to the VTABLE.

Although you can find all the details in the link above, it's very tricky. It appears to be easier to use VBA code.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...