PDA

View Full Version : vlisp in multiple drawings



mahazen
2004-08-08, 03:44 PM
Hello all,

How do you get a vlisp routine to continue in a new drawing?
I'm trying to create a startup routine that will add a title block as an xref and set some standard settings for the user. As long as I stay in the original drawing, I can make it do what I want. The problem I run into is when I try to open a new drawing and continue with the routine. As soon as I open and activate the new drawing, the routine explodes.

Thanks

peter
2004-08-09, 11:29 AM
Hi

LISP is a document level programming language. So when you close a drawing it stops.
TO get around this there is one thing you can do (actually a couple ways). The way I found which works best is to use a flag and a vbastmt.

In you acaddoc.lsp you watch a flag like the users1 system variable and if it has some value in it like "RUNLISP,PROG2" it will load and run the program PROG2.LSP.

Set the variable users1 to the above value.

Run your routine and have if do something before the drawing change and then used a
(command "vbastmt"
(strcat "AcadApplication.Documents.Open \"" strDrawingName "\"")
)

With the string variable strDrawingName being the full name of the drawing you want to open...

Then the acaddoc.lsp would check the users1 system variable and you can run the secon half of your routine.

You could also use the vl-bb-set and vl-bb-ref instead of the users1.

Hope this helps

Peter Jamtgaard

eugene_k
2010-04-06, 01:44 AM
Peter, I was trying to follow your instructions, but could not even find that "users1" system variable in the acad2010doc.lsp. This is probably very old stuff now any way... Is there any better way of running lisp on multiple drawings?
I believe Autodesk should provide some sort of batch processing engine as a tool to run lisp on multiple drawings. ScriptPro is far less powerful and not good enough...

RobertB
2010-04-06, 01:54 AM
Peter, I was trying to follow your instructions, but could not even find that "users1" system variable in the acad2010doc.lsp. This is probably very old stuff now any way... Is there any better way of running lisp on multiple drawings?
I believe Autodesk should provide some sort of batch processing engine as a tool to run lisp on multiple drawings. ScriptPro is far less powerful and not good enough...UserS1 is an AutoCAD system variable, not a Visual LISP variable.

Command: ._Setvar ? User*

You can use Visual LISP to process multiple drawings, as long as you stay away from selection sets and using the command function.

