Message 1 of 15
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, everyone.
I realized I had previously posted this question on the wrong forum (which is I why I was receiving no response...)
I'm pretty new to coding error catching (and ObjectDBX as well), and have been trying to fix a possible error that happens in this routine:
; Checks if it is possible to insert block (defun checkBlock (chkBlock chkFile / ) (vl-load-com) ; Check block: (if (tblsearch "block" chkBlock) ; checks whether block exists in current drawing (insertBlock chkBlock) ; insert if block already exists in current file (progn ; if block does not exist in current file, move on to next step (if (findfile chkFile) ; check if file exists (progn ; if found, insert block from drawing (borrowBlockDBX chkBlock chkFile) (insertBlock chkBlock) ) (princ "\nBlock container file not found") ) ) ) ) ; Insert block: (defun insertBlock (blockName / ) (command "-INSERT" blockName PAUSE "1" "1") (while (> (getvar 'CMDACTIVE) 0) (command PAUSE) ) ) (defun borrowBlockDBX (dbxBlock dbxFile / borrowDBX) (setq borrowDBX (openFileDBX dbxFile)) (vla-CopyObjects borrowDBX (vlax-safearray-fill (vlax-make-safearray vlax-vbObject '(0 . 0)) (list (vla-item (vla-get-blocks borrowDBX) dbxBlock)) ) (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) ) (vlax-release-object borrowDBX) ; Clean-up ) (defun openFileDBX (dbxFile / dbxOpen) (if (setq dbxOpen (vlax-create-object (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2) ) ) ) (if (vl-catch-all-apply 'vla-open (list dbxOpen dbxFile)) (not (vlax-release-object dbxOpen)) dbxOpen ) (princ "\nUnable to create object") ) )
The pseudo-code is basically this:
- check if desired block (chkBlock) is already defined in current drawing
- if it is there, just go through the insert command
- if it is not, check if provided filepath drawing (chkFile) exists
- if it exists, try to open that file in the background (DBX), and copy that block's definition from that file to the current one and close the background file - then go through the insert command
- if it can't open the file, warn the user that the file is opened by someone else
So far, it works like a charm - unless the background file is in use by someone else, then it stops and gives me error messages. I already put an error catch in the openFileDBX function, but it doesn't quite work and I can't understand why...
Thanks in advance,
Edgar
Solved! Go to Solution.