locked
How to build a script file? RRS feed

  • Question

  • I have some problem finding out how to buld a script file. I would like to open Autocad with a script to batch multiple files. For this i need to build a large script (temp.scr) file and copy some content to it.

    I have a listbox where i can choose different files. The content of this file i would like to copy and paste it to the temporary temp.scr file. Lets say i choosen one file and it have a content like below

    ;Command:
    FILEDIA
    ;Enter new value for FILEDIA <1>:
    0
    ;------RITA LINJE
    ._LINE
    0,0
    2000,2000
    _QSAVE

    I have 3 .dwg files.

    • drawing1.dwg
    • drawing2.dwg
    • drawing3.dwg

    I want to make a temporary .scr file and run it with autocad.

    My goal is to make the file look like this. The first three rows is repeating before the contets of the script is pasted. This three rows would be nice to have inside my program so its easy to paste and change .dwg file name within a loop because the amount of dwg files always changes.

    Last row is always the same in the end.

    (if (findfile (strcat "C:/Users/andre/AppData/Local/Temp/_stopScript.now"))(command ".END"))
    (setq wf1 "C:/Temp/")
    (if (or (= (getvar "dbmod") 0) (= (getvar "dbmod") 32)) (command "_fileopen" (strcat wf1 "drawing1.dwg"))(command "_fileopen" "_yes" (strcat wf1 "drawing1.dwg")))
    ;Command:
    FILEDIA
    ;Enter new value for FILEDIA <1>:
    0
    ;------RITA LINJE
    ._LINE
    0,0
    2000,2000
    _QSAVE
    (if (findfile (strcat "C:/Users/andre/AppData/Local/Temp/_stopScript.now"))(command ".END"))
    (setq wf1 "C:/Temp/")
    (if (or (= (getvar "dbmod") 0) (= (getvar "dbmod") 32)) (command "_fileopen" (strcat wf1 "drawing2.dwg"))(command "_fileopen" "_yes" (strcat wf1 "drawing2.dwg")))
    ;Command:
    FILEDIA
    ;Enter new value for FILEDIA <1>:
    0
    ;------RITA LINJE
    ._LINE
    0,0
    2000,2000
    _QSAVE
    (if (findfile (strcat "C:/Users/andre/AppData/Local/Temp/_stopScript.now"))(command ".END"))
    (setq wf1 "C:/Temp/")
    (if (or (= (getvar "dbmod") 0) (= (getvar "dbmod") 32)) (command "_fileopen" (strcat wf1 "drawing3.dwg"))(command "_fileopen" "_yes" (strcat wf1 "drawing3.dwg")))
    ;Command:
    FILEDIA
    ;Enter new value for FILEDIA <1>:
    0
    ;------RITA LINJE
    ._LINE
    0,0
    2000,2000
    _QSAVE
    _quit _yes
    Thanks for your guidance in advance.

    Saturday, July 27, 2019 3:22 PM

Answers

All replies

  • This is surely a good excuse to hit the search tools for examples.

    As we're talking c#, you would be including your the Autodesk.AutoCAD modules?

    Or from AutoCAD.net NuGet package?

    Then take the easiest route of copy, paste & learn from examples you find down the back of the Internet, like this:

    https://www.keanw.com/2009/10/implementing-a-quick-saveas-command-in-autocad-using-net.html

    GitHub is a great source for AutoCAD code examples too.

    All the best,
    Pete


    #PEJL
    Got any nice code? If you invest time in coding an elegant, novel or impressive answer on MSDN forums, why not copy it over to TechNet Wiki, for future generations to benefit from! You'll never get archived again, and you could win weekly awards!

    Have you got what it takes o become this month's TechNet Technical Guru? Join a long list of well known community big hitters, show your knowledge and prowess in your favoured technologies!

    Saturday, July 27, 2019 5:08 PM
  • Actually im not including any Autocad module. I just want to build the script file and then start a autocad process with this file.

    Ive been searcing and one thing that comes up is to read all lines to a string array and then paste it. Or is it another way thats better ?
    Sunday, July 28, 2019 2:57 PM
  • Hi anhesweden,

    Thank you for posting here.

    Since this thread is not related to c#, I will move it to Where is the Forum For…? forum to redirect it to the correct forum.

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 29, 2019 3:10 AM
  • I'd try asking for help over here.

    https://forums.autodesk.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&q=scripting

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    • Proposed as answer by Guido Franzke Monday, July 29, 2019 5:52 AM
    • Marked as answer by pituachMVP Sunday, August 4, 2019 6:24 AM
    Monday, July 29, 2019 3:40 AM