Jump to content

Insert block on layer


Glen Smith

Recommended Posts

I have a little free time and have been continuing to work on a LISP that Lee wrote for me a while back. I've made great strides today but have come up short in one place. I want to have my LISP insert three different blocks at one location, but I want them on different layers.

 

I have the following code which works, but puts everything on whatever the current layer is.

 

                      (setq rot (RTD (vla-get-rotation obj)))
                     (setq xScale (vla-get-xscalefactor obj))
                     (setq yScale (vla-get-yscalefactor obj))

                     ;switch to kc layer
                     (command "-insert" (nth count kclst) ipt xScale yScale rot)
                     ;switch to mg layer
                     (command "-insert" (nth count mglst) ipt xScale yScale rot)
                     ;switch to wipeout layer
                     (command "-insert" (nth count wipelst) ipt xScale yScale rot)

 

Is there a simple way to do this? The layer should already exist in the drawing, so it should just be a matter of making it current.

 

Thanks

Glen

Link to comment
Share on other sites

try this:

I'm assuming you already have the layers created.

(setq rot (RTD (vla-get-rotation obj)))
                     (setq xScale (vla-get-xscalefactor obj))
                     (setq yScale (vla-get-yscalefactor obj))

                     ;switch to kc layer
                     (command "-layer" "s" "kc" "")
                     (command "-insert" (nth count kclst) ipt xScale yScale rot)
                     ;switch to mg layer
                     (command "-layer" "s" "mg" "")
                     (command "-insert" (nth count mglst) ipt xScale yScale rot)
                     ;switch to wipeout layer
                     (command "-layer" "s" "wipeout" "")
                     (command "-insert" (nth count wipelst) ipt xScale yScale rot)

Link to comment
Share on other sites

You could also do something like this: (will bomb if object inserted is on a locked layer, or the layer does not exist.

 

*edit...use entmod so the layer will be automagically created if it does not exist.:shock:

(setq rot (rtd (vla-get-rotation obj)))
(setq xscale (vla-get-xscalefactor obj))
(setq yscale (vla-get-yscalefactor obj))

                   ;switch to kc layer
(command "-insert" (nth count kclst) ipt xscale yscale rot)
;;(vla-put-layer (vlax-ename->vla-object (entlast)) "kc")
(entmod (subst (cons 8 "kc") (assoc 8 (entget (entlast))) (entget (entlast))))
                   ;switch to mg layer
(command "-insert" (nth count mglst) ipt xscale yscale rot)
;;(vla-put-layer (vlax-ename->vla-object (entlast)) "mg")
(entmod (subst (cons 8 "mg") (assoc 8 (entget (entlast))) (entget (entlast))))
                   ;switch to wipeout layer
(command "-insert" (nth count wipelst) ipt xscale yscale rot)
;;(vla-put-layer (vlax-ename->vla-object (entlast)) "wipeout")
(entmod (subst (cons 8 "wipeout") (assoc 8 (entget (entlast))) (entget (entlast))))

  • Like 1
Link to comment
Share on other sites

Thank you both for the quick replies , naturally I found the following link on the AfraLISP website after I posted - even though I spent a good 20 minutes looking there prior to posting.

 

http://www.afralisp.net/lispa/lisp31.htm

 

Cedwards, what does the ELIGHT do in this statement? Looking at the command line window implys that it should be something about reconcile, but I'm not sure what.

(command "-layer" "wipeout" "ELIGHT" "")

 

Glen

Link to comment
Share on other sites

Doh,

 

Could some kind moderator move this thread to the LISP forum? I thought that I put it there but when I got home to look at it , couldn't find it.

 

Thanks,

Glen

Link to comment
Share on other sites

I have a little free time and have been continuing to work on a LISP that Lee wrote for me a while back. I've made great strides today but have come up short in one place. I want to have my LISP insert three different blocks at one location, but I want them on different layers.

 

I have the following code which works, but puts everything on whatever the current layer is.

 

                      (setq rot (RTD (vla-get-rotation obj)))
                     (setq xScale (vla-get-xscalefactor obj))
                     (setq yScale (vla-get-yscalefactor obj))

                     ;switch to kc layer
                     (command "-insert" (nth count kclst) ipt xScale yScale rot)
                     ;switch to mg layer
                     (command "-insert" (nth count mglst) ipt xScale yScale rot)
                     ;switch to wipeout layer
                     (command "-insert" (nth count wipelst) ipt xScale yScale rot)

 

Is there a simple way to do this? The layer should already exist in the drawing, so it should just be a matter of making it current.

 

Thanks

Glen

 

 

Add this function below somewhere in your program:

 

(defun MKE_LYR (NEWLAYER CLR LT / LAY FRZ)
 (setq LAY (tblsearch "layer" NEWLAYER))
 (if (not LAY)
   (command "_.layer" "_m" NEWLAYER "_c" CLR "" "_lt" LT "" "")
   (progn
     (setq FRZ (cdr (assoc 70 LAY)))
     (if (= FRZ 65)
       (progn
         (command "_.layer" "_t" NEWLAYER "")
         (command "_.layer" "_s" NEWLAYER "")
       )
       (command "_.layer" "_s" NEWLAYER "")
     )
   )
 )
 (princ)
)

 

Then add these lines as shown before you insert block:

  (setq rot (RTD (vla-get-rotation obj)))
 (setq xScale (vla-get-xscalefactor obj))
 (setq yScale (vla-get-yscalefactor obj))

 ;switch to kc layer
 [color=red](MKE_LYR "KC" "RED" "")[/color]
 (command "-insert" (nth count kclst) ipt xScale yScale rot)
 ;switch to mg layer
 [color=red](MKE_LYR "MG" "GREEN" "")[/color]
 (command "-insert" (nth count mglst) ipt xScale yScale rot)
 ;switch to wipeout layer
 [color=red](MKE_LYR "WIPEOUT" "YELLOW" "")[/color]
 (command "-insert" (nth count wipelst) ipt xScale yScale rot)

 

 

This will make the layer if its not there or set it if its there.

Will also set color and linetype.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...