I'm looking to process a bunch of drawings with objectDBX.
As a start, I want to:
open a drawing
draw a rectangle from 0,0 to 5,5
get a crossing selection set from 0,0 to 10,10 & store to a variable.
Pinching & tweaking from previous google searches (thanks to Lee Mac & T. Willey) I have the following:
Annotations are mine, any corrections gratefully received. I'm unsure 'pointer' is the correct terminology, but hey.
;$dwg = valid filename
;returns = nil or AcadDocument
(defun _GetDocObj ( $dwg / app dbx doc)
(cond
;check that the file exists & is the one we expect
((not (equal (vl-string-translate "/" "\\" $dwg)
(vl-string-translate "/" "\\" (findfile $dwg))
))
(prompt "\nFile in multiple places?")
nil
)
;check that the $dwg is not open, ie a member of the open documents in this acad object
((member $dwg (vlax-for doc (vla-get-Documents (setq app (vlax-get-acad-object)))))
(prompt "\nFile open")
nil
)
;get the dbx pointer for current acad doc
((not (setq dbx
(vl-catch-all-apply
'vla-GetInterfaceObject
(list
app
(if (< (atoi (setq #oVer (substr (getvar "acadver") 1 2))) 16)
"ObjectDBX.AxDbDocument"
(strcat "ObjectDBX.AxDbDocument." #oVer))
))))
(prompt "\nObjectDBX failed")
nil
)
;if the pointer is null or is an error
((or (null dbx)(vl-catch-all-error-p dbx))
(prompt "\nObjectDBX failed")
nil
)
;try to open the dbx document
((vl-catch-all-error-p (setq doc (vl-catch-all-apply 'vla-open (list dbx $dwg))))
(prompt "\nOpen failed")
nil
)
(T doc)
);cond
)
This all runs fine, assuming I have a valid filename, apart from doc returns nil.
dbx returns an Acad database object (AxDbDocument) rather than a document object (AcadDocument), so I cant use (vla-activate) on this to make it current, thus can't do the line drawing & selection setting etc. I can hopefully work these bits out on my own from googleable stuff, but how to get the Drawing object of the newly opened drawing has me stumped.
Does anyone have any suggestions?
Many thanks in advance.