Hippe013 Posted November 29, 2011 Posted November 29, 2011 I am looking for a way to open a dwg to look at the objects within via vlisp without actually opening the drawing. Is this possible? Thank you in Advance hippe013 Quote
Tharwat Posted November 29, 2011 Posted November 29, 2011 What are you looking to investigate into your drawing ? Quote
ReMark Posted November 29, 2011 Posted November 29, 2011 Darned if we just didn't have a very similar question recently. I swear it was within the last couple of weeks. Quote
Lee Mac Posted November 29, 2011 Posted November 29, 2011 I am looking for a way to open a dwg to look at the objects within via vlisp without actually opening the drawing. Is this possible? Yes, using ObjectDBX. Quote
Tharwat Posted November 29, 2011 Posted November 29, 2011 Darned if we just didn't have a very similar question recently. I swear it was within the last couple of weeks. Certainly you mean this . http://www.cadtutor.net/forum/showthread.php?64533-Import-data-from-more-AutoCAD-file-without-opening Quote
ReMark Posted November 29, 2011 Posted November 29, 2011 That's the thread I was thinking of. Thanks. Quote
Lee Mac Posted November 29, 2011 Posted November 29, 2011 (edited) If you are looking to interface with a single drawing (i.e. not intending to iterate over multiple drawings within a loop), consider the following function: [color=GREEN];;-----------------=={ Get Document Object }==----------------;;[/color] [color=GREEN];; ;;[/color] [color=GREEN];; Retrieves the VLA Document Object for the specified ;;[/color] [color=GREEN];; filename. Document Object may be present in the Documents ;;[/color] [color=GREEN];; collection, or obtained through ObjectDBX ;;[/color] [color=GREEN];; ;;[/color] [color=GREEN];; It is the callers responsibility to release such object. ;;[/color] [color=GREEN];;------------------------------------------------------------;;[/color] [color=GREEN];; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;[/color] [color=GREEN];;------------------------------------------------------------;;[/color] [color=GREEN];; Arguments: ;;[/color] [color=GREEN];; filename - filename for which to retrieve document object ;;[/color] [color=GREEN];;------------------------------------------------------------;;[/color] [color=GREEN];; Returns: VLA Document Object, else nil ;;[/color] [color=GREEN];;------------------------------------------------------------;;[/color] ([color=BLUE]defun[/color] LM:GetDocumentObject ( filename [color=BLUE]/[/color] acdocs acapp dbxdoc ) ([color=BLUE]cond[/color] ( ([color=BLUE]not[/color] ([color=BLUE]setq[/color] filename ([color=BLUE]findfile[/color] filename))) [color=BLUE]nil[/color] ) ( ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] ([color=BLUE]strcase[/color] filename) ([color=BLUE]vlax-for[/color] doc ([color=BLUE]vla-get-documents[/color] ([color=BLUE]setq[/color] acapp ([color=BLUE]vlax-get-acad-object[/color]))) ([color=BLUE]setq[/color] acdocs ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] ([color=BLUE]strcase[/color] ([color=BLUE]vla-get-fullname[/color] doc)) doc) acdocs) ) ) ) ) ) ( ([color=BLUE]not[/color] ([color=BLUE]vl-catch-all-error-p[/color] ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vla-open[/color] ([color=BLUE]list[/color] ([color=BLUE]setq[/color] dbxdoc (LM:ObjectDBXDocument acapp)) filename) ) ) ) dbxdoc ) ) ) [color=GREEN];;-----------------=={ ObjectDBX Document }==-----------------;;[/color] [color=GREEN];; ;;[/color] [color=GREEN];; Retrieves a version specific ObjectDBX Document object ;;[/color] [color=GREEN];;------------------------------------------------------------;;[/color] [color=GREEN];; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;[/color] [color=GREEN];;------------------------------------------------------------;;[/color] [color=GREEN];; Arguments: ;;[/color] [color=GREEN];; acapp - AutoCAD VLA Application Object ;;[/color] [color=GREEN];;------------------------------------------------------------;;[/color] [color=GREEN];; Returns: VLA ObjectDBX Document object, else nil ;;[/color] [color=GREEN];;------------------------------------------------------------;;[/color] ([color=BLUE]defun[/color] LM:ObjectDBXDocument ( acapp [color=BLUE]/[/color] acver ) ([color=BLUE]vla-GetInterfaceObject[/color] acapp ([color=BLUE]if[/color] ([color=BLUE]<[/color] ([color=BLUE]setq[/color] acver ([color=BLUE]atoi[/color] ([color=BLUE]getvar[/color] [color=MAROON]"ACADVER"[/color]))) 16) [color=MAROON]"ObjectDBX.AxDbDocument"[/color] ([color=BLUE]strcat[/color] [color=MAROON]"ObjectDBX.AxDbDocument."[/color] ([color=BLUE]itoa[/color] acver)) ) ) ) The above function 'GetDocumentObject' will return the VLA Document Object for a supplied filename (if possible). Note: it is the caller's responsibility to release the object returned by this function. The reason I discourage its usage within a looping construct is that it will iterate over the Documents Collection and potentially create an ObjectDBX Document object for every drawing in the loop, which is extremely inefficient indeed. After obtaining the VLA Document Object for the filename, this Document Object can be interfaced in much the same way as you would with the ActiveDocument Object. However, since the Document Object may be an ObjectDBX Document, some collections / properties may not be accessible. I assume you know the 'rules' of ObjectDBX, e.g. No use of SelectionSets / No access to System Variables / No use of ent* methods to update objects / etc etc. Lee Edited November 29, 2011 by Lee Mac I has a grammar Quote
Lee Mac Posted November 29, 2011 Posted November 29, 2011 Interesting post, Lee. Cheers RenderMan Quote
Hippe013 Posted November 29, 2011 Author Posted November 29, 2011 All right! Thank you everyone for such a quick response. Lee, looking through your code it looks as if that would work for what I am trying to do. I am not too familar with ObjectDBX, so this will be a great learning experience! I am looking to compare two drawings. Looking for similar linework, blocks, text and etc... I will need to repeat this process for several drawings. So I was a little dissapointed when you said that I couldn't use loops. So my function would be something as follows: I have drawings A1, A2, A3... An & drawings B1, B2, B3... Bn Open dwg A1 Open dwg B1 Compare A1 to B1 - Looking for similar linework, blocks, text & etc... Write to a text file some sort of report. I want to do this sorta behind the scenes so that they wouldn't be actually opened in the editor so to speak. So I will start with this and do a bit of experimenting. Thank you! regards, hippe013 Repeat command for the each set of drawings. Quote
Lee Mac Posted November 29, 2011 Posted November 29, 2011 I will need to repeat this process for several drawings. So I was a little dissapointed when you said that I couldn't use loops. I'm not saying you can't use loops; only that the function I have posted above will be highly inefficient if used within a loop. I use it when interfacing with a single drawing, such as in my 'Steal' program. When iterating over multiple drawings, I recommend you construct the list of open Documents, create the ObjectDBX Document Object, then use the logic demonstrated in my above function for each drawing to be opened. [ Hence, not creating the list of open Documents for each drawing, and also only creating one instance of the ObjectDBX Document, which is released only after all drawings have been processed ]. Here are some implementations of ObjectDBX for you to study: Layer Extractor Batch Find & Replace Text Global Attribute Extractor & Editor Reset XRef Layers Steal from Drawing Copy to XRef Copy to Drawing Copy Block from Drawing Copy or Rename Block ObjectDBX Wrapper Quote
Hippe013 Posted November 30, 2011 Author Posted November 30, 2011 Thanks Lee! This will be great material to get me started. I took a look at the other thread that was suggested. It didn't seem to be too helpful (mostly talk of the OPS inappropriate language). I can't understand why someone would post it, especially while asking for help. Well anyways, I appreciate your help! I will look into these and see what i can come up with. regards, hippe013 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.