Create a New Drawing using vlax-invoke-method

Discussion in 'AutoCAD' started by petervose, Jun 9, 2004.

  1. petervose

    petervose Guest

    Hi,
    I'm attempting to understand the 'vlax-invoke-method' way of executing methods, but am having a few teething trouibles. My first attempt is to try to create a new blank drawing, and I entered the following:

    (vlax-invoke-method (vla-get-activeDocument (vlax-get-acad-object)) 'New "C:\\Program Files\\AutoCAD 2002\\Template\\acad.dwt")

    which fails miserably. Could someone please point out where I'm going wrong ? - SDI is set to 1, and I'm using 2k2 on WinXP Thanks Peter
     
    petervose, Jun 9, 2004
    #1
  2. petervose

    BillZ Guest

    This is what I do.

    (defun Q_new (/ acad acaddoc newdoc QnewTemplatePath)
    (vl-load-com)
    (setq acad (vlax-get-acad-object)
    )
    (setq acadDoc (vlax-get-property acad 'Documents)
    )
    ;;;
    (setq QnewTemplatePath "C:\\Documents and Settings\\wpz\\Local Settings\\Application Data\\Autodesk\\AutoCAD 2005\R16.1\\enu\\Template\\acad.dwt")
    ;;;
    (setq newDoc (vlax-invoke-method acadDoc 'Add QnewTemplatePath)
    )
    (if (/= newDoc nil)
    (vlax-invoke-method newDoc 'Activate)
    (prompt "\nFailed to create new drawing file.")
    )
    )

    Bill
     
    BillZ, Jun 9, 2004
    #2
  3. petervose

    petervose Guest

    Thans Bill, That's cleared it up. My confusion appears to have been the difference between

    (vlax-get-property (vlax-get-acad-object) 'Documents))
    and
    (vla-get-activeDocument (vlax-get-acad-object))

    I assume the first is the object containing all documents within the application, and the second is just the currently active document.
    Thanks again
    Peter
     
    petervose, Jun 9, 2004
    #3
  4. petervose

    BillZ Guest

    You're welcome.

    I got this form someone at the NG but I am poor at documenting sometimes and have lost the author.

    Bill
     
    BillZ, Jun 9, 2004
    #4
  5. petervose

    petervose Guest

    Bill, It works perfectly, but I've just noticed that it's designed to run when SDI is set to 0 so it will add a new document. In my case I have SDI set to 1 and consequently need to somehow dispose of the current document and create a new blank document, I assumed you need to use the "New" method, and not the "Add" method (as your earlier post). I assume there may be problems with disposing of the currently open document (decision on whether or not to discard changes) but I was hoping to somehow cover this within the code. The 'new' method fails and displays the following "(sys-error "ActiveX Server returned the error: unknown name: NEW")", although 'New' is documented in the help files:

    RetVal = object.New(TemplateFileName)
    Object
    Document
    The object or objects this method applies to.
    TemplateFileName
    String; input-only
    The full path and file name of the template file.
    RetVal
    Document object
    The newly created Document object.
    Remarks
    You should only call the New method from the Document object when working in SDI mode. When working in MDI mode, use the Add method on the Documents collection to create a new drawing.

    Any pointers would be great, but please don't lose any sleep over it as I'm just trying to use this as a way of learning, I can use the old ("Command "new"....) but it would be interesting to know where I'm going wrong.
    Cheers
    Peter
     
    petervose, Jun 9, 2004
    #5
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.