Jump to content

Recommended Posts

Posted

Hello experts.
I'm having problems with the lisp I'm using. Specifically:
- When I set dim style > round off = 10 the lisp I am using still reports the dim values with round off = 0.

Can experts help me fix this error?
Thank you very much !

ccd.lsp Copy dim.dwg

Posted

Like this?

 

(defun c:ccd (/ gtt dt sdt ent id str)
	(setq dt (ssget '((0 . "DIMENSION")))
		sdt (sslength dt)
		id 0
		gtt 0
		str "="
	)
	(repeat sdt
		(setq
			ent (ssname dt id)
			id (1+ id)
			gtt (+ gtt (gt1 ent) )
			str (strcat str  (Rtos (gt1 ent) 2 0 ) "+")
		)
	)
	(Lisped (substr str 1 (1- (strlen str))))
	(princ gtt)
	(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun gt1 (ent / so ro)
	;; roundoff
	(setq ro (nth 0 (ParseIt (cdr (assoc 3 (entget ent))))))
	
	(if (wcmatch (cdr (assoc 1 (entget ent))) "")
		(setq so (LM:roundm (cdr (assoc 42 (entget ent))) ro))		;; round the value to ro
		(setq so (atof (cdr (assoc 1 (entget ent)))))
	)
)

;; http://www.lee-mac.com/round.html
;; Round Multiple  -  Lee Mac
;; Rounds 'n' to the nearest multiple of 'm'
(defun LM:roundm ( n m )
    (* m (fix ((if (minusp n) - +) (/ n (float m)) 0.5)))
)

;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/extracting-numeric-values-on-a-string/td-p/784014
(defun ParseIt (str)
  (read
    (vl-list->string
      (append
        '(40) ; "(".
        (mapcar
          '(lambda (int) (if (or (= 46 int) (<= 48 int 57)) int 32))
          (vl-string->list str)
        )
        '(41) ; ")".
      )
    )
  )
)

 

  • Like 1
Posted

Thanks Emmanuel Delay.

Your Lisp works exactly as I wanted.

  • Like 1

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