Jump to content

Looking for a Lisp to offset 1" an angle line to an ortho line!


stlo
 Share

Recommended Posts

Hi everyone! I wonder if it's possible to offset 1" an angle line to an ortho line? the calculation point of the 1" offset would depend on the offset direction. Here's is a dwg for better explanation! 

Thanks

Have a good day!

 

 

SPECIAL OFFSET.dwg

Link to comment
Share on other sites

Using VL  bounding box will give 4 ortho points of the line, using a pick near end method also gives a implied offset to right direction. Length or width greater is HOR or VER.

 

Will have a think maybe later today.

 

 

Link to comment
Share on other sites

@stlo

Give this a try:

(defun c:foo (/ a s)
  ;; RJP » 2022-09-21
  (cond	((setq s (ssget '((0 . "LINE"))))
	 (while (not (wcmatch (setq a (strcase (getstring "\nUp Down Left Right: "))) "U,D,L,R")))
	 (setq a (cdr (assoc a
			     '(("U" (0 0 1. 0) (0 0 1.25 0))
			       ("D" (0 0 -1. 0) (0 0 -1.25 0))
			       ("L" (0 -1. 0 0) (0 -1.25 0 0))
			       ("R" (0 1. 0 0) (0 1.25 0 0))
			      )
		      )
		 )
	 )
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (entmake (mapcar '(lambda (x)
			       (cond ((= 10 (car x)) (mapcar '+ (car a) x))
				     ((= 11 (car x)) (mapcar '+ (cadr a) x))
				     (x)
			       )
			     )
			    (entget e '("*"))
		    )
	   )
	 )
	)
  )
  (princ)
)

 

Link to comment
Share on other sites

Nice @ronjonp but i think the 1.25 was just for the example if the line was at another angle it then wouldn't be vertical or horizontal.

 

--EDIT

dxf 11 polar (0 , 90, 180, 270) length of line from pt 10?

Edited by mhupp
Link to comment
Share on other sites

1 minute ago, mhupp said:

Nice @ronjonp but i think the 1.25 was just for the example if the line was at another angle it then wouldn't be vertical or horizontal.

Ooops .. I did the opposite. Offset a straight line to a crooked one 😂

Link to comment
Share on other sites

Was thinking the same @BIGAL But tested for the farthest point.

 

--EDIT

Depending on where you pick doesn't give the right offset. needs another point test?

 

;;----------------------------------------------------------------------------;;
;; Ortho offset
(defun C:OOF (/ line LL UR LR UL d x dist pos)
  (if (and (setq line (car (entsel "\nSelect Line: "))) (eq (cdr (assoc 0 (entget line))) "LINE"))
    (progn
      (vla-getboundingbox (vlax-ename->vla-object line) 'minpt 'maxpt)
      (setq LL (vlax-safearray->list minpt)
            UR (vlax-safearray->list maxpt)
            LR (list (car UR) (cadr LL))
            UL (list (car LL) (cadr UR))
      )
      (setq pts (list LL UR LR UL))
      (setq d (getpoint "\nPick Offset Direction"))
      (setq x (mapcar '(lambda (p) (distance d p)) pts))
      (setq dist (car (vl-sort x '>)))
      (setq pos (vl-position dist x))
      (cond
        ((eq pos 0)
             (setq p1 (mapcar '+ LR '(1 0 0)))
             (setq p2 (mapcar '+ UR '(1 0 0)))
        )
        ((eq pos 1)
             (setq p1 (mapcar '- LL '(1 0 0)))
             (setq p2 (mapcar '- UL '(1 0 0)))
        )
        ((eq pos 2)
             (setq p1 (mapcar '+ UL '(0 1 0)))
             (setq p2 (mapcar '+ UR '(0 1 0)))
        )
        ((eq pos 3)
             (setq p1 (mapcar '- LL '(0 1 0)))
             (setq p2 (mapcar '- LR '(0 1 0)))
        )
      )
      (entmake (list '(0 . "LINE")
                     (cons 10 p1)
                     (cons 11 p2)
               )
      )
    )
  )
  (princ)
)

 

 

Edited by mhupp
Link to comment
Share on other sites

Tried calculating and angle from the midpoint but still wasn't 100%.

This works but have to input the direction you want the offset.

 

;;----------------------------------------------------------------------------;;
;; Ortho offset
(defun C:OOF (/ line LL UR MPT LR UL rep p1 p2)
  (if (and (setq line (car (entsel "\nSelect Line: "))) (eq (cdr (assoc 0 (entget line))) "LINE"))
    (progn
      (vla-getboundingbox (vlax-ename->vla-object line) 'minpt 'maxpt)
      (setq LL (vlax-safearray->list minpt)
            UR (vlax-safearray->list maxpt)
            MPT (mapcar '/ (mapcar '+ LL UR) '(2 2 2))
            LR (list (car UR) (cadr LL))
            UL (list (car LL) (cadr UR))
      )
      (initget "Up Down Left Right")
      (setq rep (getkword "\nOffset [Up Down Left Right]: "))
      (cond
        ((eq rep "Right")
             (setq p1 (mapcar '+ LR '(1 0 0)))
             (setq p2 (mapcar '+ UR '(1 0 0)))
        )
        ((eq rep "Up")  
            (setq p1 (mapcar '+ UL '(0 1 0)))
            (setq p2 (mapcar '+ UR '(0 1 0)))
        )
        ((eq rep "Left")
            (setq p1 (mapcar '- LL '(1 0 0)))
            (setq p2 (mapcar '- UL '(1 0 0)))
        )
        ((eq rep "Down")
            (setq p1 (mapcar '- LL '(0 1 0)))
            (setq p2 (mapcar '- LR '(0 1 0)))
        )
      )
      (if rep
        (entmake (list '(0 . "LINE")
                     (cons 10 p1)
                     (cons 11 p2)
                 )
        )
        (prompt "\nDirection not picked")
      )
    )
  )
  (princ)
)

 

Edited by mhupp
Link to comment
Share on other sites

Hi everyone! mhupp, thanks! this is perfect, entering the direction does the trick as well! Thanks ronjonp and BIGAL also for having a look at this and yes the 1.25 was just as an example, I should've mention it! You guys are awesome! No way I can build something like this, but I'm enjoying trying to understand the logic!

Have a great day!

Link to comment
Share on other sites

For mhupp no need for R or L pick use the pick end to imply side, check pick pt to start, end point, and this implies line direction so know L or R.

 

(setq ent (entsel "\npick object "))
(setq pt (cadr ent))
(setq obj (vlax-ename->vla-object (car ent)))
(setq end (vlax-curve-getendpoint  Obj))
(setq start (vlax-curve-getstartpoint  Obj))
(setq len (vla-get-length obj))
(setq d1 (distance pt end))
(setq d2 (distance pt start))
(if (< d1 d2)
(progn
(setq temp end)
(setq end start)
(setq start temp)
(reverse ent)
)
)

 

  • Like 1
Link to comment
Share on other sites

@BIGAL

No need to convert to an object when using curve functions. Plus you need to check if the object is actually selected and valid before trying to do anything with it. And what are you doing with the length ?

 

 

Edited by ronjonp
  • Like 1
Link to comment
Share on other sites

My mistake cut from a bit of code removed the length line. Yes does rely on the user picking something. Could wrap that part in a while. Same with the reverse may not be needed as reversed the line direction points. 

 

Another post over there forum, get a side of multiple parallel lines so dims go to pick the "F" fence side when choosing lines. Then  know left and right ends of those lines for dimensioning.

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

 Share

×
×
  • Create New...