TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Hangman on January 05, 2007, 04:35:16 PM
-
I want to pick on an xref and open the drawing as a second drawing or MDI.
But when I use the (command ".open" ... ), It comes back saying unrecognizable command.
Command: (command ".open" blk-path)
.open
Command: D:\temp\Tests\Xref\2.dwg Unknown command "D:\TEMP\TESTS\XREF\2.DWG".
Press F1 for help.
I've tried using ".fileopen", but it comes back saying it has to establish SDI mode in order to open.
Command: (command ".fileopen" blk-path)
.fileopen
Cannot run FILEOPEN if SDI mode cannot be established.
Command: D:\temp\Tests\Xref\2.dwg Unknown command "D:\TEMP\TESTS\XREF\2.DWG".
Press F1 for help.
I'm using AutoLisp 'cause I don't know VLA yet.
If this is no longer possible with AutoLisp, can someone help me integrate it into my code ??
Thanks,
-
Here is how I do it.
(defun MyOpen (FileName ReadOnly)
(vla-Open
(vla-get-Documents
(vlax-get-Acad-Object)
)
FileName
(if ReadOnly
:vlax-true
:vlax-false
)
)
)
-
Thanks Tim for your quick response.
So, would I work it in something like ... (I'm just reading and editing this here, I haven't tried it yet.)
vl-load-com
...
(command ".undo" "be")
(setq echoprv (getvar "cmdecho")
old_err *error*
*error* $error
fdiaprv (getvar "filedia")
SDIprev (getvar "SDI"))
(setvar "cmdecho" 1)
(setvar "filedia" 0)
(setvar "SDI" 0); Some users like SDI, but want to be able to open another drawing on the fly.
;
(while (/= xref-type "INSERT")
(setq xref-1 (entsel "\nSelect XREF to open for editing: "))
(while (= xref-1 nil)
(setq xref-1 (entsel "\nSelect XREF to open for editing: ")))
(setq xref-2 (car xref-1)); gets entity name
(setq xref-data (entget xref-2)); gets entity data
(setq xref-type (cdr (assoc 0 xref-data)))); determines entity type
;
(setq blk-name (cdr (assoc 2 xref-data))); gets xref name
(setq blk-list (tblsearch "block" blk-name)); gets xref location info
(setq blk-path (cdr (assoc 1 blk-list))); gets xref path
(vla-Open
(vla-get-Documents
(vlax-get-Acad-Object))
blk-path ;;; ???? D:\temp\Tests\Xref\2.dwg ????
(if ReadOnly
:vlax-true
:vlax-false))
;;;(command ".open" blk-path)
;
(setvar "filedia" fdiaprv)
(setvar "SDI" SDIprev)
(setvar "cmdecho" echoprv)
(princ)
)
If I drop in the blk-path , will it read the entire path ?? Or do I have to spell it out ??
Thanks,
-
If the path returns a full path, then yea, but you will need to provide something else as to the 'ReadOnly' variable now. See below.
(vla-Open
(vla-get-Documents
(vlax-get-Acad-Object))
blk-path ;;; ???? D:\temp\Tests\Xref\2.dwg ????
(if ReadOnly
:vlax-true
:vlax-false))
Since you will most likely be making changes to the file, I would just make it look like
(vla-Open
(vla-get-Documents
(vlax-get-Acad-Object))
blk-path ;;; ???? D:\temp\Tests\Xref\2.dwg ????
:vlax-false)
Edit: One way to make sure that what is returned is a full path is to use findfile, so something like
(vla-Open
(vla-get-Documents
(vlax-get-Acad-Object))
(findfile blk-path) ;;; ???? D:\temp\Tests\Xref\2.dwg ????
:vlax-false)
-
OK,
so, 2 questions now.
1st, does the ReadOnly set the properties of the drawing to what is specified ??
another words, in the second example, you have only the :vlax-false
Does this set the properties of the drawing to read-write access if the drawing is currently read-only ??
2nd, will this make the new drawing being opened, the active document ?? Or does it open the drawing and then switch back to the original ??
I'm going to go try this & see what I can get, wish me luck :-)
-
1. - This will tell Acad to open it as read only or not. True = read only.
2. - It will open the drawing, make it active, and then switch back to the original drawing. If you want the other one to be active, then you will have to put a statement like
(command "_.vbastmt" (strcat "documents.item \(\"" (vl-filename-base blk-path) "\"\).activate"))
Which has to be the last line in the lisp code (even if it's not, it will be executed at the end of the lisp).
-
Hey Tim,
It's working well with one exception, Your last line of code.
2. - It will open the drawing, make it active, and then switch back to the original drawing. If you want the other one to be active, then you will have to put a statement like
Code:
(command "_.vbastmt" (strcat "documents.item \(\"" (vl-filename-base blk-path) "\"\).activate"))
Which has to be the last line in the lisp code (even if it's not, it will be executed at the end of the lisp).
It gave me an error:
Runtime error '-2147467259 (80004005)':
Automation error
Unspecified error
Here's what I have:
(command ".undo" "be");Begin recording .undo information
(setq echoprv (getvar "cmdecho")
old_err *error*
*error* $error
fdiaprv (getvar "filedia")
SDIprev (getvar "SDI"))
(setvar "cmdecho" 1)
(setvar "filedia" 0)
(setvar "SDI" 0)
;
(while (/= xref-type "INSERT")
(setq xref-1 (entsel "\nSelect XREF to open for editing: "))
(while (= xref-1 nil)
(setq xref-1 (entsel "\nSelect XREF to open for editing: ")))
(setq xref-2 (car xref-1)); gets entity name
(setq xref-data (entget xref-2)); gets entity data
(setq xref-type (cdr (assoc 0 xref-data)))); determines entity type
;
(setq blk-name (cdr (assoc 2 xref-data))); gets xref name
(setq blk-list (tblsearch "block" blk-name)); gets xref location info
(setq blk-path (cdr (assoc 1 blk-list))); gets xref path
(vla-Open
(vla-get-Documents
(vlax-get-Acad-Object))
(findfile blk-path)
:vlax-false)
;
(setvar "filedia" fdiaprv)
(setvar "SDI" SDIprev)
(setvar "cmdecho" echoprv)
(command "_.vbastmt" (strcat "documents.item \(\"" (vl-filename-base blk-path) "\"\).activate"))
(princ)
)
-
Glad to hear it's almost there. I guess the last line should be
(command "_.vbastmt" (strcat "documents.item \(\"" (vl-filename-base blk-path) ".dwg\"\).activate"))
It should work now that the file extention is added, sorry about that.
-
Hey, that did the trick. Boy I've gotta learn this stuff.
Ya know, r2007 is not all it's cracked up to be. It takes almost twice as long to load a drawing than it did in '06.
Thanks Tim.
-
Hey, that did the trick. Boy I've gotta learn this stuff.
Ya know, r2007 is not all it's cracked up to be. It takes almost twice as long to load a drawing than it did in '06.
Thanks Tim.
Maybe that is why my company skipped 07 and is waiting to evaluate 08.
You're welcome.
-
don't know... but have you tried this one:
http://www.theswamp.org/index.php?topic=9441.msg172497#msg172497