Author Topic: undefine, then use the undefined command...  (Read 2268 times)

0 Members and 1 Guest are viewing this topic.

pfristoe

  • Guest
undefine, then use the undefined command...
« on: July 26, 2004, 04:33:35 PM »
I gave these commands while in an autocad session
with the following results:


Command: undefine
Enter command name: open

Command: open
Unknown command "OPEN".  Press F1 for help.

Command: .open
[Here, the regular open command ran, and I could have selected a dwg to open]

Command: (load "open")
C:OPEN
[I have listed my "open.lsp" below]

Command: open
.OPEN                   ;the open command did not accually run here
Command: Description of work, or hit enter to cancel:
Canceled


(defun C:OPEN ( / path dname usrname time note dv fil pdname cmdsave)
  (command ".OPEN")
  (setq note (getstring T "Description of work, or hit enter to cancel: "))
   (if (= 0 (strlen note)) (princ "Canceled")
  (progn
  (setq dname (menucmd "M=$(getvar, dwgname)"))
  (setq path (menucmd "M=$(getvar, dwgprefix)"))
  (setq pdname (strcat path dname))
  (setq dv "________________________________________________________________________________")
  (setq fil (open "Journal.txt" "a"))
  (write-line dv fil)
  (write-line (menucmd "M=$(getvar, loginname)") fil)
  (write-line (menucmd "M=$(edtime,$(getvar,date),DDDD\",\" D MONTH YYYY)") fil)
  (write-line pdname fil)
  (write-line note fil)
  (close fil)))
(princ)
)


As you can see, I am trying to design a method to automatically enter information into a loging system.....
any feedback would be usefull.[/b]

SMadsen

  • Guest
undefine, then use the undefined command...
« Reply #1 on: July 26, 2004, 05:14:23 PM »
AutoLISP runs in environments that are private to each drawing (also known as namespaces). This means you can't use the OPEN and NEW commands directly.

You need to go through ActiveX by accessing the Documents collection and call VLA-OPEN. E.g.:

(setq docs (vla-get-documents (vlax-get-acad-object)))
(setq newDoc (vla-open docs "MyDrawing.dwg"))

Now you can use newDoc to reference the newly opened drawing and do your stuff.

(setq newName (vla-get-name newDoc))
(setq newPath (vla-get-path newDoc))

To let user select a file via a dialog, you could use GETFILED as normal before calling VLA-OPEN