Change a start point to line

Change a start point to line

skchui6159
Advocate Advocate
322 Views
3 Replies
Message 1 of 4

Change a start point to line

skchui6159
Advocate
Advocate

Hello everyone

I have this code.

 

(Defun c:change_stpoint()
(setq q1 (entsel "\n a line "));
(setq q1data (entget (car q1)))
(setq pt10_q1 (cdr (assoc 10 q1data)))
(setq pt11_q1 (cdr (assoc 11 q1data)))
(setq pt10_q1_1x (car (cdr (assoc 10 q1data)))); q1 Startpoint x- coordinate
(setq a (- pt10_q1_1x 500))
(setq pt10_q1_1y (cadr (cdr (assoc 10 q1data)))); q1 Startpoint y- coordinate
(setq newlist (list 10 pt10_q1_1x pt10_q1_1y 0))
;;; (setq pt10_q1_1x (atof pt10_q1_1x))
(setq a (-(pt10_q1_1x 500)))
(entmod (subst (cons '10 '(a 0 0)) (assoc 10 q1data) q1data))
(princ)
)

 

Why the line cannot be entmod? Nothing Happen.  if i type a=500 is work. Thank!

0 Likes
323 Views
3 Replies
Replies (3)
Message 2 of 4

Sea-Haven
Mentor
Mentor

Try this 

 

 

(Defun c:change_stpoint()
(setq q1 (entsel "\n a line "));
(setq q1data (entget (car q1)))
(setq pt10_q1 (cdr (assoc 10 q1data)))
(setq pt11_q1 (cdr (assoc 11 q1data)))
(setq pt10_q1_1x (car (cdr (assoc 10 q1data)))); q1 Startpoint x- coordinate
(setq a (- pt10_q1_1x 500))
(setq pt10_q1_1y (cadr (cdr (assoc 10 q1data)))); q1 Startpoint y- coordinate
(setq newlist (list a pt10_q1_1y 0.0))
(entmod (subst (cons 10 newlist) (assoc 10 q1data) q1data))
(princ)
)

 

A couple of comments there is a command lengthen which does what you want.

Can grab an end point and drag ortho lines, with mouse, then type distance.

Using pick end to lengthen and a polar function to work out new point handles lines on angles.

 

I am sure some people will provide more solutions.

 

A good idea is get in habit of localising your variables

(Defun c:change_stpoint( / put your local variable names here)

0 Likes
Message 3 of 4

Moshe-A
Mentor
Mentor

@skchui6159 hi,

 

it doesn't work, probably you are getting bad argument type or some bad functions...

check my fix and note for the declaration of local variables plus the use of (if) function to exit quite if noting is selected in (entsel) (e.g pressing just enter of miss pick)

 

enjoy

Moshe

 

 

(defun c:change_stpoint (/ q1dat pt10_q1 pt11_q1 pt10_q1_1x pt10_q1_1y nX nY)
 (if (setq q1 (entsel "\nSelect line "))
  (progn
   (setq q1data (entget (car q1)))
   (setq pt10_q1 (cdr (assoc '10 q1data)))
   (setq pt11_q1 (cdr (assoc '11 q1data)))
   
   (setq pt10_q1_1x (car (cdr (assoc '10 q1data)))) ; q1 Startpoint x- coordinate
   (setq nX (- pt10_q1_1x 500))
   
   (setq pt10_q1_1y (cadr (cdr (assoc '10 q1data)))); q1 Startpoint y- coordinate
   (setq nY (- pt10_q1_1y 500))

   (entmod (subst (cons '10 (list nX nY 0.0)) (assoc '10 q1data) q1data))
  ); progn
 ); if
  
 (princ)
)

 

 

0 Likes
Message 4 of 4

ВeekeeCZ
Consultant
Consultant

@skchui6159 wrote:

Hello everyone

I have this code.

 

(Defun c:change_stpoint()
(setq q1 (entsel "\n a line "));
(setq q1data (entget (car q1)))
(setq pt10_q1 (cdr (assoc 10 q1data)))
(setq pt11_q1 (cdr (assoc 11 q1data)))
(setq pt10_q1_1x (car (cdr (assoc 10 q1data)))); q1 Startpoint x- coordinate
(setq a (- pt10_q1_1x 500))
(setq pt10_q1_1y (cadr (cdr (assoc 10 q1data)))); q1 Startpoint y- coordinate
(setq newlist (list 10 pt10_q1_1x pt10_q1_1y 0))
;;; (setq pt10_q1_1x (atof pt10_q1_1x))
(setq a (-(pt10_q1_1x 500)))
(entmod (subst (cons '10 '(a 0 0)) (assoc 10 q1data) q1data))
(princ)
)

 

Why the line cannot be entmod? Nothing Happen.  if i type a=500 is work. Thank!


 

You cannot quote a list if it contains a variable (anywhere inside, no matter how deep). The variable won't be evaluated that way.

 

'(a 0 0) does not work you expect

'(500 0 0) is right

(list a 0 0) is correct

(cons a '(0 0)) also possible with the same result

(list a '(0 0)) is possible, but a different result

 

(list 0 0 0) works.

'(500 (list a 0 0)) does not return result you want

0 Likes