Jump to content

to draw numbers as clock dial


devitg

Recommended Posts

I have the attached DWG , 

 

image.png.6fef03ed5ba89e986500a2ce9a67478f.png

 

I need to represents  numbers from 0 to 14 to set speed at a dial cursor , I did it for 0 

 

Up now,  I made it by polar array . 

 

Could it be a lisp or a command  as to make incremental numbers from 0 to 14 clock wise  ?

Thanks in advance 

 

text at dial.dwg

Link to comment
Share on other sites

Because you have used array polar

 

(setq ss (ssget '((0 . "TEXT"))))

; ccw
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(vla-put-textstring obj (rtos x 2 0))
)


;cw
(setq x -1 y (- (sslength ss) 1))
(repeat (sslength ss)
(setq obj (vlax-ename->vla-object (ssname ss (setq x (1+ x)))))
(vla-put-textstring obj (rtos y 2 0))
(setq y (1- Y))
)

 

  • Like 1
Link to comment
Share on other sites

; DIAL - 2022.06.09 exceed
; https://www.cadtutor.net/forum/topic/75376-to-draw-numbers-as-clock-dial/
;
; Commad : DIAL
;
; If you specify the center point and start point of the dial, the text is created like the dial with that radius.
; It is judged whether the angle between the center point and the starting point is closer to 0, 90, 180, or 270 degrees, 
; and it is taken as the reference line.
;
; - The starting text is 0.
; - Depending on the number of text input, more numbers can be entered.
; - The size of the text can be adjusted with the TEXTSIZE command.

(vl-load-com)
(defun c:DIAL ( / centerpt startpt textnum startangle dialsize startangle direction exceptangle angle1piece textangle mspace textheight startnum placepoint textobj answer index stringlist objlist )
  (setq centerpt (getpoint "\n pick center point : "))
  (setq startpt (getpoint centerpt "\n pick start point : "))
  (setq textnum (getint "\n input number of texts : "))
  (setq startangle (angle centerpt startpt))
  (setq dialsize (distance centerpt startpt))

  (defun dtr (a) (* pi (/ a 180.0)))
  (defun rtd (a) (/ (* a 180.0) pi))

  (setq startangle (rtd startangle))
  (princ "\n because your start angle is : ") 
  (princ startangle)
  (cond
    ((and (>= startangle 0) (< startangle 45)) 
      (setq direction "CCW")
      (setq exceptangle (* 2 (- startangle 0)))
    )
    ((and (>= startangle 45) (< startangle 90)) 
      (setq direction "CW")
      (setq exceptangle (* 2 (- 90 startangle)))
    )   
    ((and (>= startangle 90) (< startangle 135)) 
      (setq direction "CCW")
      (setq exceptangle (* 2 (- startangle 90)))
    )
    ((and (>= startangle 135) (< startangle 180)) 
      (setq direction "CW")
      (setq exceptangle (* 2 (- 180 startangle)))
    )   
    ((and (>= startangle 180) (< startangle 225)) 
      (setq direction "CCW")
      (setq exceptangle (* 2 (- startangle 180)))
    )
    ((and (>= startangle 225) (< startangle 270)) 
      (setq direction "CW")
      (setq exceptangle (* 2 (- 270 startangle)))
    )   
    ((and (>= startangle 270) (< startangle 315)) 
      (setq direction "CCW")
      (setq exceptangle (* 2 (- startangle 270)))
    )
    ((and (>= startangle 315) (< startangle 360)) 
      (setq direction "CW")
      (setq exceptangle (* 2 (- 360 startangle)))
    )   
  )
  (princ "\n make it : ") 
  (princ direction)
  (princ "\n exception angle : ")
  (princ exceptangle)

  (setq angle1piece (/ (- 360 exceptangle) (- textnum 1)))
  (setq textangle startangle)

  (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
  (setq textheight (getvar 'textsize))

  (setq startnum 0) ; change this if you want to edit the start number

  (setq stringlist '())
  (setq objlist '())
  (repeat textnum
    (setq placepoint (polar centerpt (dtr textangle) dialsize))
    (setq textobj (vla-addtext mspace startnum (vlax-3d-point placepoint) textheight))
    (vlax-put-property textobj 'alignment 10)
    (setq objlist (cons textobj objlist))
    (setq stringlist (cons startnum stringlist))
    (setq startnum (+ startnum 1))
    (cond 
      ((= direction "CW")
        (setq textangle (- textangle angle1piece))
      )
      ((= direction "CCW")
        (setq textangle (+ textangle angle1piece))
      )
    )
  );end of repeat

  (setq answer (getstring "\n do you want reverse it? [ SpaceBar - No / Y - Yes ] : \n"))
  (if (= "Y" (strcase answer))
    (progn
      (setq stringlist (reverse stringlist))
      (setq index 0)
      (repeat textnum
        (vla-put-textstring (nth index objlist) (nth index stringlist))
        (setq index (+ index 1))
      )
    )
    (progn)
  )
  (princ)
);end of defun

dial.gif

 

 

It might be a little different from what you're looking for, but for reference.

 

It only works by specifying two points and entering the number of texts. 

The direction of text writing is determined by nearest of 0,90,180,270 degrees, so it can be applied to any angle. 

There is no limit to the number, It is also possible to create a 360 degree protractor with 2 orthogonal points and input 361 

Edited by exceed
add function - reverse texts Y/N
  • Like 1
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...