Change Delta X and/ or Delta Y of a Line.

Change Delta X and/ or Delta Y of a Line.

Anonymous
Not applicable
2,966 Views
12 Replies
Message 1 of 13

Change Delta X and/ or Delta Y of a Line.

Anonymous
Not applicable

Hello,
if you select a Line, in its Properties there are Delta X and Delta Y values.
Is there a possibilty to change
1. only Delta X,
2. Only Delta Y,
3. Both Delta X and Delta Y?
Without lisp - you have to catch this Line's Endpoint and stretch this Line.
But please, tell me, is that possible to write such lisp?
If yes, please, if you have time and you have so big abilities, write this lisp.

0 Likes
2,967 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable

I think I have a way to make such lisp be possible.

But my idea may turn to be not to fulfil, if there is no way to make specified point move via AutoLisp.

So tell me please, is that possible?

0 Likes
Message 3 of 13

Anonymous
Not applicable

damian,

 

something quick and dirty:

 

(defun c:dxy (/ ename base-pt chg-pt dist dist2end dx
dy e elist end-pt pt sec-pt st-pt
v-obj x1 x2 y1 y2
)
(while (not
(and
(setq e (Entsel "\nSelect line to change delta value:"))
(= "LINE" (cdr (assoc 0 (entget (car e)))))
)
)
(prompt "\nNothing selected or object is not line!")
)

(setq dx (getreal "\X value <0.00>:")
dy (getreal "\Y value <0.00>:"))
(if (not dx) (setq dx 0.))
(if (not dy) (setq dy 0.))

(setq ename (car e))
(setq v-obj (vlax-ename->vla-object ename))

(setq pt (vlax-curve-getclosestpointto v-obj (cadr e)))

(setq dist (vlax-curve-getdistatpoint v-obj pt))
(setq st-pt (vlax-curve-getstartpoint v-obj)
end-pt (vlax-curve-getendpoint v-obj)
)

(setq dist2end (- (vlax-curve-getdistatpoint v-obj end-pt) dist))


(setq elist (entget ename))

(if (< dist dist2end)
(progn
(setq base-pt (cdr (assoc 10 elist)))
(setq sec-pt (cdr (assoc 11 elist)))
(setq x1 (car base-pt)
x2 (car sec-pt)
y1 (cadr base-pt)
y2 (cadr sec-pt)
)
(setq chg-pt (list (if (< x1 x2) (+ (car base-pt) dx) (- (car base-pt) dx))
(if (< y1 y2) (+ (cadr base-pt) dy) (- (cadr base-pt) dy))
(caddr base-pt))
)
(setq elist (subst (cons 11 chg-pt) (assoc 11 elist) elist))
(entmod elist)
)
(progn
(setq base-pt (cdr (assoc 11 elist)))
(setq sec-pt (cdr (assoc 10 elist)))
(setq x1 (car base-pt)
x2 (car sec-pt)
y1 (cadr base-pt)
y2 (cadr sec-pt)
)
(setq chg-pt (list (if (< x1 x2) (+ (car base-pt) dx) (- (car base-pt) dx))
(if (< y1 y2) (+ (cadr base-pt) dy) (- (cadr base-pt) dy))
(caddr base-pt))
)
(setq elist (subst (cons 10 chg-pt) (assoc 10 elist) elist))
(entmod elist)
)
);end if
);end defun

Hope this help,

dicra

0 Likes
Message 4 of 13

Anonymous
Not applicable

Very good job, thank you!

 

I changed only prompts for Delta X and Delta Y:

 (setq
  dx (getreal "\nNew Delta_X value <0.00>: ")
  dy (getreal "\nNew Delta_Y value <0.00>: ")
 )

 

0 Likes
Message 5 of 13

Anonymous
Not applicable

Glad I could help,

 

dicra

0 Likes
Message 6 of 13

Lee_Mac
Advisor
Advisor

Here's another example:

 

(defun c:test ( / d e p q s v )
    (and (setq s (ssget "_+.:E:S:L" '((0 . "LINE"))))
         (setq e (entget (ssname s 0))
               p (cdr (assoc 10 e))
               q (cdr (assoc 11 e))
               v (mapcar '(lambda ( s d ) (cond ((getdist (strcat "\nNew delta " s " <" (rtos d) ">: "))) (d))) '("X" "Y") (mapcar '- q p))
         )
         (entmod (subst (cons 11 (mapcar '+ p v)) (assoc 11 e) e))
    )
    (princ)
)

 

Message 7 of 13

Anonymous
Not applicable

Lee,

 

Your code is working only in firs quadrant, if x and y of start points are lower than x and y of end point.

Delta x and y are going to be properly changed, but not like using stretch, for any other case.

And there need to be check for which point user need to stretch, start or end point.

 

But using mapcar and lambda, is far more elegant.

I always need a lot of time looking at your codes to figure out what are they doing, and of course learning a lot from them.

 

dicra

PS I'm envious for that scroll bar in your code Smiley Wink

 

0 Likes
Message 8 of 13

Lee_Mac
Advisor
Advisor
dicra wrote:

Your code is working only in firs quadrant, if x and y of start points are lower than x and y of end point.

Delta x and y are going to be properly changed, but not like using stretch, for any other case.

And there need to be check for which point user need to stretch, start or end point.

 

My code should work correctly in all quadrants, since the user may specify negative delta values.

 

0 Likes
Message 9 of 13

Anonymous
Not applicable

Sorry Lee,

 

I didn't think about that.

Depending from what user need, it could be a better approach to this problem.

 

dicra

0 Likes
Message 10 of 13

Lee_Mac
Advisor
Advisor

However, you raise a good point regarding which end point of the line should be modified, and therefore, I would propose the following solution:

 

(defun c:test ( / d e k p q s v )
    (while
        (progn (setvar 'errno 0) (setq s (entsel "\nSelect line near end point to modify: "))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null s) nil)
                (   (/= "LINE" (cdr (assoc 0 (setq e (entget (car s))))))
                    (princ "\nSelected object is not a line.")
                )
                (   (setq p (cdr (assoc 10 e))
                          q (cdr (assoc 11 e))
                    )
                    (if (< (distance (trans (cadr s) 1 0) p) (distance (trans (cadr s) 1 0) q))
                        (setq k 10 v (mapcar '- p q))
                        (setq k 11 v (mapcar '- q p))
                    )
                    (setq v (mapcar '(lambda ( s d ) (cond ((getdist (strcat "\nNew delta " s " <" (rtos d) ">: "))) (d))) '("X" "Y") v))
                    (entmod (subst (cons k (mapcar '+ (cdr (assoc (- 21 k) e)) v)) (assoc k e) e))
                    nil
                )
            )
        )
    )
    (princ)
)
Message 11 of 13

Anonymous
Not applicable

Wow, Lee, very good job! I'm impressed.

0 Likes
Message 12 of 13

Lee_Mac
Advisor
Advisor
damian.wrobel wrote:

Wow, Lee, very good job! I'm impressed.

 

Thank you damian! Smiley Happy

0 Likes
Message 13 of 13

Anonymous
Not applicable

Dear Lee,

I use your lisp and I'm glad you wrote it. But there is only one thing which ciuld make it even more useful.

It would be superb if you would add two options:

1. in the '<>' will stay current Length_X value

2. option 'Leave the downslope unchanged' - AutoCad changes Len_Y so the Len_X is changed, but downslope is not.

 

It would look like this:

"Specify new Length_X (TYPE or PICK) <>: "

"Specify new Length_Y or [Leave the downslope unchanged]: "

 

I think it would make the work in Autocad more easier.

0 Likes