Jump to content

DXF code error when creating a center point to insert a circle based on math


RLispLearner
 Share

Recommended Posts

Hi all,

 

I am getting a DXF code error (on group code 10 I believe) when I try to create a center point for my circle based on math. Perhaps I have the wrong syntax . Does someone see the issue by chance?

 

FYI: When the routine works, there should be a rectangle with a midpoint line on the longest side and a 24 diameter circle at each end of the midpoint line.  Thanks in advance everyone!

 

 

Code:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Create a rectangle. Draw a midpoint line on the longest side of a rectangle ;;;;
;;; Put a 24 diameter circle at each end of the midpoint line drawn             ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
(defun c:midlinecircles (/ mylength mywidth mylengthmid1 mylengthmid2 mywidthmid1 mywidthmid2 pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 )

  (VL-LOAD-COM)
  (command-s "_.rectang"); [draw area for rectangle]
  (setq
    pt1 (vlax-curve-getPointAtParam (entlast) 0)
    pt2 (vlax-curve-getPointAtParam (entlast) 1)
    pt3 (vlax-curve-getPointAtParam (entlast) 2)
    pt4 (vlax-curve-getPointAtParam (entlast) 3)
  ); 


;Get length and width of rectangle
(setq mylength (distance pt1 pt2)); length
(setq mywidth (distance pt1 pt4)); width

;Find the mid point of each side of the rectangle
;
  (setq mylengthmid1 (/ (distance pt1 pt2) 2)) ; mid point of length on one side of rectangle
  (setq mylengthmid2 (/ (distance pt3 pt4) 2)); mid point of length on the opposite side of rectangle
;
  (setq mywidthmid1 (/ (distance pt2 pt3) 2)) ;mid point of width on one side of rectangle
  (setq mywidthmid2 (/ (distance pt1 pt4) 2)) ;mid point of width on the opposite side of rectangle
;
;
;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;
;
;Find out which is the shorter side of the rectangle and then draw a line between the midpoints
;
  (if (> mywidth mylength); if mywidth is more than my length * 2 ( if true then...)
    ;;

  (Progn
    (setq pt5 (/ (distance pt2 pt3) 2))
    (setq pt6 (/ (distance pt1 pt4) 2))

    (entmake (list '(0 . "LINE")
           (cons 10 (polar pt2 (angle pt2 pt3) (/ (distance pt2 pt3) 2)))
           (cons 11 (polar pt1 (angle pt1 pt4) (/ (distance pt1 pt4) 2)))
           ;; put the line on a layer
           '(8 . "MIDPOINTLINE")
           ;;color white
           '(62 . 7)

         )


;Draw a circle at the end of the midpoints with diameter of 24
(entmake
        (list '(0 . "CIRCLE")
              (cons 10  (/ (distance pt2 pt3) 2))
              (cons 40 48); size 24 diameter
        
        )
)

(entmake
        (list '(0 . "CIRCLE")
              (cons 10  (/ (distance pt1 pt4) 2))
              (cons 40 48); size 24 diameter
        
        )
)

;Draw a circle at the end of the midpoints
;(command "_circle" pt5 "D" 24); Doesnt work
;(command "_circle" pt6 "D" 24); Doesnt work


   );End Progn
  );End IF


; If its not true then...
;
  (Progn
    (setq pt7 (/ (distance pt1 pt2) 2))
    (setq pt8 (/ (distance pt3 pt4) 2))
    (entmake (list '(0 . "LINE")
           (cons 10 (polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2)))
           (cons 11 (polar pt3 (angle pt3 pt4) (/ (distance pt3 pt4) 2)))
           ;; put the line on a layer
           '(8 . "MIDPOINTLINE")
           ;;line to color white
           '(62 . 7)
         )

;Draw a circle at the end of the midpoints with diameter of 24
(entmake
        (list '(0 . "CIRCLE")
              (cons 10  (/ (distance pt1 pt2) 2))
              (cons 40 48); size 24 diameter
        
        )
)

(entmake
        (list '(0 . "CIRCLE")
              (cons 10  (/ (distance pt3 pt4) 2))
              (cons 40 48); size 24 diameter
        
        )
)

;Draw a circle at the end of the midpoints
;(command "_circle" pt7 "D" 24); Doesnt work
;(command "_circle" pt8 "D" 24); Doesnt work

    ); End Draw a line from mid points mylengthmid1 to mylengthmid2
   );End Progn
  ) ;_ if

); End Program

 

 

 

