Hi to all, recently I was experimenting with ObjectDBX and I've found out that I can't enable it for some extra simple tasks :
So here is the problem, I want to set current layer in all dozen of dwgs to "0" layer and then make line pt1-pt2...
Code:
(defun CLAYTO0+LIN ( doc adoc / 0lay msp pt1 pt2 ) (vl-load-com)
(setq *lay (vla-get-layers adoc))
(vlax-for lay *lay
(if (= (vla-get-name lay) "0") (setq 0lay lay))
)
(vla-put-activelayer adoc 0lay)
(setq msp (vla-get-modelspace adoc))
(setq pt1 '(0.0 0.0 0.0))
(setq pt2 '(100.0 100.0 100.0))
(vla-addline msp (vlax-3d-point pt1) (vlax-3d-point pt2))
t ;; Success for layer 0
)
(defun C:TEST ( )
(LOAD (findfile "ObjectDBX Wrapper.lsp"))
(LM:ODBX 'CLAYTO0+LIN nil t)
)
Here are my changes to ObjectDBX Wrapper.lsp :
Code:
;;------------------=={ ObjectDBX Wrapper }==-----------------;;
;; ;;
;; Evaluates a function on all drawings in a supplied list ;;
;; or in a selected directory (and subdirectories) ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; foo - a function taking a two arguments ;;
;; (the ODBXDocument) and (the ActiveDocument) ;;
;; ;;
;; dwglst - [Optional] List of DWG Filenames, if nil, ;;
;; BrowseForFolder Dialog is displayed ;;
;; ;;
;; save - Boolean flag determining whether drawings should ;;
;; be saved after function evaluation (T=saved) ;;
;;------------------------------------------------------------;;
;; Returns: List of ((<DWGFilename> . <FunctionResult>)...) ;;
;; ;;
;; <DWGFilename> is the drawing filename string ;;
;; <FunctionResult> is the result of evaluating the function ;;
;; 'foo' on the document object representing the drawing ;;
;; filename - note: this could be an Error Object ;;
;;------------------------------------------------------------;;
(defun LM:ODBX ( foo dwglst save / *error* _ReleaseObject acapp acdoc acdocs dbx dbxx dbxdoc err path result ) (vl-load-com)
(setq acapp (vlax-get-acad-object)
acdoc (vla-get-ActiveDocument acapp)
acdocs (vlax-for x (vla-get-documents acapp) (setq acdocs (cons (cons (strcase (vla-get-fullname x)) x) acdocs)))
dbxdoc (LM:ObjectDBXDocument acapp)
)
(defun *error* ( msg )
(mapcar '_ReleaseObject (list dbx dbxdoc))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ)
)
(defun _ReleaseObject ( obj )
(and obj (eq 'VLA-OBJECT (type obj)) (not (vlax-object-released-p obj))
(not
(vl-catch-all-error-p
(vl-catch-all-apply
(function vlax-release-object) (list obj)
)
)
)
)
)
(if
(setq dwgLst
(cond
( dwgLst )
( (setq Path (LM:DirectoryDialog "Select Directory to Process" nil 832))
(initget "Yes No")
(LM:GetAllFiles Path (eq "Yes" (cond ( (getkword "\nProcess SubDirectories? <Yes> : ") ) ( "Yes" ))) "*.dwg")
)
)
)
(foreach dwg dwgLst
(if
(or (setq dbxx (cdr (assoc (strcase dwg) acdocs)))
(progn
(setq err
(vl-catch-all-apply 'vla-open (list dbxdoc dwg)) dbx dbxdoc
)
(not (vl-catch-all-error-p err))
)
)
(progn
(setq result (cons (cons dwg (vl-catch-all-apply foo (list dbx dbxx))) result))
(if save (vla-saveas dbx dwg))
)
(princ (strcat "\n--> Error Opening File: " (vl-filename-base dwg) ".dwg"))
)
)
)
(mapcar '_ReleaseObject (list dbx dbxdoc))
(reverse Result)
)
;;-------------------=={ Directory Dialog }==-----------------;;
;; ;;
;; Displays a dialog prompting the user to select a folder ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; msg - message to display at top of dialog ;;
;; dir - root directory (or nil) ;;
;; flag - bit coded flag specifying dialog display settings ;;
;;------------------------------------------------------------;;
;; Returns: Selected folder filepath, else nil ;;
;;------------------------------------------------------------;;
(defun LM:DirectoryDialog ( msg dir flag / Shell Fold Self Path )
(vl-catch-all-apply
(function
(lambda ( / ac HWND )
(if
(setq Shell (vla-getInterfaceObject (setq ac (vlax-get-acad-object)) "Shell.Application")
HWND (vl-catch-all-apply 'vla-get-HWND (list ac))
Fold (vlax-invoke-method Shell 'BrowseForFolder (if (vl-catch-all-error-p HWND) 0 HWND) msg flag dir)
)
(setq Self (vlax-get-property Fold 'Self)
Path (vlax-get-property Self 'Path)
Path (vl-string-right-trim "\\" (vl-string-translate "/" "\\" Path))
)
)
)
)
)
(if Self (vlax-release-object Self))
(if Fold (vlax-release-object Fold))
(if Shell (vlax-release-object Shell))
Path
)
;;--------------------=={ Get All Files }==-------------------;;
;; ;;
;; Retrieves all files or those of a specified filetype that ;;
;; reside in a directory (and, optionally, subdirectories) ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; Dir - Directory to search ;;
;; Subs - Boolean, if T, subdirectories are included ;;
;; Filetype - (optional) Filter for filetype (DOS pattern) ;;
;;------------------------------------------------------------;;
;; Returns: List of filenames, else nil if none are found ;;
;;------------------------------------------------------------;;
(defun LM:GetAllFiles ( Dir Subs Filetype / _GetSubFolders )
(defun _GetSubFolders ( folder )
(apply 'append
(mapcar
(function
(lambda ( f )
(cons (setq f (strcat folder "\\" f)) (_GetSubFolders f))
)
)
(vl-remove "." (vl-remove ".." (vl-directory-files folder nil -1)))
)
)
)
(apply 'append
(mapcar
(function
(lambda ( Filepath )
(mapcar
(function
(lambda ( Filename ) (strcat Filepath "\\" Filename))
)
(vl-directory-files Filepath Filetype 1)
)
)
)
(cons Dir (if subs (_GetSubFolders Dir)))
)
)
)
;;-----------------=={ ObjectDBX Document }==-----------------;;
;; ;;
;; Retrieves a version specific ObjectDBX Document object ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; _acad - AutoCAD VLA Application Object ;;
;;------------------------------------------------------------;;
;; Returns: VLA ObjectDBX Document object, else nil ;;
;;------------------------------------------------------------;;
(defun LM:ObjectDBXDocument ( _acad / acVer )
(vla-GetInterfaceObject _acad
(if (< (setq acVer (atoi (getvar "ACADVER"))) 16)
"ObjectDBX.AxDbDocument" (strcat "ObjectDBX.AxDbDocument." (itoa acVer))
)
)
)
;;------------------------------------------------------------;;
;; End of File ;;
;;------------------------------------------------------------;;
I keep getting %catch-all-apply-error% and I don't quite understand why...
If it is possible to do this simple tasks in other way or fix my error, please reply...
Thanks, M.R.