N
no.name
i passed a function thats opens a picked xref, to the cad manager.
i know there both not perfect, but lets compare them anyway.
i was informed that my lisp does too much checking, autocad takes care of
all the errors & users don't need all that chaecking.
managers code is derived from the code i gave him.
which one do you think does a better job ?
help support a lonely old drafter.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
managers lisp
(defun PickXrefOpen (/ olderr sel sdat)
(errorsetup)
(if
(and
(setq sel (entsel "\nSelect Xref: "))
(eq "INSERT" (dxf 0 (setq sdat (entget (car sel)))))
(not (null (pxo:xrefcheck (dxf 2 sdat)))))
(progn
(setq fnam (getfilepath (car sel)))
(pxo
pen fnam))
(princ "\nNope."))
(errorrestore)
)
(defun pxo
pen (fil)
(COMMAND
"vbastmt"
(STRCAT
"AcadApplication.Documents.Open "
(CHR 34)
fil
(CHR 34)
)
)
)
(DEFUN pxo:xrefcheck (bnam)
(OR
(=
(VLA-GET-ISXREF
(VLA-ITEM
(VLA-GET-BLOCKS
(VLA-GET-ACTIVEDOCUMENT
(VLAX-GET-ACAD-OBJECT)))
bnam
)
)
:VLAX-TRUE
)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
my lisp below
;;;Open named drawing file (no error trapping is done!)
;| From newsgroup, it rocks |;
(DEFUN pxto
pendwg (opendwg:fullname)
(SETVAR "cmdecho" 0)
(PRINC "\n")
(COMMAND "vbastmt"
(STRCAT "AcadApplication.Documents.Open " (CHR 34)
opendwg:fullname (CHR 34))
) ;_ end of COMMAND
(SETVAR "cmdecho" 1)
(PRINC (STRCAT "\n " pxto:xrpathname " was opened."))
(PRINC)
) ;_ end of DEFUN
;;;
;|From newsgroup, it rocks |;
(DEFUN pxto:isxref (isxref:bname)
(OR
(= (VLA-GET-ISXREF
(VLA-ITEM (VLA-GET-BLOCKS (VLA-GET-ACTIVEDOCUMENT
(VLAX-GET-ACAD-OBJECT))) ;_ end of VLA-GET-BLOCKS
isxref:bname
) ;_ end of VLA-ITEM
) ;_ end of VLA-GET-ISXREF
:VLAX-TRUE
) ;_ end of =
) ;_ end of OR
) ;_ end of DEFUN
;;;
;| from autocad help file |;
(DEFUN pxto:inlist (inlist:lst inlist:str / inlist:ct tmpstr inlist:ret)
(SETQ inlist:ct 0
inlist:str
(STRCASE inlist:str)
) ;_ end of SETQ
(REPEAT (LENGTH inlist:lst) ;begin repeat
(SETQ tmpstr (STRCASE (NTH inlist:ct inlist:lst)))
(IF (WCMATCH tmpstr (STRCAT "*" inlist:str "*")) ;begin if
(SETQ inlist:ret T)
) ;end if
(SETQ inlist:ct (1+ inlist:ct))
) ;end repeat
inlist:ret ;return T or nil
) ;_ end of DEFUN
;;;
(DEFUN pxto:checkfile ()
(IF (SETQ pxto:fil (OPEN (STRCAT (VL-FILENAME-DIRECTORY pxto:xrpathname)
"\\"
(VL-FILENAME-BASE pxto:xrpathname)
".dwl"
) ;_ end of STRCAT
"r"
) ;_ end of OPEN
) ;_ end of SETQ
(PROGN
(SETQ pxto:user (READ-LINE pxto:fil))
(CLOSE pxto:fil)
(ALERT (STRCAT pxto:xrpathname
"\n\nis currently in use by : \n\n"
pxto:user
"\n\nOpen has FAILED !!"
) ;_ end of STRCAT
) ;_ end of ALERT
) ;_ end of PROGN
;| ALERT |;
(IF (DOS_FILEP pxto:xrpathname)
(ALERT
(STRCAT pxto:xrpathname "\n\nis currently in use !!\n\nOpen has
FAILED !!")
) ;_ end of ALERT
(ALERT (STRCAT pxto:xrpathname "\n\ndoes not exist !!\n\nOpen has
FAILED !!")) ;_ end of ALERT
) ;_ end of IF
) ;_ end of IF
) ;_ end of DEFUN
;;;
;;; cridder
(DEFUN c
xto ;()
(/ pxto:err pxto:ent pxto:dwg-dwgpath pxto:xref-vlaobj
pxto:xref-name pxto:xref-name-dwg pxto:xref-path pxto:xrpathname
pxto:fil pxto:user
)
(IF ;| from autocad help file |;
(NOT (pxto:inlist (ARX) "whohas")) ;if statement is nil
(SETQ pxto:err (ARXLOAD "whohas" nil)) ;then load arx
) ;_ end of IF
(IF (DOS_XREFLIST)
(PROGN
(WHILE (NULL pxto:ent)
(WHILE (NULL pxto:ent) (SETQ pxto:ent (ENTSEL "\n Pick XREF to
OPEN")))
(IF (OR (/= (STRCASE "INSERT") (CDR (ASSOC 0 (ENTGET (CAR
pxto:ent)))))
(NOT (pxto:isxref (CDR (ASSOC 2 (ENTGET (CAR pxto:ent))))))
) ;_ end of OR
(PROGN (PRINC (STRCAT "\t The selected object was not a XREF.
Please try again.") ;_ end of STRCAT
) ;_ end of PRINC
(SETQ pxto:ent nil)
) ;_ end of PROGN
(PROGN (SETQ pxto:dwg-dwgpath (STRCASE (GETVAR "dwgprefix")))
(SETQ pxto:xref-vlaobj (VLAX-ENAME->VLA-OBJECT (CAR
pxto:ent)))
(SETQ pxto:xref-name (STRCASE (VLAX-GET-PROPERTY
pxto:xref-vlaobj 'name)))
(SETQ pxto:xref-name-dwg (STRCAT pxto:xref-name ".DWG"))
(SETQ pxto:xref-path (STRCASE (VLAX-GET-PROPERTY
pxto:xref-vlaobj 'path)))
(COND ((VL-STRING-SEARCH ":" pxto:xref-path)
(PROGN (SETQ pxto:xrpathname pxto:xref-path))
)
((NOT (VL-STRING-SEARCH ":" pxto:xref-path))
(PROGN (SETQ pxto:xrpathname (STRCAT
pxto:dwg-dwgpath pxto:xref-path)))
)
) ;_ end of COND
(COND ((AND (DOS_FILEP pxto:xrpathname) (NOT (DOS_OPENP
pxto:xrpathname)))
(PROGN (pxto
pendwg pxto:xrpathname))
)
((DOS_OPENP pxto:xrpathname) (PROGN
(pxto:checkfile)))
((NOT (DOS_FILEP pxto:xrpathname))
(PROGN
(IF (DOS_FILEP (STRCAT pxto:dwg-dwgpath
(VL-FILENAME-BASE pxto:xref-path) ".dwg"))
(PROGN (SETQ pxto:xrpathname (STRCAT
pxto:dwg-dwgpath (VL-FILENAME-BASE pxto:xref-path) ".dwg"))
(IF (AND (DOS_FILEP pxto:xrpathname) (NOT
(DOS_OPENP pxto:xrpathname)))
(pxto
pendwg pxto:xrpathname)
(pxto:checkfile)
) ;_ end of IF
) ;_ end of progn
(PROGN (SETQ pxto:xrpathname (STRCAT
pxto:dwg-dwgpath (VL-FILENAME-BASE pxto:xref-path) ".dwg"))
(ALERT (STRCAT pxto:xrpathname "\n\ndoes
not exist !!\n\nOpen has FAILED !!"))
) ;_ end of PROGN
) ;_ end of IF
) ;_ end of PROGN
)
) ;_ end of COND
) ;_ end of PROGN
) ;_ end of IF
) ;_ end of WHILE
) ;_ end of PROGN
(PROGN (ALERT "No XREF'S in this drawing !")
) ;_ end of PROGN
) ;_ end of IF
(PRINC)
) ;_ end of DEFUN
(PRINC)
i know there both not perfect, but lets compare them anyway.
i was informed that my lisp does too much checking, autocad takes care of
all the errors & users don't need all that chaecking.
managers code is derived from the code i gave him.
which one do you think does a better job ?
help support a lonely old drafter.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
managers lisp
(defun PickXrefOpen (/ olderr sel sdat)
(errorsetup)
(if
(and
(setq sel (entsel "\nSelect Xref: "))
(eq "INSERT" (dxf 0 (setq sdat (entget (car sel)))))
(not (null (pxo:xrefcheck (dxf 2 sdat)))))
(progn
(setq fnam (getfilepath (car sel)))
(pxo
(princ "\nNope."))
(errorrestore)
)
(defun pxo
(COMMAND
"vbastmt"
(STRCAT
"AcadApplication.Documents.Open "
(CHR 34)
fil
(CHR 34)
)
)
)
(DEFUN pxo:xrefcheck (bnam)
(OR
(=
(VLA-GET-ISXREF
(VLA-ITEM
(VLA-GET-BLOCKS
(VLA-GET-ACTIVEDOCUMENT
(VLAX-GET-ACAD-OBJECT)))
bnam
)
)
:VLAX-TRUE
)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
my lisp below
;;;Open named drawing file (no error trapping is done!)
;| From newsgroup, it rocks |;
(DEFUN pxto
(SETVAR "cmdecho" 0)
(PRINC "\n")
(COMMAND "vbastmt"
(STRCAT "AcadApplication.Documents.Open " (CHR 34)
opendwg:fullname (CHR 34))
) ;_ end of COMMAND
(SETVAR "cmdecho" 1)
(PRINC (STRCAT "\n " pxto:xrpathname " was opened."))
(PRINC)
) ;_ end of DEFUN
;;;
;|From newsgroup, it rocks |;
(DEFUN pxto:isxref (isxref:bname)
(OR
(= (VLA-GET-ISXREF
(VLA-ITEM (VLA-GET-BLOCKS (VLA-GET-ACTIVEDOCUMENT
(VLAX-GET-ACAD-OBJECT))) ;_ end of VLA-GET-BLOCKS
isxref:bname
) ;_ end of VLA-ITEM
) ;_ end of VLA-GET-ISXREF
:VLAX-TRUE
) ;_ end of =
) ;_ end of OR
) ;_ end of DEFUN
;;;
;| from autocad help file |;
(DEFUN pxto:inlist (inlist:lst inlist:str / inlist:ct tmpstr inlist:ret)
(SETQ inlist:ct 0
inlist:str
(STRCASE inlist:str)
) ;_ end of SETQ
(REPEAT (LENGTH inlist:lst) ;begin repeat
(SETQ tmpstr (STRCASE (NTH inlist:ct inlist:lst)))
(IF (WCMATCH tmpstr (STRCAT "*" inlist:str "*")) ;begin if
(SETQ inlist:ret T)
) ;end if
(SETQ inlist:ct (1+ inlist:ct))
) ;end repeat
inlist:ret ;return T or nil
) ;_ end of DEFUN
;;;
(DEFUN pxto:checkfile ()
(IF (SETQ pxto:fil (OPEN (STRCAT (VL-FILENAME-DIRECTORY pxto:xrpathname)
"\\"
(VL-FILENAME-BASE pxto:xrpathname)
".dwl"
) ;_ end of STRCAT
"r"
) ;_ end of OPEN
) ;_ end of SETQ
(PROGN
(SETQ pxto:user (READ-LINE pxto:fil))
(CLOSE pxto:fil)
(ALERT (STRCAT pxto:xrpathname
"\n\nis currently in use by : \n\n"
pxto:user
"\n\nOpen has FAILED !!"
) ;_ end of STRCAT
) ;_ end of ALERT
) ;_ end of PROGN
;| ALERT |;
(IF (DOS_FILEP pxto:xrpathname)
(ALERT
(STRCAT pxto:xrpathname "\n\nis currently in use !!\n\nOpen has
FAILED !!")
) ;_ end of ALERT
(ALERT (STRCAT pxto:xrpathname "\n\ndoes not exist !!\n\nOpen has
FAILED !!")) ;_ end of ALERT
) ;_ end of IF
) ;_ end of IF
) ;_ end of DEFUN
;;;
;;; cridder
(DEFUN c
(/ pxto:err pxto:ent pxto:dwg-dwgpath pxto:xref-vlaobj
pxto:xref-name pxto:xref-name-dwg pxto:xref-path pxto:xrpathname
pxto:fil pxto:user
)
(IF ;| from autocad help file |;
(NOT (pxto:inlist (ARX) "whohas")) ;if statement is nil
(SETQ pxto:err (ARXLOAD "whohas" nil)) ;then load arx
) ;_ end of IF
(IF (DOS_XREFLIST)
(PROGN
(WHILE (NULL pxto:ent)
(WHILE (NULL pxto:ent) (SETQ pxto:ent (ENTSEL "\n Pick XREF to
OPEN")))
(IF (OR (/= (STRCASE "INSERT") (CDR (ASSOC 0 (ENTGET (CAR
pxto:ent)))))
(NOT (pxto:isxref (CDR (ASSOC 2 (ENTGET (CAR pxto:ent))))))
) ;_ end of OR
(PROGN (PRINC (STRCAT "\t The selected object was not a XREF.
Please try again.") ;_ end of STRCAT
) ;_ end of PRINC
(SETQ pxto:ent nil)
) ;_ end of PROGN
(PROGN (SETQ pxto:dwg-dwgpath (STRCASE (GETVAR "dwgprefix")))
(SETQ pxto:xref-vlaobj (VLAX-ENAME->VLA-OBJECT (CAR
pxto:ent)))
(SETQ pxto:xref-name (STRCASE (VLAX-GET-PROPERTY
pxto:xref-vlaobj 'name)))
(SETQ pxto:xref-name-dwg (STRCAT pxto:xref-name ".DWG"))
(SETQ pxto:xref-path (STRCASE (VLAX-GET-PROPERTY
pxto:xref-vlaobj 'path)))
(COND ((VL-STRING-SEARCH ":" pxto:xref-path)
(PROGN (SETQ pxto:xrpathname pxto:xref-path))
)
((NOT (VL-STRING-SEARCH ":" pxto:xref-path))
(PROGN (SETQ pxto:xrpathname (STRCAT
pxto:dwg-dwgpath pxto:xref-path)))
)
) ;_ end of COND
(COND ((AND (DOS_FILEP pxto:xrpathname) (NOT (DOS_OPENP
pxto:xrpathname)))
(PROGN (pxto
)
((DOS_OPENP pxto:xrpathname) (PROGN
(pxto:checkfile)))
((NOT (DOS_FILEP pxto:xrpathname))
(PROGN
(IF (DOS_FILEP (STRCAT pxto:dwg-dwgpath
(VL-FILENAME-BASE pxto:xref-path) ".dwg"))
(PROGN (SETQ pxto:xrpathname (STRCAT
pxto:dwg-dwgpath (VL-FILENAME-BASE pxto:xref-path) ".dwg"))
(IF (AND (DOS_FILEP pxto:xrpathname) (NOT
(DOS_OPENP pxto:xrpathname)))
(pxto
(pxto:checkfile)
) ;_ end of IF
) ;_ end of progn
(PROGN (SETQ pxto:xrpathname (STRCAT
pxto:dwg-dwgpath (VL-FILENAME-BASE pxto:xref-path) ".dwg"))
(ALERT (STRCAT pxto:xrpathname "\n\ndoes
not exist !!\n\nOpen has FAILED !!"))
) ;_ end of PROGN
) ;_ end of IF
) ;_ end of PROGN
)
) ;_ end of COND
) ;_ end of PROGN
) ;_ end of IF
) ;_ end of WHILE
) ;_ end of PROGN
(PROGN (ALERT "No XREF'S in this drawing !")
) ;_ end of PROGN
) ;_ end of IF
(PRINC)
) ;_ end of DEFUN
(PRINC)