CADWarrior Posted December 17, 2012 Posted December 17, 2012 Hello all, Just got finished with making a lisp that found a Title block on all open drawings and inserts an engineers Logo onto it. Long story short ObjectIDtoobject command gets a little funky when working with a 64 bit system and it confused me a for a bit (worked perfect on 32 bit switch to the 64 bit system Access violation ) but got it to work thanks to Lee Mac and a previous thread of his. Anyhow back to the point at hand I figured will if I can put logos on every page i should be able to Print, Zoom Extents, Purge, Audit, and Close each drawing with no issue. Well I started working on the Printing portion and from what I can tell this should work 100% but when it opens the next drawing to print it freezes and I receive a fatal error. (defun C:SPC (/) (vl-load-com) (setvar 'backgroundplot 0) (vlax-for dwg (vla-get-documents (vlax-get-acad-object)) (setq plotcons (vla-get-PlotConfigurations dwg)) (setq plotcon (vl-catch-all-apply 'vla-Item (list plotcons "PDF-Fit"))) (if (/= (type plotcon) 'VLA-OBJECT) (if (= (getvar "TILEMODE") 0) (setq plotcon (vla-Add plotcons "PDF-Fit" :vlax-false)) (setq plotcon (vla-Add plotcons "PDF-Fit" :vlax-true)) ) ) (vla-RefreshPlotDeviceInfo plotcon) (vla-put-ConfigName plotcon "Adobe PDF") (vla-put-CanonicalMediaName plotcon "Ledger") (vla-put-PaperUnits plotcon acInches) (if (= (getvar "TILEMODE") 0) (progn (vla-put-PlotType plotcon acLayout) (vla-put-UseStandardScale plotcon :vlax-true) (vla-put-StandardScale plotcon ac1_1) ) (progn (vla-put-PlotType plotcon acExtents) (vla-put-UseStandardScale plotcon :vlax-true) (vla-put-StandardScale plotcon acScaleToFit) (vla-put-CenterPlot plotcon :vlax-true) ) ) (vla-put-PlotHidden plotcon :vlax-false) (vla-put-PlotRotation plotcon ac0degrees) (vla-put-PlotViewportBorders plotcon :vlax-false) (vla-put-PlotViewportsFirst plotcon :vlax-true) (vla-put-PlotWithLineweights plotcon :vlax-true) (vla-put-ScaleLineweights plotcon :vlax-true) (vla-put-PlotWithPlotStyles plotcon :vlax-true) (vla-put-ShowPlotStyles plotcon :vlax-true) (if (= (getvar "PSTYLEMODE") 0) (vla-put-StyleSheet plotcon "grayscale.stb") (vla-put-StyleSheet plotcon "grayscale.ctb") ) (vla-plottodevice (vla-get-plot dwg)) ) ) Any help you guys can give me to resolve this would be great. I would use publish but there are further things I wish to do to this lisp. (EG search for Title Block and find what the scale is in the block attributes and print to that scale) Quote
Lee Mac Posted December 17, 2012 Posted December 17, 2012 As far as I know, you are very restricted on the operations that may be performed on inactive Document Objects in the Documents Collection; as such, I tend to avoid this method where possible. I have written a number of 'batch plotting' applications in the past and have always used a technique of writing a Visual LISP plotting function to an AutoLISP file in the support path from the program, then constructing & running a Script file from the program. The Script would then open each drawing to be plotted, load & run the Visual LISP Plotting function, then close the drawing. As a result, you can harness the batch processing ability of a Script, and still utilise the power & error trapping offered by AutoLISP & Visual LISP to perform the necessary operations on each drawing. Quote
CADWarrior Posted December 17, 2012 Author Posted December 17, 2012 (edited) Aww man Lee why do you have to dash my hopes like that. I was hoping you would be the one with the answer Well typically all the drawings are already open (for doing corrections and code reviews). I guess I could take out the printing functionality for now. Do all other steps close the drawings. And reopen them as needed to print. Just seemed like it would be easier/quicker to do it the way I had it above. So much for doing this the easy way It seems like it wants to do it but it just bugs out. Any idea why AutoCAD would make it seem like something would work then poof all of a sudden it doesnt? And, do you think it would help if I forced the DWG that is to be printed to become active? Or would that cause even more issue? If I remember correctly VLisps are geared towards Dwg level scripts (as opposed to the AutoCAD Environment as a whole). Which makes me wonder even more why they would have (vla-get-documents (vla-get-acad-object)) if they wont let you utilize it to its fullest. I mean it does come in handy for small stuff like simple block insert lisps and BOM Block counting and such. Just seems like such a waste of potential. Edited December 17, 2012 by CADWarrior Additional Questions didnt want to double post. Quote
Lee Mac Posted December 17, 2012 Posted December 17, 2012 FYI: the Zoom methods will also only work in the active document, since they are derived from the Application Object and are not document dependent. Quote
BIGAL Posted December 18, 2012 Posted December 18, 2012 Like Lee just set up the auto plot lisp as a defun load it first via autoload and then just have it as a 1 line in your master script I would have all the differrent tasks as individual defuns makes it easier to debug and control. You may though have provided me with a clue to a plotting problem in 2013 where autoplotting does not do text fill. Do you need an example lisp about attributes that will work in conjunction with muli layout plotting ? a quick example (setq newstr "" newstr2 "") (setq ss1 (car (entsel))) ; pick a block (foreach att (vlax-invoke (vlax-ename->vla-object SS1) 'getattributes) (setq newstr (strcat newstr "," (vla-get-textstring att ))) (setq newstr2 (strcat newstr2 "," (vla-get-tagstring att))) ) (princ newstr) (princ newstr2) Quote
CADWarrior Posted December 18, 2012 Author Posted December 18, 2012 BIGAL, Not sure if we are talking about the same thing here. When you are talking about multi layout plotting are you thinking Paper space tabs on the same dwg file? If so I use the below to accomplish that. (Defun C:PDF (/ PSpaces Center Center2 PlotList PlotTabs) (vl-load-com) (setvar "FILEDIA" 0) (setvar "CMDDIA" 0) (setq PSpaces (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))) (setq Center 0) (setq Center2 0) (repeat (vla-get-count PSpaces) (setq PlotList (cons (setq Center (1+ Center)) PlotList)) ) (vlax-for PlotTab PSpaces (setq PlotList (subst (vla-get-name PlotTab)(vla-get-taborder PlotTab)PlotList)) ) (setq PlotList (reverse PlotList)) (while (/= Center2 (1- Center)) (setq PlotTabs (nth Center2 PlotList)) (command "-PLOT" "y" PlotTabs "Adobe PDF" "Ledger" "Inches" "Landscape" "No" "Extents" "1:1" "Center" "Yes" "acad.ctb" "Yes" "No" "No" "No" "No" "Yes" "Yes") (setq Center2 (1+ Center2)) ) (setvar "FILEDIA" 1) (setvar "CMDDIA" 1) (princ) ) And not quite sure what Lee is getting at. My lisps automatically load on every drawing. My place of work has me switch to different computers to work on through out the day. So, I set up a flash drive that I have a loader lisp so as soon as I plug in my flash drive to said computer it loads all my lisp as I open autocad. See below: (vl-load-com) (progn (setq dirltr (list "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z")) ;;possible dir locations (foreach Dir dirltr (if (or (/= (findfile (strcat Dir":\\Loader.lsp")) nil) (/= (findfile (strcat Dir":\\Loader.fas")) nil));;find flash drive dir (setq Path Dir) ) ) (setq lload '()) (foreach file (vl-directory-files (strcat Path ":\\") "*.fas");;locate all fas files in main dir (setq lload (append lload (list file))) ) (foreach file (vl-directory-files (strcat Path ":\\") "*.lsp");;locate all lsp files in main dir (setq lload (append lload (list file))) ) (Foreach lisp Lload (if (not (or (= (strcase lisp) (strcase "Loader.lsp")) (= (strcase lisp) (strcase "Loader.fas")))) (progn (load (strcat Path ":\\" Lisp)) (princ (strcat lisp "\r\n")) ) ) ) ) It has more stuff to it for updating. Connects to the net and downloads the latest version of the lisp if applicable. But it wouldnt work for you guys. So, this is the meat of it anyhow. Let me know if the above is what you are talking about or if I am about to learn something new Also BIGAL You might find this useful seeing as you posted the above. (defun C:BM ( / attlst ent entN Block BlName cadblk attobjlst objatt promstr attprom attname atttext attlst attr attlst2 ent2 entN2 Block2 BlName2 cadblk2 attobjlst2 objatt2 promstr2 attprom2 attname2 atttext2 attlst2 attr2 name prom text) (vl-load-com) (setq attlst nil) (setq attlst2 nil) (if (setq ent (entsel "\nSelect a block to copy attributes from: ")) (progn (setq entN (car ent)) (setq Block (vlax-ename->vla-object entN)) (setq BlName (vla-get-name Block)) (setq cadblk (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) BlName)) (if (= (vla-get-hasattributes Block) :vlax-true) (setq attobjlst (vlax-safearray->list (variant-value (vla-getattributes Block)))) ) (foreach objatt attobjlst (vlax-for promstr cadblk (if (= (vla-get-objectname promstr) "AcDbAttributeDefinition") (progn (if (= (vla-get-ObjectID objatt) (vla-get-ObjectID promstr)) (progn (setq attprom (vla-get-promptstring promstr)) ) ) ) ) ) (setq attname (vla-get-tagstring objatt)) (setq atttext (vla-get-textstring objatt)) (setq attlst (append attlst (list (list objatt attname attprom atttext)))) ) ) (princ "..no object selected.") ) (if (setq ent2 (entsel "\nSelect a block to copy attributes to: ")) (progn (setq entN2 (car ent2)) (setq Block2 (vlax-ename->vla-object entN2)) (setq BlName2 (vla-get-name Block2)) (setq cadblk2 (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) BlName2)) (if (= (vla-get-hasattributes Block2) :vlax-true) (setq attobjlst2 (vlax-safearray->list (variant-value (vla-getattributes Block2)))) ) (foreach objatt2 attobjlst2 (vlax-for promstr2 cadblk2 (if (= (vla-get-objectname promstr2) "AcDbAttributeDefinition") (progn (if (= (vla-get-Handle objatt2) (vla-get-Handle promstr2)) (progn (setq attprom2 (vla-get-promptstring promstr2)) ) ) ) ) ) (setq attname2 (vla-get-tagstring objatt2)) (setq atttext2 (vla-get-textstring objatt2)) (setq attlst2 (append attlst2 (list (list objatt2 attname2 attprom2 atttext2)))) ) ) (princ "..no object selected.") ) (foreach attr attlst (setq name (nth 1 attr)) (setq prom (nth 2 attr)) (setq text (nth 3 attr)) (foreach attr2 attlst2 (if (and (= name (nth 1 attr2))(= prom (nth 2 attr2))) (vla-put-textstring (nth 0 attr2) text) ) ) ) (princ) ) Quote
BIGAL Posted December 19, 2012 Posted December 19, 2012 Thanks Cadwarrior but I have around 6 different title block modifiers already stuff like copy lines from first title block to all, count sheets up, change attributes based on layout name so pretty on top of changing attributes details also have the stuff done in VBA as well as I wrote it there first. The last one testing at moment is update revisons with yes / No per layout tabs auto increments if yes, allows operator to see the layout tab first very quick enter for NO. Quote
CADWarrior Posted December 19, 2012 Author Posted December 19, 2012 Do you have any idea how to do what Lee is talking about? I am far from use to controlling drawings from other drawings and my 2nd attempt as already thrown me for a loop Quote
BIGAL Posted December 20, 2012 Posted December 20, 2012 (edited) Using scripts can allow you to modify as many dwg's as you like the only hiccup (and maybe a way around) is you work on 1 dwg at a time, but in saying using .net I am sure can allow you to make any dwg as the current dwg then maybe run a lisp etc this way you do not need a list of dwgs, the other way is you can (examples here) pick your dwg names then basicly write a script that modifies the picked dwg's opening and closing. Help someone make a list of open documents write a script close all run script. Any suggestions Edited December 21, 2012 by BIGAL Quote
CADWarrior Posted December 20, 2012 Author Posted December 20, 2012 Any good references on where to get started on .net. Never tried my hand at it. I was going to look into .net but never had a reason to. This is the first thing I haven't been able to do with VLisp. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.