Author Topic: The problem of deal with documents  (Read 1934 times)

0 Members and 1 Guest are viewing this topic.

cjw

  • Guest
The problem of deal with documents
« on: August 13, 2008, 06:32:31 AM »
the problem of the code is it can't sendcommand between the documents...please help
thank you first...

Code: [Select]
(defun c:pc ()
  (setq *command* (getstring "\nInput the command:" T))
  (IF (setq DWGS (cjw-CommonDialog "Open" "*.dwg" "*.dwg"))
    (PROGN
      (setq APP (vlax-get-acad-object))
      (setq SDI (getvar "SDI"))
      (mapcar
'(lambda (DWGNAME)
   (setq LSPIN (getvar "LISPINIT"))
   (setvar "cmdecho" 0)
   (cond
     ((= SDI 0)
      (progn
(setvar "LISPINIT" 0)
(setq DOC (vla-open (vla-get-documents APP) DWGNAME))
      )
     )
     ((= SDI 1)
      (progn
(command "open" DWGNAME)
(setq DOC (vla-get-ActiveDocument APP))
      )
     )
   )
   
   ($Sub_Funtion$ DOC *command*)
   
   (prompt (strcat "\n*** " DWGNAME " ***\n"))
   (vla-save DOC)
   (if (= SDI 0)
     (vla-close DOC :vlax-false)
   )
   (setvar "LISPINIT" LSPIN)
)
DWGS
      )
      (vlax-release-object DOC)
      (vlax-release-object APP)
      (prompt "\n*** 批处理完毕 ***\n")
    )
    (prompt "\n*** 所选目录中未有任何DWG图档 ***\n")
  )
  (princ)
)

Code: [Select]
(defun $Sub_Funtion$ (DOC *command*)
  (vla-sendcommand
    DOC
    *command*
  )
)

Code: [Select]
;;;(setq str "F:\\2008\\ 1.dwg 2.dwg 3.dwg")
;;;(string_split str " ")
;;;("F:\\2008\\" "1.dwg" "2.dwg" "3.dwg")
(defun string_split (str
     delimiter
     /
     lenStr
     lenDelimiter
     start@
     lstStr
     done
     find@
    )
  (setq lenStr      (strlen str)
lenDelimiter (strlen delimiter)
start@      0
lstStr      nil
done      nil
  )
  (while (and (not done) (<= (1+ start@) lenStr))
    (if (setq find@ (vl-string-search delimiter str start@))
      (setq lstStr (cons
     (if (zerop find@)
       ""
       (substr str (1+ start@) (- find@ start@))
     )
     lstStr
   )
    start@ (+ find@ lenDelimiter)
      )
      (setq done   t
    lstStr (cons (substr str (1+ start@)) lstStr)
      )
    )
  )
  (if (= start@ lenStr)
    (setq lstStr (cons "" lstStr))
  )
  (reverse lstStr)
)

Code: [Select]
;;;(cjw-CommonDialog "Get the DWG files" "*.dwg" "*.dwg")
(defun cjw-CommonDialog (DialogTitle
FileName
Filter
/
BLKNAS
CHAR
DELIMITER
N
RETURN
SEARCHSTR
STR
STRINGLEN
OBJ
)
  (vl-registry-write
    "HKEY_CLASSES_ROOT\\Licenses\\4D553650-6ABE-11cf-8ADB-00AA00C00905"
    ""
    "gfjmrfkfifkmkfffrlmmgmhmnlulkmfmqkqj"
  )
  (if (setq x (vlax-create-object "MSComDlg.CommonDialog"))
    (progn (vlax-put-property x "DialogTitle" DialogTitle)
   (vlax-put-property x "Filename" FileName)
   (vlax-put-property x "Filter" Filter)
   (vlax-put-property x "MaxFileSize" 10000)
   (vlax-put-property x "Flags" 512)
   (vlax-put-property x "Action" 1)
   (setq str (vlax-get-property x "Filename"))
    )
  )
  (if (/= str "*.dwg")
    (progn
      (setq p&f (cjw-string-split str " "))
      (setq p   (car p&f)
    fns   (cdr p&f)
    files nil
      )
      (if fns
(foreach f fns
  (setq files (cons (strcat p f) files))
)
(setq files p&f)
      )
      (reverse files)
    )
    (setq files nil)
  )
)
« Last Edit: August 14, 2008, 03:15:36 AM by cjw »

kpblc

  • Bull Frog
  • Posts: 396
Re: The problem of deal with documents
« Reply #1 on: August 13, 2008, 07:11:13 AM »
You can use only script file or you should use vla-functions
Sorry for my English.

cjw

  • Guest
Re: The problem of deal with documents
« Reply #2 on: August 13, 2008, 08:50:22 PM »
You can use only script file or you should use vla-functions

kpblc,thank you.
i just want to try it with lisp,and it has used vla-functions.
OR it can't work ? never ever?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: The problem of deal with documents
« Reply #3 on: August 14, 2008, 01:42:05 PM »
Look into ObjectDBX
HERE
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.

cjw

  • Guest
Re: The problem of deal with documents
« Reply #4 on: August 18, 2008, 05:19:37 AM »
Look into ObjectDBX
HERE
Aha...the same as i saw before,but i didn't understand.
Thanks,CAB.

cjw

  • Guest
Re: The problem of deal with documents
« Reply #5 on: August 18, 2008, 06:07:11 AM »
CAD 2006
I guess "sendcommand" not available in ObjectDBX.
right?

Code: [Select]

(defun c:pc ()
  (setq *command* (getstring "\nInput the command <Exit>: " T))
  (setq files (cjw-CommonDialog
"Get the DWG files to batch"
"*.dwg"
"*.dwg"
      )
  )
  (setq dbxdoc (vla-GetInterfaceObject
(vlax-get-acad-object)
"ObjectDBX.AxDbDocument.16"
       )
  )
  ;;(vlax-dump-Object dbxdoc T)
  (foreach f files
    (setq of (vl-catch-all-apply
       '(lambda ()
  (vlax-invoke-method dbxdoc 'open f)
)
     )
    )
    (if (vl-catch-all-error-p of)
      (setq lst (cons (vl-catch-all-error-message of) lst))
      (progn
($Sub_Funtion$ dbxdoc *command*)
(vla-saveas dbxdoc f)
      )
    )
  )
  (vlax-release-object dbxdoc)
  (gc)
  (princ)
)


jbuzbee

  • Swamp Rat
  • Posts: 851
Re: The problem of deal with documents
« Reply #6 on: August 18, 2008, 07:00:17 AM »
Looks like your attempting to batch process some drawings?

Have a look here:

http://www.theswamp.org/index.php?topic=24479.0
James Buzbee
Windows 8