Jump to content

Recommended Posts

Posted

I found a lisp routine that devides lenghts and places insert points.

For architectural design it would be such a time saver because I always place objects by drawing an intercept theorem to devide,or calculate a length on my mind.

 

So why does this not work in graebert ares commander (auto cad alternative with lisp funktion)?

 

Has it something to do with the grread function? (I read in the forum I found the code grread is used to do the program)

        ;; ----------------------------------------
        ;; div (dynamic divide) - by dexus 2022
        ;; ----------------------------------------
        ;;
        ;; Dynamic version of the divide function.
        ;; Divides a line into segments using points.
         
        (defun c:div (/ cmd div gr1 gr2 i isTmp len part pt ss str strval target _princ _try)
          (defun _try (func inputs / result)
            (if (not (vl-catch-all-error-p (setq result (vl-catch-all-apply func inputs))))
              result
            )
          )
          (defun _princ (str div newdiv)
            (repeat (+ (strlen (itoa div)) (strlen str) 3)
              (princ "\010\040\010")
            )
            (princ (strcat (itoa newdiv) ">: "))
            (setenv "dexus:div" (itoa newdiv))
            newdiv
          )
          (setq cmd (getvar 'cmdecho))
          (setvar 'cmdecho 0)
          (command "._UNDO" "_Begin")
         
          (setq div (cond ((_try 'atoi (list (getenv "dexus:div")))) (6)) str "")
          (princ
            (strcat
              "\nEnter number of segments or use +/- in- or decrease the amount of segments."
              "\nSelect object to divide <" (itoa div) ">: "
            )
          )
          (while
            (progn
              (setq gr1 (grread T 15 2)
                    gr2 (cadr gr1)
                    gr1 (car gr1))
              (cond
                ((or (= gr1 3) (= gr1 5))
                  (setq isTmp (= gr1 5))
                  (redraw)
                  (cond
                    (
                      (and
                        (/= div 0)
                        (setq ss (ssget gr2))
                        (/= (sslength ss) 0)
                        (setq target (ssname ss 0))
                        (member (cdr (assoc 0 (entget target))) '("LINE" "ARC" "LWPOLYLINE"))
                      )
                      (setq len (vlax-curve-getDistAtParam target (vlax-curve-getEndParam target))
                            part (/ len div)
                            i part)
                      (while (not (or (equal i len 1e-4) (> i len)))
                        (setq pt (vlax-curve-getPointAtDist target i)
                              i (+ i part))
                        (if isTmp
                          (grpoint pt nil) ; Tmp Point
                          (entmakex (list '(0 . "POINT") (cons 10 pt))) ; Point
                        )
                      )
                      isTmp
                    )
                    ((not isTmp)
                      (princ (strcat "\nMissed! try again...\nSelect object to divide <" (itoa div) ">: "))
                    )
                    (T)
                  )
                )
                ((= 2 gr1)
                  (cond
                    ((= 8 gr2) ; Backspace
                      (and
                        (< 0 (strlen str))
                        (princ "\010\040\010")
                        (setq str (substr str 1 (1- (strlen str))))
                      )
                      T
                    )
                    ((or (= 43 gr2) (= 61 gr2)) ; PLUS
                      (setq div (_princ str div (1+ div))
                            str "")
                      T
                    )
                    ((or (= 45 gr2) (= 95 gr2)) ; MINUS
                      (if (> div 2)
                        (setq div (_princ str div (1- div))
                              str "")
                      )
                      T
                    )
                    ((or (= 13 gr2) (= 32 gr2)) ; Enter or Space
                      (if (/= str "") ; Break loop if str is empty
                        (if (setq strval (_try 'atoi (list str))) ; Get new divisor
                          (setq div (_princ str div strval)
                                str "")
                        )
                      )
                    )
                    ((< 32 gr2 127) ; [a-zA-Z0-9]
                      (setq str (strcat str (princ (chr gr2))))
                    )
                  )
                )
                ((= 11 gr1) T) ; Aux Menu (ignore)
                ((= 13 gr1) T) ; Menu (ignore)
              )
            )
          )
         
          (redraw)
          (command "._UNDO" "_End")
          (setvar 'cmdecho cmd)
          (princ)
        )
         
        ;; -----------------------
        ;; grpoint - by dexus 2022
        ;; -----------------------
        ;;
        ;; Draws a temporary point at location.
        ;;
        ;; Size and shape are derived from the point style settings.
        ;; If color is not given it will use the color of the current layer.
        ;;
        ;; Usage: (grpoint location colornumber)
         
        (defun grpoint (point col / c e i m typ r rad s x _pol _rev)
          (defun _pol (x) ; Polar for 1/24th piece
            (polar point (* i x) rad)
          )
          (defun _rev (x) ; Revolve
            (if x (setq x (cons (car x) (reverse (cdr x)))))
          )
          (if (and point (listp point))
            (progn
              (or
                (= 'int (type col)) ; If color is not set, use color of currentlayer
                (setq col (cdr (assoc 62 (tblsearch "layer" (getvar 'clayer)))))
              )
              (setq typ (getvar 'pdmode) ; typ - get type of point
                    rad (getvar 'pdsize) ; rad - get pointsize
                    rad (cond
                          ((equal rad 0.0 1e-4) (/ (getvar 'viewsize) 40))
                          ((minusp rad) (/ (getvar 'viewsize) (/ 200 (abs rad))))
                          (rad)
                        )
                    m (* pi 2)
                    i (/ pi 12)
                    r (* rad 0.5)
                    e (rem typ 32)
                    e (cond ; e - extra lines
                        ((= e 0) (list point point))
                        ((= e 2) (mapcar '_pol '(0 12 6 18)))
                        ((= e 3) (mapcar '_pol '(3 15 9 21)))
                        ((= e 4) (list point (polar point (* i 6) r)))
                      ))
              (if (zerop (boole 2 32 typ)) ; c - circle
                (repeat 24
                  (setq m (- m i)
                        x (polar point m r)
                        c (vl-list* x x c))
                )
              )
              (if (> typ 63) ; s - square
                (foreach x '((-1 -1) (1 -1) (1 1) (-1 1) (-1 -1))
                  (setq x (list
                            (if (minusp (car x)) (- (car point) r) (+ (car point) r))
                            (if (minusp (cadr x)) (- (cadr point) r) (+ (cadr point) r))
                          )
                        s (vl-list* x x s))
                )
              )
              (grvecs (cons col (append (_rev c) (_rev s) e)))
              t
            )
          )
        )

    [Click and drag to move]


[Click and drag to move]

When I use the lisp it tells my to pick the object: line, pline or spline I think and the cursor changes to pick but I cant pick an item.

so it tells :"Missed! try again..."

I can enter a number of divisions I want to make but the program crashes after this

 

I fsomeone knows a trick to get grread to work in bricks cad, draft sight or ares commander, pls tell me!

Posted (edited)

grread looks at a lot of things

 

In this lisp its uses in a loop to allow the user to change the division of the entity. it loops 100's if not 1000's times a second. but once clicked it uses the mouse position like demo 2 here to select the entity and then check it against a list.

 

(member (cdr (assoc 0 (entget target))) '("LINE" "ARC" "LWPOLYLINE"))

 

This is why its giving you the error. what ever your selecting are not  a line arc or lwpolyline. You might be able to add spline but i don't know if the vlax-curve functions work with a spline.

also it won't work on blocks made up of lines arc or lwpolyline. You either have to go into edit mode or explode it.

 

This will do the same thing without all the fancy grread. So it will only ask you for a division and then allow you to pick multiple entities one at a time.

(defun c:div (/ div ss target len part i pt)
  (setq div (getreal "\nDivide by: "))     
  (while (setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE,Line,ARC")))) ;only allows you to pick items listed and will be dash by mouse
    (setq target (ssname ss 0))
    (setq len (vlax-curve-getDistAtParam target (vlax-curve-getEndParam target))
          part (/ len div)
          i part
    )
    (while (not (or (equal i len 1e-4) (> i len)))
      (setq pt (vlax-curve-getPointAtDist target i)
            i (+ i part)
      )
      (entmakex (list '(0 . "POINT") (cons 10 pt)))  ; Point
    )
  )
  (princ)
)

 

Edited by mhupp

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