Author Topic: Only one  (Read 3112 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
Only one
« on: November 24, 2006, 12:46:28 AM »
Hi Alls,
To day I just created a program lisp to save as a drawing until 26 time,that drawing (Title-A.dwg) only contain a string,it's "A" letter,then with that program lisp would save as a Title-B.dwg...Title-C.dwg...Title-D.dwg...etc,and that string should change too from "A" to "B"..."C"..."D"..etc,here this code.
This code is work well,the problem is if user load that program only create one dwg,I want 26 dwg (or A to Z.dwg)
Code: [Select]
; sdaz is stand for Saveas Drawing A to Z
;        Design by  : Adesu <Ade Suharna>
;        Email      : mteybid@yuasabattery.co.id
;        Homepage   : http://www.yuasa-battery.co.id
;        Create     : 24 November 2006
;        Program no.: 0471/11/2006
;        Edit by    :
(defun c:sdaz (/ cnt ed ext_name fol new_file new_name
       new_str new_xcnt num_str ss sse ssn str
       str_num title xcnt xdwg)
  (vl-load-com)
  (setq fol "D:/YBI/Drawing/Data Base/Xref/TITLE/")     
  (setq xdwg (getvar "dwgname"))                         
  (setq cnt 0)                                           
  (repeat
    26
    (setq title (substr xdwg 7 1))                       
    (if
      (= title (chr (+ 65 cnt)))                         
      (progn
(setq ext_name (vl-string->list title))         
(setq cnt 1)                                     
(setq str_num (vl-string->list "A"))             
(setq xcnt (read (strcat "(" (itoa cnt) ")")))     
(setq new_xcnt (append str_num xcnt))                     
(setq new_str (apply '+ new_xcnt))                         
(setq num_str (chr new_str))                         
(setq new_name (strcat "Title-" num_str ".dwg"))
(setq new_file (strcat fol new_name))
(setq ss (ssget "x" '((0 . "TEXT"))))
(setq ssn (ssname ss 0))             
(setq sse (entget ssn))
(setq str (cdr (assoc 1 sse)))       
(if
  (= str title)
  (progn
    (setq ed (subst (cons 1 num_str)(assoc 1 sse) sse))
    (entmod ed)
    (command "_saveas" "2000" new_file "")
    )                                            ; progn
  )                                              ; if
(setq cnt (1+ cnt))
)                                                ; progn
      )                                                  ; if
    )                                                    ; repeat
  (princ)
  )                                                      ; defun       


Adesu

  • Guest
Re: Only one
« Reply #1 on: November 24, 2006, 01:23:13 AM »
Oops,sorry.
it's need add a little,here new complited code
Code: [Select]
; sdaz is stand for Saveas Drawing A to Z
;        Design by  : Adesu <Ade Suharna>
;        Email      : mteybid@yuasabattery.co.id
;        Homepage   : http://www.yuasa-battery.co.id
;        Create     : 24 November 2006
;        Program no.: 0471/11/2006
;        Edit by    :
(defun c:sdaz (/ cnt ed ext_name fol new_file new_name
       new_str new_xcnt num_str ss sse ssn str
       str_num title xcnt xdwg)
  (vl-load-com)
  (setq fol "D:/YBI/Drawing/Data Base/Xref/TITLE/")  ; "D:/YBI/Drawing/Data Base/Xref/TITLE/"     
  (setq xdwg (getvar "dwgname"))                     ; "Title-B.dwg"
  (setq cnt 0)                                       ; 0
  (repeat
    26
    (setq title (substr xdwg 7 1))                   ; "B"
    (setq num_title (car (vl-string->list title)))   ; 66
    (if
      (= title (chr (+ num_title cnt)))                  ; T
      (progn
(setq ext_name (vl-string->list title))          ; (66)
(setq cnt (1+ cnt))                              ; 1
(setq str_num (vl-string->list title))           ; (66)
(setq xcnt (read (strcat "(" (itoa cnt) ")")))   ; (1)
(setq new_xcnt (append str_num xcnt))            ; (66 1)
(setq new_str (apply '+ new_xcnt))               ; 67
(setq num_str (chr new_str))                     ; "C"
(setq new_name (strcat "Title-" num_str ".dwg")) ; "Title-C.dwg"
(setq new_file (strcat fol new_name))            ; "D:/YBI/Drawing/Data Base/Xref/TITLE/Title-C.dwg"
(setq ss (ssget "x" '((0 . "TEXT"))))            ; <Selection set: 4>
(setq ssn (ssname ss 0))                         ; <Entity name: 7ef8e038>
(setq sse (entget ssn))
(setq str (cdr (assoc 1 sse)))                   ; "B"
(if
  (= str title)                                  ; T
  (progn
    (setq ed (subst (cons 1 num_str)(assoc 1 sse) sse))
    (entmod ed)
    (command "_saveas" "2000" new_file "")
    )                                            ; progn
  )                                              ; if
(setq cnt (1+ cnt))
)                                                ; progn
      )                                                  ; if
    )                                                    ; repeat
  (princ)
  )                                                      ; defun

mohobrien

  • Guest
Re: Only one
« Reply #2 on: November 26, 2006, 12:41:42 PM »
Basically same idea. It would work better if you opened a blank drawing and queried in what you have in your "Title-A" drawing.
I don't understand why you would want to grab text only. Isn't Title-A just a template for all the drawings? What did I miss?

Code: [Select]
(defun c:test
       (/ dwg_suffix dwg_path dwg_name dwg_name_base n old_expert)
  (vl-load-com)
(setq old_expert (getvar "EXPERT")) ; allows overwriting files without confirmation!
(setvar "EXPERT" 5)
  (setq dwg_suffix
(list "B"   "C"   "D" "E"   "F"   "G"   "H" "I"   "J"
       "K"   "L"   "M" "N"   "O"   "P"   "Q" "R"   "S"
       "T"   "U"   "V" "W"   "X"   "Y"   "Z"
      )
  )
  (setq dwg_path
(vl-filename-directory
   (vla-get-fullname
     (vla-get-ActiveDocument (vlax-get-acad-object))
   )
)
dwg_name (vl-filename-base
   (vla-get-fullname
     (vla-get-ActiveDocument (vlax-get-acad-object))
   )
)
  )
  (setq dwg_name_base (substr dwg_name 1 (- (strlen dwg_name) 1)))
  (setq n 0)
  (while (< n (length dwg_suffix))
    (command "SAVEAS"
     "2000"
     (strcat dwg_path
     "\\"
     dwg_name_base
     (nth n dwg_suffix)
     ".dwg"
     )
    )
    (setq n (1+ n))
  )
(setvar "EXPERT" old_expert)
  (princ)
)


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Only one
« Reply #3 on: November 26, 2006, 03:02:23 PM »
Not sure what exactly you are trying to accomplish, but here is a stab at it.
This routine assumes you are in a drawing named <your name>-A.DWG
and there is a text object of the same name in the drawing.
It saves copies B through Z in folder  "C:/temp/" and the text string is
changed to match the new drawing title.
Code: [Select]
(defun c:sdaz (/ cnt fol ss sse suffix title xdwg)
  (vl-load-com)
  (setq fol "C:/temp/")
  ;;  Assume the first drawing is "Title-A"
  (setq xdwg (vl-filename-base (getvar "dwgname")) ; "Title-A"
        xdwg (substr xdwg 1 (1- (strlen xdwg)))
        )
  (setq cnt 1)
  ;;  Saveas B through Z
  ;;  assumes that the current drawing is "Title-A.dwg"
  ;;  and there is text containing "Title-A.dwg"
  (while (< (setq cnt (1+ cnt)) 27)
    (setq suffix (chr (+ 64 cnt)))
    (setq title (strcat xdwg suffix)) ; "Title-B.dwg"..."Title-Z.dwg"
    (and ; skip if any nil encountered
      (setq ss (ssget "x"
                      (list '(0 . "TEXT")
                            (cons 1 (strcat xdwg (chr (+ 64 (1- cnt)))))
                      )))
      (setq sse (entget (ssname ss 0)))
      (entmod (subst (cons 1 title) (assoc 1 sse) sse))
      (null (command "_saveas" "2000" (strcat fol title) ""))
      (princ (strcat "\nFile Created -> " title))
    ) ; and
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Adesu

  • Guest
Re: Only one
« Reply #4 on: November 26, 2006, 06:46:05 PM »
Hi mohobrien,
Your code perfect and cool,thanks
that code for create drawing as xref.

Basically same idea. It would work better if you opened a blank drawing and queried in what you have in your "Title-A" drawing.
I don't understand why you would want to grab text only. Isn't Title-A just a template for all the drawings? What did I miss?

Code: [Select]
(defun c:test
       (/ dwg_suffix dwg_path dwg_name dwg_name_base n old_expert)
  (vl-load-com)
(setq old_expert (getvar "EXPERT")) ; allows overwriting files without confirmation!
(setvar "EXPERT" 5)
  (setq dwg_suffix
(list "B"   "C"   "D" "E"   "F"   "G"   "H" "I"   "J"
       "K"   "L"   "M" "N"   "O"   "P"   "Q" "R"   "S"
       "T"   "U"   "V" "W"   "X"   "Y"   "Z"
      )
  )
  (setq dwg_path
(vl-filename-directory
   (vla-get-fullname
     (vla-get-ActiveDocument (vlax-get-acad-object))
   )
)
dwg_name (vl-filename-base
   (vla-get-fullname
     (vla-get-ActiveDocument (vlax-get-acad-object))
   )
)
  )
  (setq dwg_name_base (substr dwg_name 1 (- (strlen dwg_name) 1)))
  (setq n 0)
  (while (< n (length dwg_suffix))
    (command "SAVEAS"
     "2000"
     (strcat dwg_path
     "\\"
     dwg_name_base
     (nth n dwg_suffix)
     ".dwg"
     )
    )
    (setq n (1+ n))
  )
(setvar "EXPERT" old_expert)
  (princ)
)


Adesu

  • Guest
Re: Only one
« Reply #5 on: November 26, 2006, 06:58:19 PM »
Hi CAB,
Your code is perfect and cool too,many thanks.
.
Not sure what exactly you are trying to accomplish, but here is a stab at it.
This routine assumes you are in a drawing named <your name>-A.DWG
and there is a text object of the same name in the drawing.
It saves copies B through Z in folder  "C:/temp/" and the text string is
changed to match the new drawing title.
Code: [Select]
(defun c:sdaz (/ cnt fol ss sse suffix title xdwg)
  (vl-load-com)
  (setq fol "C:/temp/")
  ;;  Assume the first drawing is "Title-A"
  (setq xdwg (vl-filename-base (getvar "dwgname")) ; "Title-A"
        xdwg (substr xdwg 1 (1- (strlen xdwg)))
        )
  (setq cnt 1)
  ;;  Saveas B through Z
  ;;  assumes that the current drawing is "Title-A.dwg"
  ;;  and there is text containing "Title-A.dwg"
  (while (< (setq cnt (1+ cnt)) 27)
    (setq suffix (chr (+ 64 cnt)))
    (setq title (strcat xdwg suffix)) ; "Title-B.dwg"..."Title-Z.dwg"
    (and ; skip if any nil encountered
      (setq ss (ssget "x"
                      (list '(0 . "TEXT")
                            (cons 1 (strcat xdwg (chr (+ 64 (1- cnt)))))
                      )))
      (setq sse (entget (ssname ss 0)))
      (entmod (subst (cons 1 title) (assoc 1 sse) sse))
      (null (command "_saveas" "2000" (strcat fol title) ""))
      (princ (strcat "\nFile Created -> " title))
    ) ; and
  )
  (princ)
)