PDA

View Full Version : lsp routine update


charlielgolden
2007-10-18, 04:10 PM
I have a lsp that has worked on previous versions of autocad (200, 2000i,2004) but does not work on 2006.

;**************************************************************************8
; xfix.LSP
;
; XREF updates - changes the insertion layer of all xrefs to their file name
; and locks the layer
;
;***************************************************************************


;;********************************************************
;; Load up the list box
(defun get_xrefs_ins ()
(setq XLIST '())
(setq XTEMP (tblnext "block" t))
(setq XLIST (append XLIST (list (cons -4 "<OR"))))
(while XTEMP
(if (cdr (assoc 1 XTEMP))
(setq XLIST (append XLIST (list (assoc 2 XTEMP))))
)
(setq XTEMP (tblnext "block"))
)
(setq XLIST (append XLIST (list (cons -4 "OR>"))))
)

;;********************************************************
;; Get all references of an xref in the drawing

(defun c:xfix (/ Kount Kount2 entas refs locklist)

(setq Kount 0)
(setq Kount2 0)
(setq oldcmdecho (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq list1 '())
(get_xrefs_ins)

(if (setq refs (ssget "X" XLIST))
(progn

(princ
"\nFinding insertion layers of all xrefs - please wait"
)
(while (< Kount (sslength refs))

(setq entas (entget (ssname refs Kount)))
(setq locklist (cdr (assoc 8 entas)))
(setq list1 (cons locklist list1))
(if (/= (cdr (assoc 2 entas)) (cdr (assoc 8 entas)))
(progn
(setq entas (subst (cons 8 (cdr (assoc 2 entas)))
(assoc 8 entas)
entas
)
)
(entmod entas)
(setq Kount2 (1+ Kount2))
) ;progn
) ;IF

(setq Kount (1+ Kount))

) ; while

) ; progn
) ; if
(princ "\nNow Locking the Xref Layers")
(foreach laylist list1
(command "-layer" "Lock" laylist "")
)

(if (> Kount 0)
(princ (strcat "\nFixed the insertion layers of "
(itoa Kount2)
" out of "
(itoa kount)
" total xrefs."
)
)

) ;if Kount >0
(setvar "cmdecho" oldcmdecho)
(princ)
) ; xref-fix
Any one help?

Opie
2007-10-18, 05:44 PM
Are you certain it was working before? Are there layers in your drawings that correspond to the XREF names? I don't see any layer creation code.

charlielgolden
2007-10-18, 06:05 PM
It woked very well except the lock layer portion did not always work right but it was a minor flaw. In 2006 I get a return of ("_> on the command line.

Lions60
2007-10-18, 06:09 PM
Give this a try: I used the variable entas which you are using to construct the layer name and i then took the assoc 2 of it to get the layers to lock. I have Acad 2006 and from what i can tell it is working like it is supposed too.


;**************************************************************************8
; xfix.LSP
;
; XREF updates - changes the insertion layer of all xrefs to their file name
; and locks the layer
;
;***************************************************************************


;;********************************************************
;; Load up the list box
(defun get_xrefs_ins ()
(setq XLIST '())
(setq XTEMP (tblnext "block" t))
(setq XLIST (append XLIST (list (cons -4 "<OR"))))
(while XTEMP
(if (cdr (assoc 1 XTEMP))
(setq XLIST (append XLIST (list (assoc 2 XTEMP))))
)
(setq XTEMP (tblnext "block"))
)
(setq XLIST (append XLIST (list (cons -4 "OR>"))))
)

;;********************************************************
;; Get all references of an xref in the drawing

(defun c:xfix (/ Kount Kount2 entas refs locklist)

(setq Kount 0)
(setq Kount2 0)
(setq oldcmdecho (getvar "cmdecho"))
(setvar "cmdecho" 0)
;(setq list1 '())
(get_xrefs_ins)

(if (setq refs (ssget "X" XLIST))
(progn

(princ
"\nFinding insertion layers of all xrefs - please wait"
)
(while (< Kount (sslength refs))

(setq entas (entget (ssname refs Kount)))
(setq locklist (cdr (assoc 8 entas)))
(if (/= (cdr (assoc 2 entas)) (cdr (assoc 8 entas)))
(progn
(setq entas (subst (cons 8 (cdr (assoc 2 entas)))
(assoc 8 entas)
entas
)
)
(if (/= entas "0")(setq list1 (cons (cdr(assoc 2 entas)) list1)))
(entmod entas)
(setq Kount2 (1+ Kount2))
) ;progn
) ;IF

(setq Kount (1+ Kount))

) ; while

) ; progn
) ; if
(princ "\nNow Locking the Xref Layers")
(foreach laylist list1
(command "-layer" "Lock" laylist "")
)

(if (> Kount 0)
(princ (strcat "\nFixed the insertion layers of "
(itoa Kount2)
" out of "
(itoa kount)
" total xrefs."
)
)

) ;if Kount >0
(setvar "cmdecho" oldcmdecho)
(princ)
) ; xref-fix

Opie
2007-10-18, 06:48 PM
It woked very well except the lock layer portion did not always work right but it was a minor flaw. In 2006 I get a return of ("_> on the command line.
Were you missing a closing ")"

CAB2k
2007-10-18, 08:01 PM
Are you certain it was working before? Are there layers in your drawings that correspond to the XREF names? I don't see any layer creation code.

Using entmake with a layer that doesn't exist is no problem as long as the new name is a valid name because it will be created for you. Not sure 2006 still does that.

CAB2k
2007-10-18, 08:03 PM
The problem may be that the xref is on a locked layer.
Another problem may be that ACAD2006 will not make a layer with entmake if it doesn't exist.
Another is that the xref name may not be a valid layer name.

Opie
2007-10-18, 08:40 PM
Using entmake with a layer that doesn't exist is no problem as long as the new name is a valid name because it will be created for you. Not sure 2006 still does that.
I did not know that. Probably cause I haven't tried it.