giskumar Posted June 23, 2011 Share Posted June 23, 2011 Hi All, I just want to read the list of layers of an autocad file with out open it. Is this possible with lisp? Thanks, Kumar. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 23, 2011 Share Posted June 23, 2011 (edited) This could be done through ObjectDBX, as the following code demonstrates: (defun c:test ( / doc file lst ) (if (and (setq file (getfiled "Select Drawing" "" "dwg;dwt;dws" 16)) (setq doc (LM:GetDocumentObject (vlax-get-acad-object) file)) ) (progn (vlax-for l (vla-get-layers doc) (setq lst (cons (vla-get-name l) lst))) (vlax-release-object doc) ) ) (reverse lst) ) ;;-----------------=={ Get Document Object }==----------------;; ;; ;; ;; Retrieves a the VLA Document Object for the specified ;; ;; filename. Document Object may be present in the Documents ;; ;; collection, or obtained through ObjectDBX ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; acapp - AutoCAD Application Object ;; ;; filename - filename for which to retrieve document object ;; ;;------------------------------------------------------------;; ;; Returns: VLA Document Object, else nil ;; ;;------------------------------------------------------------;; (defun LM:GetDocumentObject ( acapp filename / acdocs dbx ) (vlax-for doc (vla-get-Documents acapp) (setq acdocs (cons (cons (strcase (vla-get-fullname doc)) doc) acdocs)) ) (cond ( (not (setq filename (findfile filename))) nil ) ( (cdr (assoc (strcase filename) acdocs)) ) ( (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list (setq dbx (LM:ObjectDBXDocument acapp)) filename) ) ) ) dbx ) ) ) ;;-----------------=={ ObjectDBX Document }==-----------------;; ;; ;; ;; Retrieves a version specific ObjectDBX Document object ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; acapp - AutoCAD Application Object ;; ;;------------------------------------------------------------;; ;; Returns: VLA ObjectDBX Document object, else nil ;; ;;------------------------------------------------------------;; (defun LM:ObjectDBXDocument ( acapp / acver ) (vla-GetInterfaceObject acapp (if (< (setq acver (atoi (getvar "ACADVER"))) 16) "ObjectDBX.AxDbDocument" (strcat "ObjectDBX.AxDbDocument." (itoa acver)) ) ) ) (vl-load-com) (princ) An extension of this idea is used in this program. Edited June 24, 2011 by Lee Mac Quote Link to comment Share on other sites More sharing options...
giskumar Posted June 23, 2011 Author Share Posted June 23, 2011 Hi Lee, thanks for the quick responce. I have changed the function as below to add a layer to file. Not getting error but no layer is added to file. Please tell me where i am doing wrong. (defun c:test ( / doc file ) (if (and (setq file (getfiled "Select Drawing" "" "dwg;dwt;dws" 16)) (setq doc (GetDocumentObject (vlax-get-acad-object) file)) ) (progn (setq LayerTable (vla-get-layers doc)) (setq aNewLayer (vla-add LayerTable "TestLayer")) (vla-put-color aNewLayer 2) (vlax-release-object doc) ) ) (reverse lst) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 23, 2011 Share Posted June 23, 2011 I have changed the function as below to add a layer to file.Not getting error but no layer is added to file. You will need to save the file after adding the layer. Why has this now become: ? ... (setq doc ([color=red][b]GetDocumentObject[/b][/color] (vlax-get-acad-object) file)) ... Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 23, 2011 Share Posted June 23, 2011 Why has this now become: ? What is "How to steal someone else's idea to take full credit for themselves?" OoooOoo, sooory, sooory. The correct answer is "What is a schmuck?" Quote Link to comment Share on other sites More sharing options...
giskumar Posted June 23, 2011 Author Share Posted June 23, 2011 Sorry guys I don't want to take that credit. As a part of explaining it to a very much fresher i just removed it to prove that we can use any name for the functions. unfortunately i have copied that one. The below header is still in my original program. Same time thanks to Lee for the quick help. ;;-----------------=={ Get Document Object }==----------------;; ;; ;; ;; Retrieves a the VLA Document Object for the specified ;; ;; filename. Document Object may be present in the Documents ;; ;; collection, or obtained through ObjectDBX ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; acapp - AutoCAD Application Object ;; ;; filename - filename for which to retrieve document object ;; ;;------------------------------------------------------------;; ;; Returns: VLA Document Object, else nil ;; ;;------------------------------------------------------------;; Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 23, 2011 Share Posted June 23, 2011 Perhaps my attempt at humor was a bit pointed. I think you understand though, that those who volunteer their work for the benefit of others (i.e., do so for free), simply want credit where credit is due. Nothing more. I don't want to take that credit. As a part of explaining it to a very much fresher i just removed it to prove that we can use any name for the functions. unfortunately i have copied that one. The below header is still in my original program. Same time thanks to Lee for the quick help. Well, now you know... and knowing is: Quote Link to comment Share on other sites More sharing options...
giskumar Posted June 24, 2011 Author Share Posted June 24, 2011 Hi All, After adding layer to the document, I tried to save document using (vla-save doc) But it returns the following error. ; error: Automation Error. Description was not provided. I also noticed that it is working fine with currently opened active drawings. (setq thisdrawing (vla-get-activedocument (vlax-get-acad-object))) (vla-save thisdrawing ) Please let me know how can i save my document after adding layers to it. Thanks, Kumar. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 24, 2011 Share Posted June 24, 2011 Change the calling function to this: (defun c:test ( / doc file ) (if (and (setq file (getfiled "Select Drawing" "" "dwg;dwt;dws" 16)) (setq doc (LM:GetDocumentObject (vlax-get-acad-object) file)) ) (progn (setq layer (vla-add (vla-get-layers doc) "TestLayer")) (vla-put-color layer 2) (vla-saveas doc file) (vlax-release-object doc) ) ) (princ) ) You need to use the SaveAs method when working with ObjectDBX. Quote Link to comment Share on other sites More sharing options...
giskumar Posted June 28, 2011 Author Share Posted June 28, 2011 Thanks Lee It working great...... Quote Link to comment Share on other sites More sharing options...
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.