AutoCAD VBScript Reference

Discussion in 'AutoCAD' started by Tim J, Feb 2, 2004.

  1. Tim J

    Tim J Guest

    Hi,

    Does anyone know of any reference at all for controlling AutoCAD with
    VBScript? Here is my problem, I have an application that writes VBScripts
    that launch AutoCAD and perform some drawing functions. During one function
    I need to translate some points from the OCS to WCS. I am trying to use the
    Utility.TranslateCoordinates Method. When I do this, I get a Windows Script
    Host error stating there is an Invalid agrument Point in
    TranslateCoordinates.

    Here is the code in the .vbs file:

    'acaddoc was set previous to this point to the current
    application.activedocument
    'and acadutility was set to the utility object of acaddoc
    AcadDoc.ActiveUCS=FrontSideUCS

    Dim TranslatedPt
    Dim CurrentPt(2)

    CurrentPt(0)=xdim/2
    CurrentPt(1)=.25
    CurrentPt(2)=0
    TranslatedPt=AcadUtility.TranslateCoordinates(CurrentPt, 1, 0, False)

    Since this is done through vbscript, I had errors that the From/To argument
    enum, so i changed it to the enum value. 1 = acUcs, 0 = acWorld

    Does anyone have any ideas on how the TranslatedPt line needs to read to be
    functional? When writing the .vbs file, all variables are declared, however
    no object type is defined for the variables. They are all considered by
    VBScript to be variants and I got errors when I used something like "Dim
    myString as String". I had to truncate it to "Dim myString".

    Any help is greatly appreciated either on how to fix this error, a
    workaround for the error (some otherway to calculate the WCS values for the
    OCS point), or a reference for AutoCAD and VBScript.

    Thank you.
     
    Tim J, Feb 2, 2004
    #1
  2. Try this:

    Dim TranslatedPt
    Dim CurrentPt

    Call AcadUtility.CreateTypedArray(CurrentPt, 5, xdim / 2, 0.25, 0)
    TranslatedPt = AcadUtility.TranslateCoordinates(CurrentPt, 1, 0, False)


    --
    Paul Marshall - Toot-OR

    When a wise man does not understand, he says: "I do not understand."
    The fool and the uncultured are ashamed of their ignorance.
    They remain silent when a question could bring them wisdom.
     
    Paul Marshall, Feb 2, 2004
    #2
  3. The values need to be Doubles so use CDbl too convert them before
    passing.
    ___________________________
    Mike Tuersley
    CADalyst's AutoCAD Clinic
    Rand IMAGINiT Technologies
     
    Mike Tuersley, Feb 2, 2004
    #3
  4. Tim J

    Tim J Guest

    Hi Paul,

    Thank you very much for the suggestion. I believe that it worked. I made a
    change to my script to test and I got a different error on a line past that,
    so it made it past that point without an error. I tried to have a msgbox
    appear right after that -- msgbox TranslatedPt(0) to verify the value,
    however that line produced a type mismatch error. I have some other issues
    with how the script is formated, however once I make those changes, I will
    be able to tell if it indeed worked, however so far it looks very promising.

    Thanks again for your help.
     
    Tim J, Feb 2, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.