Check out my AU Online classes on Good Habits for Code in Visual LISP (http://au.autodesk.com/?nd=class&session_id=5372) for an approach using ObjectDBX.

the_andyman17
2010-06-15, 01:33 PM
You can use Visual LISP to process multiple drawings, as long as you stay away from selection sets and using the command function.

Hi Robert,

I'm trying to work this into a code, and am wondering if selection sets and the command function would be OK if they were defined in a function previously...and that function was called upon in the new drawing.

The LISP I'm trying to create will, when called upon in ANY drawing, open our standard metric drawing, change the (dynamic) scaleblock, and change the (dynamic) address block (we have five offices in our company). After each change of the address block it will "save as" the new drawing template for each office. Then it will go to the next scale in the list and repeat the process until it's completed every scale for each office.

I'm going to go ahead and post the lisp, but bear in mind it's elaborate and complicated. Any input is appreciated, the problem I'm having is continuing the LISP past the first scale.



(load "dynblocks.lsp")

(defun switch_scaleblock( scale_block )

;;; Get the office from the user
;;;(setq scale_block "")
;;;(setq scale_block (getstring "\nWhich scale would you like to add? [1:x] Enter 'x' : "))

;;; Setup variables for loop
(setq counter 0)
(setq ss (ssdblk "HAL_SCALEBAR_METRIC"))
(setq scale_block_full_name (strcat "SCALE 1:" scale_block))

;;; Now begin loop
(repeat (sslength ss)
(setq block (ssname ss counter))
(setq el (entget block))
(chgdynprop block "Visibility" scale_block_full_name)
(setq counter (+ counter 1))
) ;End repeat
)

;;;-------------------------------------------------------------------

(defun TM-ERASE ()

;;;Change to model space.
(command "model")

;;;Now erase all objects. Start with a nice clean drawing.
(command "erase" "all" "")

(command "-purge" "B" "*" "N")
)

;;;-------------------------------------------------------------------

(defun TM-DIMS ( scale_number )

;;; Set the current dimstyle to one you dont want to remove.
(command "-dimstyle" "R" (strcat "Hal-Dim-" scale_number))

;;;remove all the dimension styles. Except the current!
(command "-purge" "D" "*" "N")

)

;;;-------------------------------------------------------------------

(defun TM-LDRS ( scale_number )

;;;
;;; Set the Mleader style to one you dont want to remove.
(command "cmleaderstyle" (strcat "Hal-Eli-" scale_number))

;;;remove all the mleader styles beginning with "Hal-Eli-" except the current!
(command "-purge" "mu" "Hal-Eli-*" "N")

;;;
;;; Set the Mleader style to one you dont want to remove.
;;; (command "cmleaderstyle" (strcat "Hal-Cir-" scale_number))
;;; NOTE: Ron wants all circle leaders removed

;;;remove all the mleader styles beginning with "Hal-Cir-" except the current!
(command "-purge" "mu" "Hal-Cir-*" "N")

;;;
;;; Set the Mleader style to one you dont want to remove.
(command "cmleaderstyle" (strcat "Hal-Non-" scale_number))

;;;remove all the mleader styles beginning with "Hal-Non-" except the current!
(command "-purge" "mu" "Hal-Non-*" "N")

;;;
;;; Set the Mleader style to one you dont want to remove.
(command "cmleaderstyle" (strcat "Hal-Ldr-" scale_number))

;;;remove all the mleader styles beginning with "Hal-Ldr-" except the current!
(command "-purge" "mu" "Hal-Ldr-*" "N")

)

;;;-------------------------------------------------------------------

(defun TM-TEXT ( scale_number )

;;;Set the current text style to one we dont want to remove
(command "textstyle" (strcat "Hal-Ano-" scale_number))

;;; remove the rest of the ano text styles
(command "-purge" "ST" "Hal-Ano-*" "N")


;;;Set the current text style to one we dont want to remove
(command "textstyle" (strcat "Hal-Ttl-" scale_number))

;;; remove the rest of the ano text styles
(command "-purge" "ST" "Hal-Ttl-*" "N")

)

;;;-------------------------------------------------------------------

(defun TM-SAVE-ottawa ( scale_number )

(command "dimscale" 0.1)

;Turn off file dialogs in order to use the saveas command.
(command "filedia" 0)

(if (findfile "Halsall - Switch_Office.lsp")
(load "Halsall - Switch_Office.lsp")
(princ "\nHalsall - Switch_Office.lsp can not be found!")
)

;;;Switch office to OTTAWA
(switch_office "OTTAWA")

;;;FIRST Save OTTAWA'S drawing as a template file.
(setenv "TemplatePath" "G:\\ACAD Halsall Testing Menu\\Templates\\")
(command "saveas" "T" (strcat "G:\\ACAD Halsall Testing Menu\\Templates\\Ottawa\\Metric - " scale_number) "Y" "M" (strcat "Halsall - Metric - " scale_number))

)

(defun TM-SAVE-sudbury ( scale_number )

;;;Switch office to SUDBURY
(switch_office "SUDBURY")

;;;Save SUDBURY'S drawing as a template file.
(setenv "TemplatePath" "G:\\ACAD Halsall Testing Menu\\Templates\\")
(command "saveas" "T" (strcat "G:\\ACAD Halsall Testing Menu\\Templates\\Sudbury\\Metric - " scale_number) "Y" "M" (strcat "Halsall - Metric - " scale_number))

)

(defun TM-SAVE-toronto ( scale_number )

;;;Switch office to TORONTO
(switch_office "TORONTO")

;;;Set current layer to one we don't want to remove.
(command "-layer" "s" "Hal_NonPlot" "")

;;;PURGE out layers that the other offices don't use.
(command "-purge" "la" "Hal_xRef-Arch" "n")
(command "-purge" "la" "Hal_xRef-Detail" "n")
(command "-purge" "la" "Hal_xRef-Grid" "n")
(command "-purge" "la" "Hal_xRef-Stamp" "n")
(command "-purge" "la" "Hal_xRef-Struc" "n")
(command "-purge" "la" "Hal_xRef-Title" "n")

;;;SECOND Save drawing as a template file without OTTAWA's layers.
(command "saveas" "T" (strcat "G:\\ACAD Halsall Testing Menu\\Templates\\Toronto\\Metric - " scale_number) "Y" "M" (strcat "Halsall - Metric - " scale_number))

)

(defun TM-SAVE-calgary ( scale_number )

;;;Switch office to CALGARY
(switch_office "CALGARY")

;;;Save CALGARY'S drawing as a template file.
(setenv "TemplatePath" "G:\\ACAD Halsall Testing Menu\\Templates\\")
(command "saveas" "T" (strcat "G:\\ACAD Halsall Testing Menu\\Templates\\Calgary\\Metric - " scale_number) "Y" "M" (strcat "Halsall - Metric - " scale_number))

)

(defun TM-SAVE-vancouver ( scale_number )

;;;Switch office to VANCOUVER
(switch_office "VANCOUVER")

;;;Save VANCOUVER'S drawing as a template file.
(setenv "TemplatePath" "G:\\ACAD Halsall Testing Menu\\Templates\\")
(command "saveas" "T" (strcat "G:\\ACAD Halsall Testing Menu\\Templates\\Vancouver\\Metric - " scale_number) "Y" "M" (strcat "Halsall - Metric - " scale_number))

restore the file dialog settings to ON.
(command "filedia" 1)

(setenv "TemplatePath" "G:\\ACAD Halsall Testing Menu\\Templates\\Toronto\\")

)

;;;----------------------------------------------------------------------------------

(defun processtest ( scale_number )

(setq filename "G:/ACAD Halsall Testing Menu/Standards Files/Metric/Halsall - Master - Metric.dwg")

(open filename)

(switch_scaleblock scale_number)
(prompt "\nScaleblock Switched\n")
(TM-ERASE)
(TM-DIMS scale_number)
(TM-LDRS scale_number)
(TM-TEXT scale_number)
(TM-SAVE-ottawa scale_number)
(TM-SAVE-sudbury scale_number)
(TM-SAVE-toronto scale_number)
(TM-SAVE-calgary scale_number)
(TM-SAVE-vancouver scale_number)
(command "close")

)

;;;----------------------------------------------------------------------------------

(defun C:processmetric ()

(setvar "FILEDIA" 0)

(setq scale_list '("10" "20" "30" "50" "75" "100" "125" "150" "200" "250" "500" "1000"))

(foreach scale_tmp scale_list

(processtest scale_tmp)

);end foreach

(setvar "FILEDIA" 1)

);End defun



The "Processmetric" command at the bottom ideally is the only thing the user would type to run the whole process.

dgorsman
2010-06-15, 02:38 PM
You can use Visual LISP to process multiple drawings, as long as you stay away from selection sets and using the command function.

And text, for writing purposes; reading is fine. ObjectDBX doesn't respect text justification other than the default "left". Makes it useful for harvesting drawing data for reports at least.

You can run LISP across multiple drawings by calling functions in acaddoc.lsp, within reason. Personally I don't like auto-running functions just by opening a drawing, as its too easy to do something unintended and unannounced ("What do you mean, all your layers are different?").

RobertB
2010-06-15, 04:32 PM
I'm trying to work this into a code, and am wondering if selection sets and the command function would be OK if they were defined in a function previously...and that function was called upon in the new drawing.
You cannot, if you are planning on using ObjectDBX.

RobertB
2010-06-15, 04:37 PM
The LISP I'm trying to create will, when called upon in ANY drawing, open our standard metric drawing, change the (dynamic) scaleblock, and change the (dynamic) address block (we have five offices in our company). After each change of the address block it will "save as" the new drawing template for each office. Then it will go to the next scale in the list and repeat the process until it's completed every scale for each office. I don't quite understand. :confused:

Are you creating a template for every office at every scale? That seems to be really cumbersome. We have a different template for each sheet size and the user selects the office and the scale explicitly when creating a new drawing based on the sheet template.

the_andyman17
2010-06-15, 08:44 PM
I don't quite understand. :confused:

Are you creating a template for every office at every scale?

Yes. For example, the 1:100 template file in the Toronto folder will have the address already properly displayed, and will contain only the 1:100 dimstyles, textstyles and blocks etc. There is 1 template file per office per scale in both imperial and metric.

It's the company's way of ensuring that drawings stay tidy, and it's my task to figure out how to streamline the creation of the templates.

Opie
2010-06-15, 09:19 PM
You could create one set of templates with all the scales for each template and use an Xref for the appropriate office address. Once you are satisfied with the templates, you could then eTransmit the drawings and bind / insert the xref into the drawing.

RobertB
2010-06-16, 01:30 AM
Yes. For example, the 1:100 template file in the Toronto folder will have the address already properly displayed, and will contain only the 1:100 dimstyles, textstyles and blocks etc. There is 1 template file per office per scale in both imperial and metric.

It's the company's way of ensuring that drawings stay tidy, and it's my task to figure out how to streamline the creation of the templates.So you are not using annotation scaling, which largely removes all those scaling issues and allows you to have multiple scales on the same layout?