Author Topic: Real Challenge: Create a SLIDE Command  (Read 644 times)

0 Members and 1 Guest are viewing this topic.

CodeDing

  • Newt
  • Posts: 51
Real Challenge: Create a SLIDE Command
« on: January 10, 2024, 12:20:06 PM »
Hey All!

I have a challenge for you: To create a SLIDE command.

The concept of the command:
Give the user the ability to SLIDE objects until they hit another object.

It just seems like such a frequently asked-for AutoLISP request on the forums.

I created a post originally over at Autodesk forums, but not much traction there, and this community seems to take challenges a bit more seriously.
Link to Autodesk forum post: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/challenge-create-a-slide-command/m-p/12415523

Here's some pictures of what the workflow might look like (this sample DWG is attached):











Best,
~DD
~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help?
Try my custom GPT 'AutoLISP Ace'

CodeDing

  • Newt
  • Posts: 51
Re: Real Challenge: Create a SLIDE Command
« Reply #1 on: January 10, 2024, 12:22:21 PM »
Also, I did get a concept working for LINES only. See attached lisp & drawing.

Notes:
- Sometimes lines move to 2nd barrier (obstacle) instead of first. Not sure why? It's a rare occurrence.
- For some reason after running command on lines ONCE, it will not let me move them a second time? (can someone explain why?)

To Do:
- Add ability for more entities to slide (and slide into)
- Increase performance by not selecting ALL entities to detect for collision, but rather only determine/select potential entities based on user-provided direction.
- Continually improve efficiency for functions.

Screenshots Before & After SLIDE(s):





Best,
~DD
~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help?
Try my custom GPT 'AutoLISP Ace'

57gmc

  • Bull Frog
  • Posts: 366
Re: Real Challenge: Create a SLIDE Command
« Reply #2 on: January 10, 2024, 04:06:32 PM »
I'm not sure when you would find this command useful, but do you want each ent to move until it hits the boundary or do you want the ents to move as a single group until the closest ent touches the boundary?

CodeDing

  • Newt
  • Posts: 51
Re: Real Challenge: Create a SLIDE Command
« Reply #3 on: January 10, 2024, 04:50:39 PM »
57GMC,

Quote
I'm not sure when you would find this command useful
Well, I personally may not have much use for it, but I see numerous requests on the online forums of users asking for this type of action. So I would bet it would help a fair amount of people quite a bit, depending on their use case.

Quote
do you want each ent to move until it hits the boundary or do you want the ents to move as a single group until the closest ent touches the boundary?
I thought about this after posting again, and I think it should ultimately be an option for the user to select the desired operation. (could be like a boolean or something)

Best,
~DD
~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help?
Try my custom GPT 'AutoLISP Ace'

57gmc

  • Bull Frog
  • Posts: 366
Re: Real Challenge: Create a SLIDE Command
« Reply #4 on: January 10, 2024, 04:58:47 PM »
The latter option is simply a MOVE command along a vector. You can use the IntersectWith method to get the closest point of intersection.

CodeDing

  • Newt
  • Posts: 51
Re: Real Challenge: Create a SLIDE Command
« Reply #5 on: January 10, 2024, 05:03:57 PM »
That would be assuming the user knows the 2 closest entities.

In a large selection set of entities sporadically spaced, it would be pretty hard to determine the 2 closest entities in the 'slide' (or move) direction.

Best,
~DD
~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help?
Try my custom GPT 'AutoLISP Ace'

nekonihonjin

  • Newt
  • Posts: 103
Re: Real Challenge: Create a SLIDE Command
« Reply #6 on: January 12, 2024, 03:17:05 PM »
This ask for a line (not polyline)  and aligns objects to it.

you may find it useful.


Code: [Select]
;; Project Point onto Line  -  Lee Mac
;; Projects pt onto the line defined by p1,p2

(defun LM:projectpointtoline ( pt p1 p2 / v1 )
   (if (setq v1 (vx1 (mapcar '- p2 p1)))
       (mapcar '+ p1 (vxs v1 (vxv (mapcar '- pt p1) v1)))
   )
)

;; Vector x Scalar  -  Lee Mac
;; Args: v - vector in R^n, s - real scalar

(defun vxs ( v s )
   (mapcar '(lambda ( n ) (* n s)) v)
)

;; Vector Dot Product  -  Lee Mac
;; Args: u,v - vectors in R^n

(defun vxv ( u v )
   (apply '+ (mapcar '* u v))
)

;; Unit Vector  -  Lee Mac
;; Args: v - vector in R^2 or R^3

(defun vx1 ( v )
   (   (lambda ( n ) (if (equal 0.0 n 1e-10) nil (mapcar '/ v (list n n n))))
       (distance '(0.0 0.0 0.0) v)
   )
)

(defun c:TEST ( / e p p2 q bl s i n)


(setq e (car (entsel "\nSelect line: ")))
(= "LINE" (cdr (assoc 0 (setq e (entget e)))))

    (if (setq s (ssget))
        (progn
            (setq i 0
                  n (sslength s)
            )
            (while (< i n)
             (setq bl (ssname s i))
             (command "_copy" bl "" "0,0" "0,0" "")
             (setq p (cdr (assoc 10 (entget (entlast)))))
             (setq q (LM:projectpointtoline (trans p 1 0) (cdr (assoc 10 e)) (cdr (assoc 11 e))))
             (entmake (list '(0 . "POINT") (cons 10 q)))
             (setq p2 (entlast))
             (command "_move" bl "" p q "")
             (command "_erase" p2 "")
             (setq i (1+ i))
            )
       )
   )
   (princ)
)

CodeDing

  • Newt
  • Posts: 51
Re: Real Challenge: Create a SLIDE Command
« Reply #7 on: January 15, 2024, 10:33:25 AM »
nekonihonjin,

Your code aligns a single point from an entity to a line at a perpendicular angle. This is not the goal of a slide command. Any angle of approach between 2 entities must be accepted and calculated precisely which is no easy task.

But I appreciate the input! Maybe try some more calculations and find a way to accept an input angle from the user, then come back and show everyone an updated version!

Happy Coding!
~DD
~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help?
Try my custom GPT 'AutoLISP Ace'