Jump to content

Recommended Posts

Posted

Hi everyone,

I was hoping someone could help me learn how to have varying lines all start at the same line. 

 

Here's an example.
Left is what I'm starting with and the right is the result I want.
 

https://imgur.com/a/OAgM9tH

Posted

That example, you can use rotate reference option, select the part touching as base point, type R for reference and select the base point again then the bottom of the far line, rotate down to the base line.

Posted

Can you tell me what im missing, I tried following the instructions and this is what I ended up with. 

The varied length lines are touching the "base" line but rotated.


Sketch.JPG.e7d796c1b701714e7ab8bcf197b041c9.JPG

Posted (edited)

One way to solve this is using getclosestpointo comparing the end points to the desired line, then use move. 

 

Something like this, note only works on vertical lines.

 

(defun c:mver ( / oldsnap ss obj1 obj start end d1 d2 pt ent)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(prompts "select lines"
(setq ss (ssget '((0 . "LINE"))))

(setq obj1 (vlax-ename->vla-object (car (entsel "\nSelect line end "))))

(repeat (setq x (sslength ss))
  (setq ent (ssname ss (setq x (- x 1))))
  (setq obj (vlax-ename->vla-object ent))
  (setq start (vlax-curve-getstartPoint obj))
  (setq end (vlax-curve-getEndPoint obj))
  (setq pt (vlax-curve-getclosestpointto obj1 start))
  (setq d1 (distance pt start))
  (setq d2 (distance pt end))
  (if (> d1 d2)
   (command "move" ent "" start pt)
   command "move" ent "" end pt)
 )
)
(setvar 'osmode oldsnap)
(princ)

)
(c:mver)

 

Edited by BIGAL
Posted

Yes, I was in a hurry and didn't think that through.

 

This likely needs a LISP solution.

Posted

I had to read lots of AfraLISP this last week and last weekend among other LISP sites and examples.

It could use improvement?

 

;;; Routine that moves lines and polylines vertically to a common line with choice of the Start or End.                                             *|
;;;                                                                                                                                                 *|
;;; https://www.cadtutor.net/forum/topic/89801-can-you-move-varying-length-lines-to-have-them-start-at-the-same-axis/?do=findComment&comment=648694 *|
;;;                                                                                                                                                 *|
;;; By SLW210 (Steve Wilson)                                                                                                                        *|
;;;                                                                                                                                                 *|
;;; Original 08/18/2024                                                                                                                             *|
;;;                                                                                                                                                 *|
;;; Helped by BIGAL's example                                                                                                                       *|
;;;                                                                                                                                                 *|
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*|
 
(defun c:M2Line (/ commonLine p1 p2 entity startPt endPt ptProjStart ptProjEnd moveDist ptMove moveWhich ss i)
  ; Prompt user to select the common line
  (setq commonLine (car (entsel "\nSelect the common line: ")))
  (if (not commonLine)
    (progn
      (princ "\nNo common line selected.")
      (exit)
    )
  )

  ; Get the start and end points of the common line
  (setq p1 (vlax-curve-getStartPoint commonLine))
  (setq p2 (vlax-curve-getEndPoint commonLine))

  ; Initialize a selection set to store multiple entities
  (setq ss (ssget '((0 . "LINE,LWPOLYLINE"))))

  ; Check if selection set is valid
  (if (not ss)
    (progn
      (princ "\nNo valid entities selected.")
      (exit)
    )
  )

  ; Ask user which end to move, only once
  (setq moveWhich (getstring T "\nMove far end or near end? [F/N]: "))
  (setq moveWhich (strcase moveWhich))

  ; Loop through each entity in the selection set
  (setq i 0)
  (repeat (sslength ss)
    (setq entity (ssname ss i))
    (setq i (1+ i))

    ; Check entity type and get start and end points
    (if (or (eq "LWPOLYLINE" (cdr (assoc 0 (entget entity))))
            (eq "LINE" (cdr (assoc 0 (entget entity)))))
      (progn
        (setq startPt (vlax-curve-getStartPoint entity))
        (setq endPt (vlax-curve-getEndPoint entity))
        
        ; Project both start and end points onto the common line
        (setq ptProjStart (vlax-curve-getClosestPointTo commonLine startPt))
        (setq ptProjEnd (vlax-curve-getClosestPointTo commonLine endPt))

        (cond
          ((= moveWhich "F")
           ; Calculate move distance for start point
           (setq moveDist (- (cadr ptProjStart) (cadr startPt)))
           (setq ptMove (list (car startPt) (+ (cadr startPt) moveDist)))

           ; Move the polyline or line to align with the common line
           (command "MOVE" entity "" startPt ptMove)
          )
          
          ((= moveWhich "N")
           ; Calculate move distance for end point
           (setq moveDist (- (cadr ptProjEnd) (cadr endPt)))
           (setq ptMove (list (car endPt) (+ (cadr endPt) moveDist)))

           ; Move the polyline or line to align with the common line
           (command "MOVE" entity "" endPt ptMove)
          )
          
          (T
           (princ "\nInvalid option. Please enter 'F' or 'N'.")
           (exit)
          )
        )
      )
    )
  )

  (princ "\nAll selected polylines and lines have been moved to align with the common line.")
  (princ)
)

 

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