PDA

View Full Version : custom export or publish lisp routine


timothyjturner
2005-10-27, 05:12 PM
Hello,

After every drawing that I create I must go through the same steps and this has come to be time consuming.
Is it possible to create a lisp that will do the following in this order?...

1. Save as in a location that is input directy from a prompt given to the command line. If not possible then open the standard save as dialog box? Other ideas?
2. Save as in a location that will not change.
3. Plot with standard plot settings.

The thing I need help with is step 1. I have no idea if any of this is possible. If I can understand how to accomplish step 1, then step 2 should be easy. I already have a lisp to do step 3.

Thanks much!


Tim Turner
CAD Tech - Electrical

Opie
2005-10-27, 05:15 PM
Timothy,

You might look into this thread - LISP - Automatic Save that runs at set intervals. I think it will help you understand how to do steps one and/or step 2.

timothyjturner
2005-10-27, 05:43 PM
I have been looking through some of the code on these posts and there does seem to be some commands in there that I can use. I am using AutoCAD 2005 and I am looking through the Developer Documentation (accessed through the main help menu) and I am having trouble spottling a lot of these commands with the vl- prefix that seem very useful. Am I just overlooking the help on these commands or is there a better external reference?

Thanks,

Tim

Opie
2005-10-27, 06:09 PM
Within the developer help file you should have a link to the Autolisp Reference. You can browse through that for several of the Visual Lisp functions.

You can also search the index of the developer help system for specific functions.

tyshofner
2005-10-27, 08:23 PM
I wrote #2 in another thread a couple of days ago, modified it for #1. You could combine these into one routine though and include the plot.



;#1
(defun C:SAVELOC ( / sav_path dwg_name)
(setvar "filedia" 0)
(setq sav_path (getstring "Specify save path: "));Set the path you want here
(setq dwg_name (getvar "dwgname"))
(command "saveas" "" (strcat sav_path "\\" dwg_name))
(setvar "filedia" 1)
(princ)
)
;#2
(defun C:SAVELOC ( / sav_path dwg_name)
(setvar "filedia" 0)
(setq sav_path "C:\\Documents and Settings\\tys\\Desktop");Set the path you want here
(setq dwg_name (getvar "dwgname"))
(command "saveas" "" (strcat sav_path "\\" dwg_name))
(setvar "filedia" 1)
(princ)
)


Quick and dirty, no error checking .

Ty :mrgreen:

timothyjturner
2005-10-27, 08:51 PM
Doh!

Thanks tyshofner, that was a lot easier than I expected. I should be able to use your example to do exactly what I want to do. But wow that was too easy, so I think I'm going to throw in another challenge. This program would be even more convenient if you could extract the drawing name from the actual drawing.

I don't know enough about attributes... but is it possible to get a string value from an already defined attribute so I can name my file? All I know is that when I doubleclick text in these standardized drawings, an edit attributes dialog box comes up and gives you an opportunity to enter a new value. Are these values stored anywhere? How can I get them into my program? :D

tyshofner
2005-10-27, 09:09 PM
#1
What do you meen when you say "Extract the drawing name from the actual drawing.". This routine does get the drawing name of the drawing your in and appends it to the path you specify. Are you wanting something else??

#2
Yes you can get the string value of an attribute, but you'll need to know a few things.
1. What is the attribute "tag"? (look in the attribute editor, or explode the block)
2. What is the name of the block the attribute is contained within? (properties)
3. Is there only ONE instance of the block in the drawing or are there multiple?

Let me know and this should get us started.

Ty :mrgreen:

timothyjturner
2005-10-27, 09:17 PM
Block: TITLE3
Tag: DWGNUM


The drawing name is already stored in this tag...i just need to get this into my autolisp routine as a string. That's all I want. Sorry for sounding so complicated. :)

Opie
2005-10-27, 09:22 PM
Timothy,

The drawing name (as shown in AutoCAD) can be extracted from the dwgname system variable. This variable is not dependent of any attribute.

timothyjturner
2005-10-27, 09:33 PM
Richard,

You answered my question correctly but I asked the wrong question. The drawings I work on contain the drawing number as a text attribute. I want to use the drawing number tag to rename my file through autolisp.

Thanks,

Tim

Opie
2005-10-27, 09:36 PM
Richard,

You answered my question correctly but I asked the wrong question. The drawings I work on contain the drawing number as a text attribute. I want to use the drawing number tag to rename my file through autolisp.

Thanks,

Tim
But you won't be truly renaming your file, since you will be creating a new one and the old one will still be there. Depending on the version of AutoCAD you have, you could use fields in your attribute to place the drawing name as the attribute value.

tyshofner
2005-10-27, 10:25 PM
This will grab the value of the "DWGNUM" attribute and set it to the variable "dwg_num". This assumes that there is only ONE block called "TITLE3" inserted in the drawing.


;#1
(defun C:SAVELOC1 ( / sav_path dwg_name)
(setvar "filedia" 0)
(setq ss (ssget "X" '((0 . "INSERT") (2 . "TITLE3"))))
(setq blk (ssname ss 0))
(setq ent (entnext blk))
(while (and (/= ent nil) (/= (cdr (assoc 0 (entget ent))) "SEQEND"))
(if (= (cdr (assoc 2 (entget ent))) "DWGNUM")
(setq dwg_num (cdr (assoc 1 (entget ent))))
)
(setq ent (entnext ent))
)
(setq sav_path (getstring "Specify save path: "));Set the path you want here
;(setq dwg_name (getvar "dwgname"))
(command "saveas" "" (strcat sav_path "\\" dwg_num))
(setvar "filedia" 1)
(princ)
)
;#2
(defun C:SAVELOC2 ( / sav_path dwg_name)
(setvar "filedia" 0)
(setq ss (ssget "X" '((0 . "INSERT") (2 . "TITLE3"))))
(setq blk (ssname ss 0))
(setq ent (entnext blk))
(while (and (/= ent nil) (/= (cdr (assoc 0 (entget ent))) "SEQEND"))
(if (= (cdr (assoc 2 (entget ent))) "DWGNUM")
(setq dwg_num (cdr (assoc 1 (entget ent))))
)
(setq ent (entnext ent))
)
(setq sav_path "C:\\Documents and Settings\\tys\\Desktop");Set the path you want here
;(setq dwg_name (getvar "dwgname"))
(command "saveas" "" (strcat sav_path "\\" dwg_num))
(setvar "filedia" 1)
(princ)
)


To echo what Richard was saying: Do you want to rename the file you are currently in or just the file that is being saved elsewhere? I'm assuming the latter.

Ty :mrgreen:

timothyjturner
2005-10-28, 02:13 PM
I want to actually grab it and save to multiple locations....After looking through some different help files I realized that I can do even more with this program than I planned. So I'm planning on using the drawing number to navigate my program to the right directories to save in the correct spots.... possibly writing over the current location of the file....if the file is not new. I just needed to figure out how to grab that number out of my drawing. I believe this will help (haven't tried it yet), so thanks! :)

I will prob work on this program next week. I will be sure to post it once I get something working.