PDA

View Full Version : Assistance required with a lisp routine to Bind and save a drawing to a different location.


stephen.coff
2008-06-24, 08:43 AM
Guys,
It has been some time since i have played with a lisp routine. Really not up to scratch and maybe a much better way of doing what i wish outside of Lisp, open to any suggestions what so ever.
I have our drawings structured in a particular way so things should never changed and the way i wish to approach this should cause any dramas at my end. I just don't know how to fully complete the task with Lisp and this is where i require some assistance.
I usually etransmitt files when i send them though i seem to be getting more and more people asking for them as a bound file lately. I wanted to write a small routine to bind the files though also place them in another folder and keep the original not bound.
I need to run the routine on the open file and have it save the file to a new location (two folders deeper "/outgoing/080624/"). I seem to have this part sorted though get stuck when it comes to binding of that saved file. Because the routine save a copy to the required location though i want this new copy to be bound and not the original. That is where i get stuck and hope i have explained myself enough?

Here is what i have so far, haven't looked over it in detail and expect errors.
How do i have the routine close the original file and then continue with the new file?


(defun c:bind (/ dp dn cd Outgoingpath datepath newpath savepath *blks* ref xname)
(vl-load-com)
(setvar "cmdecho" 1)
(setvar "filedia" 0)
(setq dp (getvar "dwgprefix"))
(setq dn (vl-filename-base (getvar "dwgname")))
(setq cd (strcat (getvar "dwgprefix") (getvar "dwgname")))
(setq Outgoingpath (strcat (getvar "dwgprefix") "Outgoing\\"))
(vl-mkdir Outgoingpath)
(setq
datepath (strcat (menucmd "M=$(edtime,$(getvar,date),YYMODD)")
"\\"
)
)
(setq newpath (strcat outgoingpath datepath))
(vl-mkdir newpath)
(setq savepath (strcat newpath dn))
(command "save" savepath "")
(command "open" savepath "")
(command "-layer" "Unlock" "*" "")
(setq *blks*
(vla-get-Blocks
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
)
(vlax-for item *blks*
(if (eq (vla-get-IsXref item) :vlax-true)
(progn
(setq ref (tblsearch "BLOCK" (setq xname (vla-get-Name item))))
(if (eq (logand (cdr (assoc 70 ref)) 32) 32)
(command "-xref" "_B" xname)
(command "-xref" "_D" xname)
)
)
)
)
(princ "...ALL XREF'S BOUND & ALL UNREFERENCED XREF'S REMOVED...")
(setvar "tilemode" 0)
(command "zoom" "extents")
(command "-layer" "lock" "*" "")
(command "purge" "a" "*" "n")
(command "audit" "y")
(setvar "filedia" 1)
(command "save" "y")
(command "close" "n")
)

Moderator Note:
Please use [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code)

Avatart
2008-06-24, 04:01 PM
Stephen, I would do the tasks the other way around, bind stuff up forst, then save it to your new folder. Attached is the routine I have used for the last few years, this one saves to a subfolder "Bind", but I'm sure you can work some magic to get it to use the folders you require:


;; This Lisp file is distributed free of copyright
;; and may be butchered about as much as you like!
;;
;; Happy draughting....... (Graphic Detail)
;;
;; Binding subfunction
(defun DoBind ( / StateName )
(command "undo" "begin")
(setq StateName (getvar "Date"))
(command "zoom" "e")
(command "tilemode" 0)
(command "pspace")
(command "zoom" "e")
(setvar "texteval" 1)
(command "-Layer" "A" "S" StateName "" "" "")
(command "-xref" "r" "*")
(command "-xref" "b" "*")
(command "-purge" "a" "*" "n")
(command "-purge" "a" "*" "n")
(command "-purge" "a" "*" "n")
(command "-Layer" "A" "R" StateName "D" StateName "" "")
(command "undo" "end")
(if (= exist 1)
(progn
(setvar "filedia" 0)
(command "saveas" "" savename "y")
(setvar "filedia" 1)
)
)
(if (/= exist 1)
(progn
(vl-mkdir bindpath)
(setvar "filedia" 0)
(command "saveas" "" savename)
(setvar "filedia" 1)
)
)
)
;; Do Not Bind subfunction
(defun DoNotBind ( / )
(alert "Drawing not bound")
)
;; Main Function
(defun C:XBindScript ( / bindpath savename boundoverwrite exist)
(setq bindpath (strcat (getvar "dwgprefix") "Bind\\"))
(setq savename (strcat bindpath (getvar "dwgname")))
(if (/= (findfile savename) nil) (setq exist 1) (setq exist nil))
(if (/= exist 1)
(DoBind)
)
(if (= exist 1)
(progn
(alert "Bound Version Exists")
(initget 1 "Yes No")
(setq boundoverwrite (getkword "Bound Version Exists - Overwrite? (Yes/No)"))
(if (= boundoverwrite "Yes")
(DoBind) (DoNotBind)
)
)
)
(princ)
)

stephen.coff
2008-06-26, 07:52 AM
Thank you for your reply. I understand why you would choose to bind first and then save to another folder though that totally defeats the purpose. By binding the file and then saving it you have already stuffed the original file. Once the file is bound it can not be unbound which is why i want to save a copy and then bind the saved copy. It leaves the original created file as it was originally designed (xref's and all). If i bind the copy well that really makes little difference or concern to me.
Once again, thank you for the post and effort though not really what i am after though very close. Is anyone else able to assistany further with this topic?

Avatart
2008-06-26, 08:55 AM
Thank you for your reply. I understand why you would choose to bind first and then save to another folder though that totally defeats the purpose. By binding the file and then saving it you have already stuffed the original file. Once the file is bound it can not be unbound which is why i want to save a copy and then bind the saved copy. It leaves the original created file as it was originally designed (xref's and all). If i bind the copy well that really makes little difference or concern to me.
Once again, thank you for the post and effort though not really what i am after though very close. Is anyone else able to assistany further with this topic?
Stephen, it doesn't save the original file, so that is left completely intact. the problem with saving and then binding is that your Xref paths are no longer true, that's why I bind and then saveas, like you would if you were doing it by hand.

ccowgill
2008-06-26, 12:55 PM
I have not read your code or tried it out, but if the name changes of the current open drawing, try using the passthorugh save, it saves the file as the alternative path and leaves the current drawing open, in which you can undo the previous command to bind the file:

(command "_SAVE" ...)

jason.magon
2008-10-23, 04:02 PM
Very helpful post. This is something that I'd been wanting to try and do but was beyond my lisp skills. Would anyone know how to save the file as with a prefix and a sufix? Using the second routine as an example how would I save the drawing to the subfolder "bind" AND add a revision designation to the end? We issue drawing pretty much the same way that the second routine is written but add an _01.dwg to the filename.

Getting the program to prompt me for the revision number would be the fix I guess. any ideas on where to start looking for the know how's to make this happen?

Avatart
2008-10-23, 04:16 PM
Very helpful post. This is something that I'd been wanting to try and do but was beyond my lisp skills. Would anyone know how to save the file as with a prefix and a sufix? Using the second routine as an example how would I save the drawing to the subfolder "bind" AND add a revision designation to the end? We issue drawing pretty much the same way that the second routine is written but add an _01.dwg to the filename.

Getting the program to prompt me for the revision number would be the fix I guess. any ideas on where to start looking for the know how's to make this happen?
Jason, hi, welcome to AUGI.

If your revision is an Attribute on the drawing, you can read the value of that attribute and append it to the filename. I can show you how to do that.

jason.magon
2008-11-06, 03:22 PM
I'd really appreciate the help. I have a working lisp routine that functions the way that I want it to other than the revision indicator on the end of the filename. The revision is an attribute on the drawing. It is contained in a block name "border-at" and the attribute name is "rev".

ReachAndre
2008-11-10, 09:40 PM
Any reason that you would not set up an etransmit syle that will bind the files?

irneb
2008-11-11, 06:07 AM
Any reason that you would not set up an etransmit syle that will bind the files?Exactly! It's there already! And any binding problems you get using eTransmit is the same ones you'll get doing a bind through LISP. You can also add the revision / path to the eTransmit file through the same methods of STRCAT with obtaining ATTRIB value of block & (getvar "DWGNAME") for file name. I use something like this (but in a script) then run it through ScriptPro to do multiple DWG issues all at once.

BTW, I prefer not actually binding ... there's chances of errors if you have nested xrefs. I prefer just doing a straight eTransmit which combines all the xreffed files into a ZIP ... no posibility of errors whatever the case may be.

It's just when a client is adement about binding, otherwise just tell him to extract all files out of the ZIP & he's got the XRefs working properly.

alan.rackham
2009-02-27, 01:50 AM
Do you really need a lisp routine. You can etransmit and set an option to bind the xreferences. Hope this helps