Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: i need help with using open command in autolisp

  1. #1
    Member
    Join Date
    2009-04
    Posts
    9
    Login to Give a bone
    0

    Default i need help with using open command in autolisp

    if we assume that there is a dwg file "dwg_name" in the following path "D:\work"

    i know that you should use double backslash "\\" ,in order to autolisp can recognize it as "\"

    but when i use the following expression ,it returns "unknown command (dwg_path)"


    (command "open" "D:\\work\\dwg_name")

  2. #2
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: i need help with using open command in autolisp

    I think the OPEN command as some problems when used through Lisp. You may have to look into the ActiveX functions instead. E.g.
    Code:
    (setq acad (vlax-get-acad-object)) ;Get COM object of AutoCAD
    (setq docs (vla-get-Documents acad)) ;Get documents collection
    (vla-Open docs "D:\\work\\dwg_name.dwg" nil nil) ;Open the DWG (not read only & without a password)
    Note that the DWG is opened, but the previously opened DWG is still active. LISP doesn't work easily between separate DWG's, for that VBA works better. There are some tricks, especially using Scripts, but they have limitations of their own.

  3. #3
    Member
    Join Date
    2009-04
    Posts
    9
    Login to Give a bone
    0

    Default Re: i need help with using open command in autolisp

    i have tried the code you had written ,and it works
    but the problem is i know autolisp better than activeX
    so let me ask you a question if you please
    *i didn't find (vla-get-Documents,vla-Open) functions in developer help,so pls give me a short explanation.

    thank you very much in any way

  4. #4
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: i need help with using open command in autolisp

    If you look in the Dev Help under "AutoLISP Developer's Guide" --> "Using the Visual LISP Environment" --> "Working with ActiveX" and its sub folders you'll see that all COM / ActiveX libraries have these functions.

    Now to see what functions are available you need to see the VBA / ActiveX help as well. Each object in the object model has properies & methods (they've got events as well, but these can't be used through Lisp - only in VBA). For each Property there's 2 Lisp functions created (vla-get-PropertyName obj) to get the value of the property and (vla-put-PropertyName obj value) to set the value of the property. For each method a (vla-MethodName obj [variables list]) function is available.

    So as a "short description" the (vla-get-Documents acad) obtains the property named Documents from the object in the acad variable. This "property" is another object containing all open documents, this type of object is called a collection.

    The Documents collection object has a method called Open, so the (vla-Open docs ...) function calls this method.

  5. #5
    I could stop if I wanted to msretenovic's Avatar
    Join Date
    2002-02
    Location
    Galloway, Oh
    Posts
    305
    Login to Give a bone
    0

    Cool Re: i need help with using open command in autolisp

    Quote Originally Posted by MHSS View Post
    i have tried the code you had written ,and it works
    but the problem is i know autolisp better than activeX
    so let me ask you a question if you please
    *i didn't find (vla-get-Documents,vla-Open) functions in developer help,so pls give me a short explanation.

    thank you very much in any way
    Another way to find information on these functions is through Apropos in the VLIDE. Press Ctrl+Shift+A to open the Apropos options box. From here, you can put in the name of a command. Once you click the OK button, the Apropos results box is displayed. From here, select the command and click the Help button. If the command is in the Help system, it will bring it right up for you.

    One note about the VL* functions, the help pages that are brought are the help pages for VBA. You will need to 'convert' the function signature to VLISP before you can use it - but it's REALLY easy. Simply take the 'OBJECT' part of the VBA function signature and make it the first argument to the VLISP function. Using VLA-GET-ACTIVEDOCUMENT as an example, here is what you will find and what you will do to use it:
    From help you will get this:
    ActiveDocument Property

    Specifies the active document (drawing file).
    Signature
    object.ActiveDocument
    object
    Application
    The object this property applies to.
    ActiveDocument
    Document object; read-write
    The default is drawing.dwg.
    From the description, you can see that the OBJECT is an Application object (you can get the Application object from VLAX-GET-ACAD-OBJECT). Also, you will notice that it is a property of the Application object and that it can be read or written. Because this is a property, it means we can use either VLA-GET- or VLA-PUT- in front of the property name to use it.

    So, to get the current drawing (ActiveDocument), we use VLA-GET-ACTIVEDOCUMENT as shown below:
    Code:
    (setq objDoc (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
    *Note: Using VLA-PUT-ACTIVEDOCUMENT may not work in VLISP as VLISP is limited in scope to the current drawing.

    After doing this conversion process on the function signature a couple of times, it won't be anything that you even think about any more.

    HTH

  6. #6
    Member
    Join Date
    2009-04
    Posts
    9
    Login to Give a bone
    0

    Default Re: i need help with using open command in autolisp

    THANKS, TO ALL YOUR GENEROUS REPLIES

    AND I AM WAITING FOR ANY INFO. ABOUT USING "OPEN" COMMAND

    THANKS AGAIN

  7. #7
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: i need help with using open command in autolisp

    Quote Originally Posted by MHSS View Post
    ... I AM WAITING FOR ANY INFO. ABOUT USING "OPEN" COMMAND
    You cannot use (command "._Open"). That is what we are telling you.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  8. #8
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: i need help with using open command in autolisp

    Just as a suggestion (I know we using CAD sometimes have the Caps Lock on): Posting in Capitals is considered shouting ... so my ears hurt

    But both msretonovic and RobertB are correct, the open command won't work through Lisp. You can have a script file which contains the Open command and then run that with a (command "._SCRIPT" ...). That's the original way people got round Lisp's limitation of only working on the current drawing.

    BTW, if you want to do something on the newly opened drawing, you'll need some trick like using a SCR file, or more efficiently use some other programming language. VBA works reasonably well with multi files, or more effectively look into .NET and program in VB.NET or C#.

  9. #9
    Member
    Join Date
    2009-04
    Posts
    9
    Login to Give a bone
    0

    Default Re: i need help with using open command in autolisp

    as i work in a consultant office , we always make changes on the number of project files and (lod) list of drawing
    so i wanted to make a lisp routine does this for me,


    **i succeeded in doing the first part, which is renaming the external dwg files


    ***secondly i wanted to rename the internal dwg name in the layout frame,and it works in an opened file , therefore i want to add a function to open the files
    Last edited by MHSS; 2009-10-12 at 08:41 AM. Reason: [code] tags added

  10. #10
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: i need help with using open command in autolisp

    In both cases (actually in both together) I'd suggest using ScriptPro (free download from ADesk). Then create a SCR file which contains the commands you'd have entered to run this code, e.g.
    Code:
    (load "lispfilename")
    QQ
    QSAVE
    Then in ScriptPro select the DWG file you want this to run on and let it open each and run the code.

    If you can't use ScriptPro (e.g. due to AC or OS version) you could generate a SCR file which opens each DWG, performs the QQ, saves & closes. You could generate the SCR out of lisp and then run it using the SCRIPT command. Search this forum, I think someone's already made such a lisp which allows you to select DWG's and then runs a selected SCR / LSP on each.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 10
    Last Post: 2015-06-19, 04:52 PM
  2. command Circle>Tan Tan Radius Autolisp
    By TUD_DUT in forum AutoLISP
    Replies: 1
    Last Post: 2012-10-23, 09:23 PM
  3. Help with using wblock command in AutoLisp format.
    By vladimir.karatsupa982899 in forum AutoLISP
    Replies: 3
    Last Post: 2012-07-24, 10:45 PM
  4. Block command in an AutoLISP script.
    By identity4 in forum AutoLISP
    Replies: 3
    Last Post: 2012-05-22, 04:48 AM
  5. AutoLISP command causes script to stop...
    By FWSchreck in forum AutoLISP
    Replies: 4
    Last Post: 2007-01-20, 12:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •