ripuz Posted May 5, 2015 Posted May 5, 2015 Hi, I want to prevent a layer from being plotted and I have found a few ways to do this but which way is the best? 1. (command "_.-layer" "p" "n" "LAYERNAME" "") 2. (defun PlotLayer2 (layerName bool / en output) (if (setq en (tblobjname "LAYER" layerName)) (progn (entmod (subst (cons 290 (if bool 1 0)) (assoc 290 (entget en)) (entget en))) (setq output T) ) ) output ) 3. (defun PlotLayer3 (layerName bool / acadObj doc layers layer output) (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-activedocument acadObj)) (setq layers (vla-get-layers doc)) (setq layer (vl-catch-all-apply 'vla-item (list layers layerName))) (if (not (vl-catch-all-error-p layer)) (progn (vla-put-plottable layer (if bool :vlax-true :vlax-false)) (vlax-release-object layer) (setq output T) ) ) (mapcar 'vlax-release-object (list layers doc acadObj)) output ) I know that it doesn´t play a big role in this example, but which is the best programming technique theoretically? Is it needed to release the objects in PlotLayer3? Thanks in advance! Quote
Tharwat Posted May 5, 2015 Posted May 5, 2015 (edited) To deal with Vanilla AutoLISP is much faster than command Calls and Visual Lisp methods . Have a look at the way that I rewrite the codes . (defun PlotLayer2 (layerName bool / en ) (if (setq en (tblobjname "LAYER" layerName )) (entmod (subst (cons 290 (if bool 1 0)) (assoc 290 (entget en)) (entget en))) ) ) Edited May 6, 2015 by Tharwat Quote
Lee Mac Posted May 5, 2015 Posted May 5, 2015 Have a look at the way that I rewrite the codes . (defun PlotLayer2 (layerName bool / en ) (if (and bool (setq en (tblobjname "LAYER" "0"))) (entmod (subst (cons 290 (if bool 1 0)) (assoc 290 (entget en)) (entget en))) ) bool ) Careful with your and expression - note that the function will not make any modifications to the layer if the 'bool' argument is nil. Perhaps something along the lines of the following will suffice: (defun plotlayer2 ( lay flg / ent ) (if (setq ent (tblobjname "layer" lay)) (entmod (setq ent (entget ent) ent (subst (if flg '(290 . 1) '(290 . 0)) (assoc 290 ent) ent) ) ) ) ) Quote
Lee Mac Posted May 5, 2015 Posted May 5, 2015 Is it needed to release the objects in PlotLayer3? This has been discussed for several years - the general consensus is that AutoCAD will automatically release ActiveX objects which derive from the AutoCAD Application Object; objects outside of the AutoCAD Object Model (e.g. ActiveX objects derived from the Excel Application Object, or some other interface) must be 'manually' released from memory using vlax-release-object. Quote
Tharwat Posted May 6, 2015 Posted May 6, 2015 Careful with your and expression - note that the function will not make any modifications to the layer if the 'bool' argument is nil. Correct , I updated the codes . Thank you . Quote
ripuz Posted May 6, 2015 Author Posted May 6, 2015 To deal with Vanilla AutoLISP is much faster than command Calls and Visual Lisp methods . Have a look at the way that I rewrite the codes . (defun PlotLayer2 (layerName bool / en ) (if (setq en (tblobjname "LAYER" "0")) (entmod (subst (cons 290 (if bool 1 0)) (assoc 290 (entget en)) (entget en))) ) ) What I can see all you have done is removed the answer part?! In your defun you will get either nil or the entmod-answer as answer of the function, instead of T/nil. I also see that you have a constant layername but I guess that´s just a misstake. I tried to find a definition of Vanilla AutoLISP and Visual Lisp. Do I understand this right: Vanilla AutoLISP = Functions that handles entities (code like nr 2 in the original post)? Visual Lisp = Functions that handles vla-objects (vla-, vlax- etc.)? Is this a general rule then: If you can do what you want with enities (like entmod etc.) then it´s not a good idea to use vla-objects to do it? Quote
ripuz Posted May 6, 2015 Author Posted May 6, 2015 This has been discussed for several years - the general consensus is that AutoCAD will automatically release ActiveX objects which derive from the AutoCAD Application Object; objects outside of the AutoCAD Object Model (e.g. ActiveX objects derived from the Excel Application Object, or some other interface) must be 'manually' released from memory using vlax-release-object. That is what I have been experience also. Excel and other external objects will not be released until AutoCAD is closed, if you don´t release the objects with vlax-release-object. It is more difficult to determine if the internal objects really gets released. I thank you for your time Lee. Quote
BIGAL Posted May 7, 2015 Posted May 7, 2015 There is a saying about splitting hairs, you really are into microseconds if your doing a 1 liner using command. What is important here my opinion is the vlax-release. If your playing with 10,000 objects speed starts to creep in. Then methods really start to come to the front, just me I have started use more Vl get & puts as I don't have to worry about remembering dxf codes but use the variable names knowing what i want to change. As has been pointed out using entmod is much faster. Can I detect the difference in speed ? You need to look at the task and make a decision compare lisp to .net the lines of code just increase but do you gain speed with thousannds of objects. 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.