Jump to content

use the selected layer !!!


Guest

Recommended Posts

Hi i use this code as alternative to chamfer command. The problem is that all new lines are in layer 0 with linetype continuous.

Is it possible when i pick each line to keep her current layer and linetype ?

 

(defun C:CRU (/ os col 1st 2nd pt p1 p2)
 (defun *error* (msg)
    (princ "error: ")(princ msg)
    (setvar "osmode" os)   
    (setvar "cecolor" col)  
    (setvar "clayer" cla)      
   (princ)
  );;defun
    (setq os (getvar "osmode")) 
    (setq cla (getvar "clayer"))
    (setq col (getvar "cecolor"))
    (setvar "osmode" 0)
(while   (setq 1st (entsel))
(if 1st (setq c_layer (cdr (assoc 8 (entget (car 1st))))))
          (setq 2nd (entsel))
          (setq p1 (osnap (cadr 1st) "near")
                    p2 (osnap (cadr 2nd) "near") )
           (setq 1st (osnap (cadr 1st) "endp")
                   2nd (osnap (cadr 2nd) "endp") )
          (setq pt (inters p1 1st p2 2nd nil))
     (command "line" 1st pt 2nd "") )
     (setvar "osmode" os)
     (setvar "cecolor" col) 
     (setvar "clayer" cla)
    (princ)
)

 

 

Thanks

Link to comment
Share on other sites

Is this all tyou need to do?  Set the current layer@

 

From

(if 1st (setq c_layer (cdr (assoc 8 (entget (car 1st))))))

 

to

(if 1st (setvar "clayer" (cdr (assoc 8 (entget (car 1st))))))

 

Link to comment
Share on other sites

1 hour ago, prodromosm said:

hI Steven P . I add your , but the ltscale is not the same with the selected line. Is any way to keep the same ltscale?

 

thanks

 

If you are wanting to change a few things you might want to look at making your line using the entmake method rather than (command "line"....) - it gives a lot more control more easily over what you draw with the LISP.

 

You can probably also remove the setvar parts from the code, and just add them in the entmake as you make the line up

 

See below for a quick example that will draw a line between 2 points using the getpoints function. The entmake function makes the line up and you can pass details to that as required . I've added a few details at the bottom with the codes you might find useful - these are all online of you can draw a line and use (entget(entlast)) to list that lines details, copy from there. Noting that often with entmake the order you do things is important, so keep them in the same order.

 

 

(defun c:getpoints ( / pt1 pt2 ) 
  (setq pt1 (getpoint "Point 1"))
  (setq pt2 (getpoint "Point 2"))
  (entmakeline pt1 pt2)
  (princ)
)

(defun entmakeline ( pt1 pt2 / )
  (entmake (list (cons 0 "LINE")
                 (cons 10 pt1)
                 (cons 11 pt2)
         ) ; end list
  )
)
;;0  : Entity Type
;;8  : Layer
;;48 : Linetype Scale
;;62 : Colour
;;6  : Linetype
;;370: Lineweight x 100
;;10 : Point 1
;;11 : Point 2

 

 

  • Agree 1
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...