Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
alan1959
Posts: 25
Registered: ‎12-14-2011
Message 1 of 2 (386 Views)

2DREP AutoLIsp Routine

386 Views, 1 Replies
07-03-2012 08:44 AM

My company wants to do the following:

1) open a subdirectory

2) open each drawing in that subdirectory

3) 2DREP the drawing

4) detach the XREF's

5) save the drawing

6) close the drawing

7) open the next drawing in the subdirectory

8) repeat steps 1-7 until all drawings have been processed

 

I can muddle through writing a lisp routine to do this but have no idea how to make it complete each drawing in the subdirectory. I can write a routine but theuser must open each drawing manually.

 

Any help would be appreciated.

Active Contributor
kefer.kb
Posts: 27
Registered: ‎08-17-2011
Message 2 of 2 (356 Views)

Re: 2DREP AutoLIsp Routine

07-03-2012 11:30 PM in reply to: alan1959

Hello,

i have some lisp files for modifying many drawings like plotting, change title-block, etc.

 

Here is a template for you:

 

;-------------------------------------------------------------------------
;globale Variablen
; INT:        int_lispinit    altueller Wert von 'lispinit'
; STRING:       str_pfad    Pfad fuer DWG-Verzeichniss
; LIST:        list_dwg    Liste mit allen DWG-Zeichnungsnamen ohne Pfad
;-------------------------------------------------------------------------
;Funktion
(defun c:functionname ( / int_lispinit str_pfad list_dwg)
  (vl-load-com)
 
  ;----- aktuelle Systemvariablenwerte sichern
  ;----- save system variables
  (setq old_lispinit (getvar "lispinit"))

  ;----- Systemvariablen veraendern
  ;----- modify ACAD variables
  (setvar "cmdecho" 0)          ;Command echo: aus
  (setvar "lispinit" 0)         ;LISP-Prg. Speicherresistent
  (setvar "sdi" 1)              ;Single Document Interface

  ;----- Abfrage: Verzeichnis mit getfiled
  ;----- Userinput: select directory with getfiled
  (setq str_pfad (gfm-getFolder "Ordner mit allen Zeichnungen zum Bearbeiten:" ""))

  ;----- Liste mit allen Zeichnungsnamen im Verzeichnis bilden
  ;----- create list with all drawings into directory
  (setq list_dwg (vl-directory-files str_pfad "*.dwg" 1))

  ;----- Schleife: Jede Zeichnung öffnen und bearbeiten
  ;----- loop: open each drawing and modify it
  (foreach str_Zeichnung list_dwg

    ;----- Zeichnung öffnen
    ;----- open dwg
    (if (> (getvar "DBMOD") 0)
      (command "_.open" "_y" (strcat str_pfad "\\" str_Zeichnung))
      (command "_.open" (strcat str_pfad "\\" str_Zeichnung))
    );endif

    ;----- Zeichnung bearbeiten
    ;----- modify drawing
    (<your-function>)

    ;----- Zeichnung speichern
    ;----- save drawing
    (command "_.qsave")

  );end foreach

  ;----- Systemvariablen-Werte wiederherstellen
  ;----- restore variables
  (setvar "sdi" 0)
  (setvar "lispinit" old_lispinit)
  (setvar "cmdecho" 1)

  (princ)
);enddefun
;-------------------------------------------------------------------------
;Titel:      GFM-GETFOLDER fuer ACAD2000-2008
;Erklaerung: Funktion öffnet den Windowsdialog zum Auswählen eines Verzeichnisses
;Datum:      Feb. 2009
;Autor:      Ing. Franz Kefer
;-------------------------------------------------------------------------
;lokale VARIABLEN
;VLA-Objekt:    objShell    Shell Objekt
;        folder        Ordner
;        objFolder    Ordner Objekt
; STRING:    str_Path    Ausgewählter Ordner(pfad)
;-------------------------------------------------------------------------
; AUFRUF:        (gfm-getFolder str_Kommentar str_rootDir)
; Argumente:    str_Kommentar    Kommentar im Windows Ordnerdialogfeld
;        str_rootDir    Vorgabeverzeichnis oder Laufwerk für Ordnerauswahl
;-------------------------------------------------------------------------
(defun gfm-getFolder (str_Kommentar str_rootDir / objShell folder objFolder str_Path)

  ;----- Vorbild aus VB
  ;set ShellApp=CreateObject("Shell.Application") 'erzeuge ein neues Objekt "Shell Application"
  ;set FolBrowser=ShellApp.BrowseForFolder(0,"Wähle einen Ordner",16,0) '16 = zusätzl. Ordnerfeld wird angezeigt
 
  ;----- VL-Extension laden
  (vl-load-com)

  ;----- Shell Objekt
  (if (setq obj_Shell (vla-getinterfaceobject (vlax-get-acad-object) "shell.application"))
    (progn
      ;----- Ordner Objekt bestimmen
      (setq folder (vlax-invoke-method obj_Shell 'browseforfolder 0 str_Kommentar 0 str_rootDir))
      ;----- Shell Objekt beenden
      (vlax-release-object obj_Shell)
      ;----- Ordnerpfad auslesen
      (if folder
    (progn
      (setq obj_Folder (vlax-get-property folder 'self))
      (setq str_Path (vlax-get-property obj_Folder 'path))
      (vlax-release-object obj_Folder)
      (vlax-release-object folder)
    );end progn
    ;ELSE
    (quit)
      );end if
    );endprogn
 );endif

  ;----- Rückgabewert
  str_Path
);enddefun

 

kind regards,

Franz

www.gfm.at
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.