Link to comment
Share on other sites

I think this will work better

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Create a rectangle. Draw a midpoint line on the longest side of a rectangle ;;;;
;;; Put a 24 diameter circle at each end of the midpoint line drawn             ;;;;
;;; Mods by Isaac A.															;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:midlinecircles (/ mylength mywidth oldecho pt1 pt2 pt3 pt4 pt5 pt6)
  (vl-load-com)
  (setq oldecho (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  (setq
    pt1 (getpoint "\nPick the first point")
    pt3 (getcorner "\Pick the next corner" pt1)
  )
  (vl-cmdf "_.rectang" pt1 pt3)
  (setq  pt2 (vlax-curve-getPointAtParam (entlast) 1)
         pt4 (vlax-curve-getPointAtParam (entlast) 3) 
  )
;Get length and width of rectangle
(setq mylength (distance pt1 pt2)); length
(setq mywidth (distance pt1 pt4)) ; width
;Find out which is the shorter side of the rectangle and then draw a line between the midpoints
  (if (> mywidth mylength); if mywidth is greather than mylength ( if true then...)
  (progn
    (setq pt5 (list (/ (+ (car pt1) (car pt4)) 2) (/ (+ (cadr pt1) (cadr pt4)) 2)))
    (setq pt6 (list (/ (+ (car pt2) (car pt3)) 2) (/ (+ (cadr pt2) (cadr pt3)) 2)))
    (entmake (list '(0 . "LINE")
           (cons 10 pt5)
           (cons 11 pt6)
           ;; put the line on a layer
           '(8 . "MIDPOINTLINE")
           ;;color white
           '(62 . 7)
           )
    )
;Draw a circle at the end of the midpoints with diameter of 24
    (entmake
        (list '(0 . "CIRCLE")
              (cons 10  pt5)
              (cons 40 12); size 24 diameter
        )
    )
    (entmake
        (list '(0 . "CIRCLE")
              (cons 10  pt6)
              (cons 40 12); size 24 diameter
        )
    )
  );End Progn
   ; If its not true then...
  (progn
    (setq pt5 (list (/ (+ (car pt1) (car pt2)) 2) (/ (+ (cadr pt1) (cadr pt2)) 2)))
    (setq pt6 (list (/ (+ (car pt3) (car pt4)) 2) (/ (+ (cadr pt3) (cadr pt4)) 2)))
    (entmake (list '(0 . "LINE")
           (cons 10 pt5)
           (cons 11 pt6)
           ;; put the line on a layer
           '(8 . "MIDPOINTLINE")
           ;;color white
           '(62 . 7)
           )
    )
;Draw a circle at the end of the midpoints with diameter of 24
    (entmake
        (list '(0 . "CIRCLE")
              (cons 10  pt5)
              (cons 40 12); size 24 diameter
        )
    )
    (entmake
        (list '(0 . "CIRCLE")
              (cons 10  pt6)
              (cons 40 12); size 24 diameter
        )
    )
  ) ;End Progn
  ) ;_ if
  (setvar 'cmdecho oldecho)
); End Program

 

Link to comment
Share on other sites

9 hours ago, RLispLearner said:

Thanks Isaac. This is a big help!

🙂

You're welcome

Link to comment
Share on other sites

15 hours ago, BIGAL said:

Another hint mid pt of 2 pts

 

(setq mp (mapcar '* (mapcar '+ pt1 pt2) '(0.5 0.5)))

Thank you BigAl it never crossed my mind, it's much less code

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