Jump to content

Need a Fix in LISP for cylindrical break in AutoCAD


hibba

Recommended Posts

Quote

 

; Define the function for the cylindrical break command
(defun c:CYL_BREAK (/ pt1 pt2 radius normal start-end ang1 ang2 end1 end2 ent)

  ; Get the first point using a point selection dialog box
  (setq pt1 (getpoint "\nSpecify first point: "))

  ; Get the second point using a point selection dialog box
  (setq pt2 (getpoint pt1 "\nSpecify second point: "))

  ; Prompt the user to enter the radius of the cylindrical break
  (setq radius (getreal "\nEnter radius: "))

  ; Calculate the normal vector and start/end points of the break
  (setq normal (vlax-3d-get-normal (vlax-3d-point pt1) (vlax-3d-point pt2)))
  (setq start-end (mapcar 'vlax-safearray->list (vlax-3d-point pt1) (vlax-3d-point pt2)))
  (setq ang1 (angle (car start-end) (cadr start-end)))
  (setq ang2 (+ ang1 pi))
  (setq end1 (polar (car start-end) ang1 radius))
  (setq end2 (polar (cadr start-end) ang2 radius))

  ; Draw the break using a polyline
  (setq ent (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 2) '(70 . 1) (cons 10 (car start-end)) (cons 20 (cadr start-end)) (cons 10 (car end1)) (cons 20 (cadr end1)) (cons 10 (car end2)) (cons 20 (cadr end2)))))

  ; Set the layer of the polyline to "Break"
  (vla-put-layer (vlax-ename->vla-object ent) "Break")
  (princ)
)

 

 

 

i created a lisp routing from ChatGPT for cylindrical break. but this lisp is not running. i have zero knowledge for a lisp routine coding. so my question is there anyone who can fix the code to make it work properly?  

Link to comment
Share on other sites

That's LWPOLYLINE with 4 vertices and all have bulge(s) - data describing strength of arced segments... My advice is that now that you've drawn -create block and insert it with point, angle, scale and that's all...

Link to comment
Share on other sites

thanks for your suggestion. there are many paid version programs that can draw cylindrical break by using command in AutoCAD. when you have to work on multiple drawings and the use case is more then lisp will be more better for time saving. 

Link to comment
Share on other sites

For this I have a block, set to the proportions I want.. insert and scale.

 

Back to your question, ChatGPT is coming up more regularly here, and on other forums and it is important perhaps to understand how it works a little - as far as I understand it zooms through the internet and finds the most probable next line to use, whether this is a LISP,  a poem or a recipe for cookies. It does not have programming knowledge, it is just doing educated guesses. And so it's use should be taken as 'it might work' and a lot of checking and validation is still needed. You have to be able to debug what it produces and work out what it is doing.

 

If it was me I would be using internet searches:

How to make a arc with LISP - this is 3 arcs.

How to make block with LISP

How to get points, angles between points and distance between points with LISP

How to insert a block with LISP

 

it is all out there to copy and paste.

 

So try this... copied and pasted from my library but mostly learnt from copying what is online

 

 

(defun c:pipe_end ( / MyBlk)
  (defun makearc ( ArcPt ArcRad ArcAnga ArcAngb / )
    (entmake (list
      '(0 . "ARC")
      '(100 . "AcDbEntity")
      (cons 10 ArcPt)
      (cons 40 ArcRad)
      (cons 50 ArcAnga)
      (cons 51 ArcAngb)
    ))
  )
  (defun RtD ( r / ) (* 180.0 (/ r pi)) )

  (setq pta (getpoint "Select Start Point"))
  (setq ptb (getpoint "Select End Point"))
  (setq diameter (distance pta ptb))
  (setq MyScale (/ diameter 100))
  (setq rotation (- (RtD (angle pta ptb)) 90))

  (entmake '(
    (0 . "BLOCK")
    (8 . "0")
    (2 . "Pipe_End")
    (70 . 2)
    (4 . "")
    (8 . "0")
    (62 . 0)
    (6 . "ByBlock")
    (370 . -2)
    (10 0.0 0.0 0.0)
  ))
  (makearc '(-18.0244 29.2613) '34.3672 '5.2645 '0.7944)
  (makearc '(11.3941 25) '27.4741 '1.9984 '4.2848)
  (makearc '(-11.4084 75) '27.48 '5.1405 '1.1427)
  (entmake '(
    (0 . "ENDBLK")
    (8 . "0")
    (8 . "0")
    (62 . 0)
    (6 . "ByBlock")
    (370 . -2)
  ))
  (command "insert" "Pipe_End" pta MyScale MyScale rotation)
  (setq MyBlk Entlast)
)

 

 

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

And simply this ?

(defun c:CYL_BREAK ( / pt1 pt2 pt-mid)
; Get the first point using a point selection dialog box
  (initget 1)
  (setq pt1 (getpoint "\nSpecify first point: "))

; Get the second point using a point selection dialog box
  (initget 33)
  (setq
    pt2 (getpoint pt1 "\nSpecify second point: ")
    pt-mid (mapcar '* (mapcar '+ pt1 pt2) '(0.5 0.5 0.5))
  )

; Draw the break using a polyline
  (entmakex
    (list
      '(0 . "LWPOLYLINE")
      '(100 . "AcDbEntity")
      '(8 . "Break")
      '(62 . 1)
      '(100 . "AcDbPolyline")
      '(90 . 4)
      '(70 . 0)
      (cons 10 pt1)
      (cons 42 (1- (sqrt 2)))
      (cons 10 pt-mid)
      (cons 42 (- 2 (sqrt 2)))
      (cons 10 pt2)
      (cons 42 (- 2 (sqrt 2)))
      (cons 10 pt-mid)
    )
  )
  (prin1)
)

 

  • Like 2
Link to comment
Share on other sites

Troggarf nice option.

 

Another.

; DRAWS ELLIPSEOID ENDS ON A PIPE
(defun c:pend ( / pt1 pt2 pt3 dist ang midpt bulge)
(SETQ PT1 (GETPOINT "\n PICK PT1"))
(SETQ PT2 (GETPOINT "\n PICK PT2"))


(SETQ DIST (DISTANCE PT1 PT2))
(SETQ ANG (ANGLE PT1 PT2))

(SETQ MIDPT (POLAR PT1 ang (/ DIST 2.0)))

(SETQ BULGE (GETREAL "\n ENTER BULGE FACTOR  <40> ")) 


(if (= BULGE nil)(setq BULGE 0.4)(setq bulge (/ bulge 100)))

(SETQ DIST (/ DIST 4.0))
(SETQ PT3 (POLAR PT1 ANG DIST))

(SETQ ANG (+ ANG 1.5714))
(SETQ DIST (* DIST BULGE))
(SETQ PT3 (POLAR PT3 ANG DIST))

(COMMAND "ARC" PT1 PT3 MIDPT)

(COMMAND "COPY" "L" "" PT1 MIDPT)

(COMMAND "MIRROR" "L" "" PT1 PT2 "N")

(setq bulge nil
      pt1   nil
      pt2  nil)
(PRINC)
)
(c:pend)

 

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