.NET

Reply
*Daren Nerad
Message 1 of 5 (182 Views)

return to current layer

182 Views, 4 Replies
05-24-2005 10:03 AM
The following is a routine that I have found very useful to use. There is
only one problem. I can't figure out how to come back to the layer that the
command was issued in. It stays in the text or dim. layer. Any suggestions
would be appreciated.

;VLR_COMMAND.lsp courtesy Peter Jamtgaard 2003

; Vlr Command is a function that will switch the active layer in a drawing.
; The reactor checks the command that is starting and if it recognizes it
; it will switch to a specified layer. If the layer doesn't exist it will
; create it with the color, linetype, and plottable setting provided.
; To load and run this program add the lines (load
"vlr_command")(c:vlr_command)
; to your acaddoc.lsp or another autoloading lisp routine.

(defun C:AVLR_COMMAND ()
(vl-load-com)
(vlr-editor-reactor nil '((:vlr-commandwillstart . COM1)))
)
(vla-get-Layer setq cl (getvar "nlayer"))
(defun COM1 (CALL CALLBACK / COMLAYLST)
; Examples of Command vs Layer
; List of corrusponding commands layers color linetype
plottable
(setq COMLAYLST (list (list "qdim" "DIMENSIONS" 2 "continuous"
:vlax-true)
(list "dimlinear" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimaligned" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimordinate" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimradius" "DIMENSIONS" 2 "continuous"
:vlax-true)
(list "dimdiameter" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimangular" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimbaseline" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimcontinue" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimqleader" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "tolerance" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimcenter" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dtext" "TEXT" 3 "continuous"
:vlax-true)
(list "mtext" "TEXT" 3 "continuous"
:vlax-true)
(list "text" "TEXT" 3 "continuous" :vlax-true)
; Add your own command layer lists here....
)
)
(foreach N COMLAYLST
(if (= (strcase (car CALLBACK)) (strcase (car N)))
(progn
(make_layers (cadr N)
(caddr N)
(cadddr N)
(car (cddddr N))
)
(setq n1 n)
(vla-put-activelayer
(vla-get-activedocument
(vlax-get-acad-object)
)
(vlax-ename->vla-object
(tblobjname "LAYER" (cadr N))
)
)
)
)
)
(prin1)
)
(setvar "nlayer" cl)
; Make layers using activeX

(defun MAKE_LAYERS (LAY_NAM COLOR LTYPE PLOTL / LAYOBJ LAYSOBJ LTYPESOBJ)
(setq CDWGOBJ (vla-get-activedocument
(vlax-get-acad-object)
)
LAYSOBJ (vla-get-layers CDWGOBJ)
)
(if (not (tblobjname "layer" LAY_NAM))
(vl-catch-all-error-p
(vl-catch-all-apply 'vla-add (list LAYSOBJ LAY_NAM))
)
)
(setq LAYOBJ (vla-item LAYSOBJ LAY_NAM))
(if (not (tblobjname "ltype" LTYPE))
(progn
(setq LTYPESOBJ (vla-get-linetypes CDWGOBJ))
(vla-load LTYPESOBJ LTYPE (findfile "acad.lin"))
(vlax-release-object LTYPESOBJ)
)
)
(vla-put-layeron LAYOBJ :vlax-true)
(if (/= (strcase (vla-get-name LAYOBJ)) (strcase (getvar "clayer")))
(vla-put-freeze LAYOBJ :vlax-false)
)
(vla-put-lock LAYOBJ :vlax-false)
(vla-put-color LAYOBJ COLOR)
(vla-put-linetype LAYOBJ LTYPE)
(vla-put-plottable LAYOBJ PLOTL)
)
(prin1)
*Albert Szilvasy
Message 2 of 5 (182 Views)

Re: return to current layer

05-24-2005 10:49 AM in reply to: *Daren Nerad
I think you want to post this in the autodesk.autocad.customization
newsgroup instead of this one. This group is about the .NET API of AutoCAD
and your question is about Visual Lisp.

Albert

"Daren Nerad" wrote in message
news:4854824@discussion.autodesk.com...
The following is a routine that I have found very useful to use. There is
only one problem. I can't figure out how to come back to the layer that the
command was issued in. It stays in the text or dim. layer. Any suggestions
would be appreciated.

;VLR_COMMAND.lsp courtesy Peter Jamtgaard 2003

; Vlr Command is a function that will switch the active layer in a drawing.
; The reactor checks the command that is starting and if it recognizes it
; it will switch to a specified layer. If the layer doesn't exist it will
; create it with the color, linetype, and plottable setting provided.
; To load and run this program add the lines (load
"vlr_command")(c:vlr_command)
; to your acaddoc.lsp or another autoloading lisp routine.

(defun C:AVLR_COMMAND ()
(vl-load-com)
(vlr-editor-reactor nil '((:vlr-commandwillstart . COM1)))
)
(vla-get-Layer setq cl (getvar "nlayer"))
(defun COM1 (CALL CALLBACK / COMLAYLST)
; Examples of Command vs Layer
; List of corrusponding commands layers color linetype
plottable
(setq COMLAYLST (list (list "qdim" "DIMENSIONS" 2 "continuous"
:vlax-true)
(list "dimlinear" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimaligned" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimordinate" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimradius" "DIMENSIONS" 2 "continuous"
:vlax-true)
(list "dimdiameter" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimangular" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimbaseline" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimcontinue" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimqleader" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "tolerance" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimcenter" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dtext" "TEXT" 3 "continuous"
:vlax-true)
(list "mtext" "TEXT" 3 "continuous"
:vlax-true)
(list "text" "TEXT" 3 "continuous" :vlax-true)
; Add your own command layer lists here....
)
)
(foreach N COMLAYLST
(if (= (strcase (car CALLBACK)) (strcase (car N)))
(progn
(make_layers (cadr N)
(caddr N)
(cadddr N)
(car (cddddr N))
)
(setq n1 n)
(vla-put-activelayer
(vla-get-activedocument
(vlax-get-acad-object)
)
(vlax-ename->vla-object
(tblobjname "LAYER" (cadr N))
)
)
)
)
)
(prin1)
)
(setvar "nlayer" cl)
; Make layers using activeX

(defun MAKE_LAYERS (LAY_NAM COLOR LTYPE PLOTL / LAYOBJ LAYSOBJ LTYPESOBJ)
(setq CDWGOBJ (vla-get-activedocument
(vlax-get-acad-object)
)
LAYSOBJ (vla-get-layers CDWGOBJ)
)
(if (not (tblobjname "layer" LAY_NAM))
(vl-catch-all-error-p
(vl-catch-all-apply 'vla-add (list LAYSOBJ LAY_NAM))
)
)
(setq LAYOBJ (vla-item LAYSOBJ LAY_NAM))
(if (not (tblobjname "ltype" LTYPE))
(progn
(setq LTYPESOBJ (vla-get-linetypes CDWGOBJ))
(vla-load LTYPESOBJ LTYPE (findfile "acad.lin"))
(vlax-release-object LTYPESOBJ)
)
)
(vla-put-layeron LAYOBJ :vlax-true)
(if (/= (strcase (vla-get-name LAYOBJ)) (strcase (getvar "clayer")))
(vla-put-freeze LAYOBJ :vlax-false)
)
(vla-put-lock LAYOBJ :vlax-false)
(vla-put-color LAYOBJ COLOR)
(vla-put-linetype LAYOBJ LTYPE)
(vla-put-plottable LAYOBJ PLOTL)
)
(prin1)
*Daren Nerad
Message 3 of 5 (182 Views)

Re: return to current layer

05-24-2005 11:53 AM in reply to: *Daren Nerad
I didn't....I posted the wrong one. This is what is current. Thanks for
the catch. Any suggestions on a fix?

Daren


;VLR_COMMAND.lsp courtesy Peter Jamtgaard 2003

; Vlr Command is a function that will switch the active layer in a drawing.
; The reactor checks the command that is starting and if it recognizes it
; it will switch to a specified layer. If the layer doesn't exist it will
; create it with the color, linetype, and plottable setting provided.
; To load and run this program add the lines (load
"vlr_command")(c:vlr_command)
; to your acaddoc.lsp or another autoloading lisp routine.

(defun C:VLR_COMMAND ()
(vl-load-com)
(vlr-editor-reactor nil '((:vlr-commandwillstart . COM1)))
)
(defun COM1 (CALL CALLBACK / COMLAYLST)
; Examples of Command vs Layer
; List of corrusponding commands layers color linetype plottable
(setq COMLAYLST (list (list "qdim" "DIMENSIONS" 2 "continuous"
:vlax-true)
(list "dimlinear" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimaligned" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimordinate" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimradius" "DIMENSIONS" 2 "continuous"
:vlax-true)
(list "dimdiameter" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimangular" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimbaseline" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimcontinue" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimqleader" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "tolerance" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimcenter" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dtext" "TEXT" 3 "continuous"
:vlax-true)
(list "mtext" "TEXT" 3 "continuous"
:vlax-true)
(list "text" "TEXT" 3 "continuous" :vlax-true)
; Add your own command layer lists here....
)
)
(foreach N COMLAYLST
(if (= (strcase (car CALLBACK)) (strcase (car N)))
(progn
(make_layers (cadr N)
(caddr N)
(cadddr N)
(car (cddddr N))
)
(setq n1 n)
(vla-put-activelayer
(vla-get-activedocument
(vlax-get-acad-object)
)
(vlax-ename->vla-object
(tblobjname "LAYER" (cadr N))
)
)
)
)
)
(prin1)
)

; Make layers using activeX

(defun MAKE_LAYERS (LAY_NAM COLOR LTYPE PLOTL / LAYOBJ LAYSOBJ LTYPESOBJ)
(setq CDWGOBJ (vla-get-activedocument
(vlax-get-acad-object)
)
LAYSOBJ (vla-get-layers CDWGOBJ)
)
(if (not (tblobjname "layer" LAY_NAM))
(vl-catch-all-error-p
(vl-catch-all-apply 'vla-add (list LAYSOBJ LAY_NAM))
)
)
(setq LAYOBJ (vla-item LAYSOBJ LAY_NAM))
(if (not (tblobjname "ltype" LTYPE))
(progn
(setq LTYPESOBJ (vla-get-linetypes CDWGOBJ))
(vla-load LTYPESOBJ LTYPE (findfile "acad.lin"))
(vlax-release-object LTYPESOBJ)
)
)
(vla-put-layeron LAYOBJ :vlax-true)
(if (/= (strcase (vla-get-name LAYOBJ)) (strcase (getvar "clayer")))
(vla-put-freeze LAYOBJ :vlax-false)
)
(vla-put-lock LAYOBJ :vlax-false)
(vla-put-color LAYOBJ COLOR)
(vla-put-linetype LAYOBJ LTYPE)
(vla-put-plottable LAYOBJ PLOTL)
)
(prin1)
*Ed Jobe
Message 4 of 5 (182 Views)

Re: return to current layer

05-24-2005 12:37 PM in reply to: *Daren Nerad
That's still lisp. You can reach Peter through the lisp forum at
www.AUGI.com.

--
----
Ed
----
"Daren Nerad" wrote in message
news:4854979@discussion.autodesk.com...
I didn't....I posted the wrong one. This is what is current. Thanks for
the catch. Any suggestions on a fix?

Daren


;VLR_COMMAND.lsp courtesy Peter Jamtgaard 2003

; Vlr Command is a function that will switch the active layer in a drawing.
; The reactor checks the command that is starting and if it recognizes it
; it will switch to a specified layer. If the layer doesn't exist it will
; create it with the color, linetype, and plottable setting provided.
; To load and run this program add the lines (load
"vlr_command")(c:vlr_command)
; to your acaddoc.lsp or another autoloading lisp routine.

(defun C:VLR_COMMAND ()
(vl-load-com)
(vlr-editor-reactor nil '((:vlr-commandwillstart . COM1)))
)
(defun COM1 (CALL CALLBACK / COMLAYLST)
; Examples of Command vs Layer
; List of corrusponding commands layers color linetype plottable
(setq COMLAYLST (list (list "qdim" "DIMENSIONS" 2 "continuous"
:vlax-true)
(list "dimlinear" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimaligned" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimordinate" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimradius" "DIMENSIONS" 2 "continuous"
:vlax-true)
(list "dimdiameter" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimangular" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimbaseline" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimcontinue" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimqleader" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "tolerance" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimcenter" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dtext" "TEXT" 3 "continuous"
:vlax-true)
(list "mtext" "TEXT" 3 "continuous"
:vlax-true)
(list "text" "TEXT" 3 "continuous" :vlax-true)
; Add your own command layer lists here....
)
)
(foreach N COMLAYLST
(if (= (strcase (car CALLBACK)) (strcase (car N)))
(progn
(make_layers (cadr N)
(caddr N)
(cadddr N)
(car (cddddr N))
)
(setq n1 n)
(vla-put-activelayer
(vla-get-activedocument
(vlax-get-acad-object)
)
(vlax-ename->vla-object
(tblobjname "LAYER" (cadr N))
)
)
)
)
)
(prin1)
)

; Make layers using activeX

(defun MAKE_LAYERS (LAY_NAM COLOR LTYPE PLOTL / LAYOBJ LAYSOBJ LTYPESOBJ)
(setq CDWGOBJ (vla-get-activedocument
(vlax-get-acad-object)
)
LAYSOBJ (vla-get-layers CDWGOBJ)
)
(if (not (tblobjname "layer" LAY_NAM))
(vl-catch-all-error-p
(vl-catch-all-apply 'vla-add (list LAYSOBJ LAY_NAM))
)
)
(setq LAYOBJ (vla-item LAYSOBJ LAY_NAM))
(if (not (tblobjname "ltype" LTYPE))
(progn
(setq LTYPESOBJ (vla-get-linetypes CDWGOBJ))
(vla-load LTYPESOBJ LTYPE (findfile "acad.lin"))
(vlax-release-object LTYPESOBJ)
)
)
(vla-put-layeron LAYOBJ :vlax-true)
(if (/= (strcase (vla-get-name LAYOBJ)) (strcase (getvar "clayer")))
(vla-put-freeze LAYOBJ :vlax-false)
)
(vla-put-lock LAYOBJ :vlax-false)
(vla-put-color LAYOBJ COLOR)
(vla-put-linetype LAYOBJ LTYPE)
(vla-put-plottable LAYOBJ PLOTL)
)
(prin1)
*Daren Nerad
Message 5 of 5 (182 Views)

Re: return to current layer

05-24-2005 12:44 PM in reply to: *Daren Nerad
Thanks Ed

Will do.

"Ed Jobe" wrote in message
news:4855035@discussion.autodesk.com...
That's still lisp. You can reach Peter through the lisp forum at
www.AUGI.com.

--
----
Ed
----
"Daren Nerad" wrote in message
news:4854979@discussion.autodesk.com...
I didn't....I posted the wrong one. This is what is current. Thanks for
the catch. Any suggestions on a fix?

Daren


;VLR_COMMAND.lsp courtesy Peter Jamtgaard 2003

; Vlr Command is a function that will switch the active layer in a drawing.
; The reactor checks the command that is starting and if it recognizes it
; it will switch to a specified layer. If the layer doesn't exist it will
; create it with the color, linetype, and plottable setting provided.
; To load and run this program add the lines (load
"vlr_command")(c:vlr_command)
; to your acaddoc.lsp or another autoloading lisp routine.

(defun C:VLR_COMMAND ()
(vl-load-com)
(vlr-editor-reactor nil '((:vlr-commandwillstart . COM1)))
)
(defun COM1 (CALL CALLBACK / COMLAYLST)
; Examples of Command vs Layer
; List of corrusponding commands layers color linetype plottable
(setq COMLAYLST (list (list "qdim" "DIMENSIONS" 2 "continuous"
:vlax-true)
(list "dimlinear" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimaligned" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimordinate" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimradius" "DIMENSIONS" 2 "continuous"
:vlax-true)
(list "dimdiameter" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimangular" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimbaseline" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimcontinue" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimqleader" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "tolerance" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dimcenter" "DIMENSIONS" 2 "continuous" :vlax-true)
(list "dtext" "TEXT" 3 "continuous"
:vlax-true)
(list "mtext" "TEXT" 3 "continuous"
:vlax-true)
(list "text" "TEXT" 3 "continuous" :vlax-true)
; Add your own command layer lists here....
)
)
(foreach N COMLAYLST
(if (= (strcase (car CALLBACK)) (strcase (car N)))
(progn
(make_layers (cadr N)
(caddr N)
(cadddr N)
(car (cddddr N))
)
(setq n1 n)
(vla-put-activelayer
(vla-get-activedocument
(vlax-get-acad-object)
)
(vlax-ename->vla-object
(tblobjname "LAYER" (cadr N))
)
)
)
)
)
(prin1)
)

; Make layers using activeX

(defun MAKE_LAYERS (LAY_NAM COLOR LTYPE PLOTL / LAYOBJ LAYSOBJ LTYPESOBJ)
(setq CDWGOBJ (vla-get-activedocument
(vlax-get-acad-object)
)
LAYSOBJ (vla-get-layers CDWGOBJ)
)
(if (not (tblobjname "layer" LAY_NAM))
(vl-catch-all-error-p
(vl-catch-all-apply 'vla-add (list LAYSOBJ LAY_NAM))
)
)
(setq LAYOBJ (vla-item LAYSOBJ LAY_NAM))
(if (not (tblobjname "ltype" LTYPE))
(progn
(setq LTYPESOBJ (vla-get-linetypes CDWGOBJ))
(vla-load LTYPESOBJ LTYPE (findfile "acad.lin"))
(vlax-release-object LTYPESOBJ)
)
)
(vla-put-layeron LAYOBJ :vlax-true)
(if (/= (strcase (vla-get-name LAYOBJ)) (strcase (getvar "clayer")))
(vla-put-freeze LAYOBJ :vlax-false)
)
(vla-put-lock LAYOBJ :vlax-false)
(vla-put-color LAYOBJ COLOR)
(vla-put-linetype LAYOBJ LTYPE)
(vla-put-plottable LAYOBJ PLOTL)
)
(prin1)
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.