@Anonymous wrote:
appologies for the late response, few issues:
- only seems to accept 5 digits for the file number
- the block needs to be edited every time, any way to just automaticly open enhanced attribute editor?
- the previous drawing dosen't seem to close on its own.
I am learning a lot from your lisp thru the autodesk help and trying to figure out what this is doing.
thanks again!
Hi shawnt,
the 'demo' it was just a starting point, for your code...
I did change the function to get the 'numbers' for the new dwg, to allow a large number of digits.
The 'demo' show a way to change the attributes in the new dwg without the need to open enhanced attribute editor, if your goal is to use the values from 'Epic Block Lot' at the current dwg, and copy to yhe new dwg, it's easy to add that feature in the code.
the previous drawing should close...
I added some comments to the code...
(defun c:demo (/ *error* dwgname name new newfile ofile scrfile)
;; error function
(defun *error* (msg)
; if the ofile is open during the error, close it
(if ofile
(close ofile)
)
(cond ((not msg))
((member msg '("Function cancelled" "quit / exit abort")))
((princ (strcat "\n** Error: " msg " ** ")))
)
(princ)
)
;; main program
; asks the user to enter a new number (as a string to allow a large number of digits)
(if (and (setq new (getstring "\nEnter the next dwg number: "))
; test if not an empty string
(/= new "")
; test if the user did enter a valid dwg name
(snvalid new)
; set name with file extension
(setq name (strcat new ".dwg"))
; set dwgname with full path
(setq dwgname (strcat (getvar 'dwgprefix) name))
)
; if all previous functions are true:
(progn
; test if dwg exists
(if (vl-directory-files (getvar 'dwgprefix) name)
; if exists, open it and set newfile with it, as a vla-object
(setq newfile (vla-open (vla-get-Documents (vlax-get-acad-object)) dwgname :vlax-false))
; if not exists, add it to the document collection using the lat used template, and set newfile with it, as a vla-object
(setq newfile (vla-add (vla-get-documents (vlax-get-acad-object)) (getenv "LastTemplate")))
)
; foreach layout (layt) from layouts collection from newfile
(vlax-for layt (vla-get-layouts newfile)
; test if layout name is "LOT-HOUSE"
(if (= (vla-get-name layt) "LOT-HOUSE")
; if true, forech block from block collection
(vlax-for blk (vla-get-block layt)
; test if is objectname property from blk is a "AcDbBlockReference"
(if (and (= (vla-get-objectname blk) "AcDbBlockReference")
; and test if the effectivename property from blk is "Epic Block Lot"
(= (vla-get-effectivename blk) "Epic Block Lot")
)
; if the previous tests are true
; foreach attribute
(foreach att (vlax-invoke blk 'getattributes)
; if tagstring is:
(cond ((= (vla-get-tagstring att) "ADD")
; put "New address..."
(vla-put-textstring att "New address...")
)
((= (vla-get-tagstring att) "ST1")
; put "New state..."
(vla-put-textstring att "New state...")
)
((= (vla-get-tagstring att) "CTY")
"New city..."
(vla-put-textstring att "New city...")
)
)
)
)
)
)
)
; save the newfile
(vla-saveas newfile (strcat (getvar 'dwgprefix) name))
; close the newfile
(vla-close newfile)
; start to create the script file
(setq scrfile (strcat (getenv "Temp") "\\My_Open.scr")
; open the script file to write "W"
ofile (open scrfile "w")
)
; write at ofile:
; qsave
(write-line "_.qsave" ofile)
; close
(write-line "_.close" ofile)
; open
(write-line "_.open" ofile)
; the dwg name to open
(write-line (strcat "\"" dwgname "\"") ofile)
; close the ofile
(close ofile)
; call the script command to run the previous cript file
(command "_.script" scrfile)
)
)
)
Hope this helps,
Henrique