Jump to content

Insert block & inherit layer from snap point?


martymoose

Recommended Posts

I have a block library of several hundred blocks. Many of these blocks I insert into my drawings (one at a time) and snap to lines already in my drawing. As I insert and snap to these lines, I need the block to take the layer of the line I am snaping to. I am just unsure how to accomplish this.

Recently, after I insert the block, I will follow up with a 'matchproperties' command, but it would be nice to do this in one click. It would save me a lot of time!! All my blocks were created on layer 0, so they can take the properties of these lines. I usually snap to the nearest or endpoint.

I appreciate your help.

Link to comment
Share on other sites

quick and dirty. Can be revised to suit your needs

(defun c:test (/ oldecho oldlayer ent p1 entlst layname blkname)
(vl-load-com)
;======ERROR TRAP=======
(setq temperr *error*            ;store *error*
     *error* errortrap            ;re-assign *error*
     oldecho (getvar "cmdecho")    ;store variables as needed
     oldlayer (getvar "clayer")
     )
;======ERROR TRAP=======
 
(setq oldlayer (getvar "clayer")
     oldecho (getvar "cmdecho")
     ent (entsel "\nPick insert point on line for block: ")
     p1 (vlax-curve-getclosestpointto (car ent) (cadr ent))
     entlst (entget (car ent))
     layname (cdr (assoc 8 entlst))
     blkname (getstring "\nEnter block name: ")
);setq
 (setvar "clayer" layname)
 (initdia)
 (command "-insert" blkname p1 "" "")
 ;(while (> (getvar 'CmdActive) 0) (command pause))
 (setvar "clayer" oldlayer)
 (setvar "cmdecho" oldecho)
 (princ)
 );defun

 ;======ERROR TRAP=======

(defun errortrap (msg)                    
   (setvar "cmdecho" oldecho)            ;restore variables
   (setvar "clayer" oldlayer)            
   (setq *error* temperr)            ;restore *error*
   (prompt "\nError or break encountered...Resetting System Variables ")    ;inform user
  (princ)
);defun
;======ERROR TRAP=======
 
 

Link to comment
Share on other sites

after selecting my point and inserting my block, the layer temporarily changed to the line I was snapping to, but ultimately ended up on my current layer, just as before.

This is more of what I am thinking...

 

1. insert my block as normal, snapping to my line as I always do (atleast this way I can preview my block on my cursor, as I am inserting it)

 

2. run lisp that takes the layer of the 'lastpoint' and makes this my current layer or 'clayer'.

 

3. run 'laymch' command converting my 'last' block to the current layer.

 

4. layerp

 

If this will work, which I think it would, then I would need help with #2 above. I just dont know lisp, or I could do this myself.

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...