TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: whdjr on October 19, 2004, 09:24:05 AM

Title: What am I doing wrong?
Post by: whdjr on October 19, 2004, 09:24:05 AM
I am trying to read data from a dwg that is open, but may or may not be active.  I am using the vla-item method to acces one of the dwg's from the documents collection, but my syntax is wrong or something.  I not sure.  Could you guys help me out?
Code: [Select]
;*docs* = (vla-get-documents (vlax-get-acad-object))
;document = "Y:\\Common\\Projects\\School\\0303\\index of drawings.dwg"


(vla-item *docs* document)


What am I doing wrong?
Please help me?
Title: What am I doing wrong?
Post by: whdjr on October 19, 2004, 09:38:00 AM
Ok
I managed to get this to work, but is there a away to not have to use strcat?

Quote
(vla-item *docs* (strcat (vl-filename-base document) ".dwg"))
Title: What am I doing wrong?
Post by: Mark on October 19, 2004, 09:38:32 AM
Try this;
Code: [Select]

(setq docs (vla-get-documents (vlax-get-acad-object)))

(vlax-for dwg docs
  (setq doc_lst (cons (vla-get-name dwg) doc_lst))
  )

; doc_lst = ("ARC.dwg" "0104-296.dwg" "710-151.dwg")

(setq dwg1 (vla-item docs (last doc_lst)))

; dwg1 = #<VLA-OBJECT IAcadDocument 01117570>
Title: What am I doing wrong?
Post by: Mark on October 19, 2004, 09:40:22 AM
The dwg is loaded into acad right?
Title: What am I doing wrong?
Post by: whdjr on October 19, 2004, 09:44:33 AM
Mark,

I knew I could use vlax-for I just didn't want to have to iterate through the docs because I knew the file I wanted and it is loaded.
Title: What am I doing wrong?
Post by: SMadsen on October 19, 2004, 09:57:20 AM
I think what Mark was trying to tell is that when using VLA-ITEM by name, it should be the name without path - as returned by the document's Name property.
So your strcat and filename-base thingie would be a proper way to extract the name.
Title: What am I doing wrong?
Post by: whdjr on October 19, 2004, 10:02:37 AM
Thanks guys.

I appreciate the responses.
Title: What am I doing wrong?
Post by: Mark on October 19, 2004, 10:07:20 AM
Also;
Code: [Select]

(setq docs (vla-get-documents (vlax-get-acad-object)))

(reverse
  (vlax-for dwg docs
(setq doc_lst (cons (vla-get-name dwg) doc_lst))
)
  )

; doc_lst = ("710-151.dwg" "0104-296.dwg" "ARC.dwg")

; we know we want "710-151.dwg" so how about this

(setq this_dwg (vla-item docs (vl-position "710-151.dwg" doc_lst)))
Title: What am I doing wrong?
Post by: Keith™ on October 19, 2004, 10:13:53 AM
Ok Stig.. you lost me on that ....tis ok ... I frequently get lost .....
After looking at it a little closer I think I understand now .....

and you are correct strcat with filename-base is the short way around the problem.