Jump to content

Help me finish this LISP please


trmg

Recommended Posts

With this LISP Im trying to make under floor heating.

 

I think i am close to finishing it, but some error occurs in the end.

 

Im trying to explode the last selection set but to do that google told me that you need to (setvar "qaflags" 1), and i think it's there that i don't follow.

 

What is wrong and how to solve it?

 

Please note that Im new to LISP and programming in general.

 

If you took an extra minute to explain what i did wrong i would really appreciate it.

 

Also, Im sorry if the code looks really bad, as i said i am new to this.

 

Attaching a .dwg containing a block that is used in the lisp, so you can try it.

 

gv.dwg

 

(defun c:gt (/ lastEnt ss)
 ;; Save the last entity
 (setq lastEnt (entlast))
 ;; Underfloorheatinghorizontal
 
  



   (setq pt1 (getdist "\nSpecify length of room"))

   (setq pt2 (getdist "\nSpecify height of room"))
   
   (setq pt3 (getpoint "\nSpecify lower middlepoint of room"))
   
 (command "-insert" "1" "x" (-(* pt1 3) 300) "y" "300" pt3 "0")
 (command "move" "l" "" "d" "0,50,0")
 

;;; ROUND
;;; (round pi 0.01) -> 3.14
;;; (round pi 1e-5) -> 3.14159
;;; (round 5456.50 1) -> 5457
;;; (round 5456.50 100) -> 5500

(defun round (num prec)
 (* prec
    (if (minusp num)
      (fix (- (/ num prec) 0.5))
      (fix (+ (/ num prec) 0.5))
    )
 )
)


  (command "_array" "l" "" "rectangular" (round (/ pt2 600) 1) "1" "600")
  
  

(setq ss (ssadd))
 (while (setq lastEnt (entnext lastEnt))
   (ssadd lastEnt ss)


(sssetfirst nil ss) ;Grip select the set
 
 (setq OldQa (getvar "QAFLAGS" ) )
 (setvar "QAFLAGS" 5 )
 
   (command "._explode" SelSet)
 
 (setvar "QAFLAGS" OldQa )
  

 )

  

 (princ)
)

Link to comment
Share on other sites

(defun c:gt  (/ lastEnt ss)
     (setq pt1 (getdist "\nSpecify length of room"))
     (setq pt2 (getdist "\nSpecify height of room"))
     (setq pt3 (getpoint "\nSpecify lower middlepoint of room"))
     (command
           "-insert"
           "1"
           "x"
           (- (* pt1 3) 300)
           "y"
           "300"
           pt3
           "0")
     (command "move" "l" "" "d" "0,50,0");<not sure whats this for
     (defun round  (num prec)
           (* prec
              (if (minusp num)
                    (fix (- (/ num prec) 0.5))
                    (fix (+ (/ num prec) 0.5))
                    )
              )
           )
     [color=blue][b](setq lastEnt (entlast)[/b][/color]
[color=blue][b]            ss      (ssadd))[/b][/color]
     [color=blue][b](command "._explode" "L" "")[/b][/color]
     (command
           "_[b][color=blue]-[/color][/b]array"
          [color=blue][b] "P"[/b][/color]
           ""
           "rectangular"
           (round (/ pt2 600) 1)
           "1"
           "600")
     (while (setq lastEnt (entnext lastEnt))
           (ssadd lastEnt ss))
(sssetfirst nil ss)               ;Grip select the set
     (princ)
     )

Link to comment
Share on other sites

The move command is because i couldnt figure out how to use 50y above pt3.

 

Wow, thank you it does seem to work now.

 

I still cant figure out how to select created items for use in next commands. I would also like to pedit the selection and fillet it with a radius of 150.

 

Any input on that?

Link to comment
Share on other sites

Use variable ss

 

(defun c:gt  (/ lastEnt ss pt1 pt2 pt3 i e ang)
(defun round  (num prec)
   (* prec
      (if (minusp num)
            (fix (- (/ num prec) 0.5))
            (fix (+ (/ num prec) 0.5))
            )
      )
   )
(if (and      
     (setq pt1 (getdist "\nSpecify length of room"))
     (setq pt2 (getdist "\nSpecify height of room"))
     (setq pt3 (getpoint "\nSpecify lower middlepoint of room"))
     )
   (progn
         (command
               "-insert"
               "1"
               "x"
               (- (* pt1 3) 300)
               "y"
               "300"
               pt3
               "0")
         (command "move" "l" "" "d" "0,50,0")
                                       ;<not sure whats this for
         (setq lastEnt (entlast)
               ss      (ssadd))
         (command "._explode" "L" "")
         (command
               "_-array"
               "P"
               ""
               "rectangular"
               (round (/ pt2 600) 1)
               "1"
               "600")
         (while (setq lastEnt (entnext lastEnt))
               (ssadd lastEnt ss))
                                       ;(sssetfirst nil ss)
         [color=blue](repeat (setq i (sslength ss))[/color]
[color=blue]              (setq e   (ssname ss (setq i (1- i)))[/color]
[color=blue]                    Ang (apply 'angle[/color]
[color=blue]                               (setq se   (mapcar '(lambda (j)[/color]
[color=blue]                                                         (cdr (assoc j (entget e))))[/color]
[color=blue]                                                  '(10 11)))))[/color]
[color=blue]              (if (not (apply 'or (mapcar 'zerop (list i ang))))[/color]
[color=blue]                    (progn[/color]
[color=blue]                          (entmakex[/color]
[color=blue]                                (list (cons 0 "ARC")[/color]
[color=blue]                                      (cons 10 (mapcar[/color]
[color=blue]                                                  (function[/color]
[color=blue]                                                        (lambda (a b) (/ (+ a b) 2.)))[/color]
[color=blue]                                                  (car se)[/color]
[color=blue]                                                  (cadr se)))[/color]
[color=blue]                                      '(40 . 150)[/color]
[color=blue]                                      (cons 50 (if   (equal[/color]
[color=blue]                                                        ang[/color]
[color=blue]                                                        (/ pi  2.0)  0.1)[/color]
[color=blue]                                                       (* pi 1.5)[/color]
[color=blue]                                                       (/ pi 2.0)))[/color]
[color=blue]                                      (cons 51 Ang)[/color]
[color=blue]                                      ))[/color]
[color=blue]                          (entdel e)[/color]
[color=blue]                          (ssdel e ss)[/color]
[color=blue]                          (ssadd (entlast) ss)[/color]
[color=blue]                          )[/color]
[color=blue]                    )[/color]
[color=blue]              )[/color]
[color=blue]        (command "_pedit" "_multiple" ss "" "_Yes" "_join" "" "")[/color]
[color=blue]        )[/color]

   )

     (princ)

     )

 

Not sure if this is what you want though. :unsure:

 

EDIT: if you guys are wondeering about this

(not (apply 'or (mapcar 'zerop (list i ang))))

 

On testing phase (since i'm unsure of the OPS final result will be) I redfined block "i" from his example drawing (not attached here). that way the first vertical line will remain and the rest would be an arc.

Edited by pBe
info
Link to comment
Share on other sites

(repeat (setq i (sslength ss))
             (setq e   (ssname ss (setq i (1- i)))
                   Ang (apply 'angle
                              (setq se   (mapcar '(lambda (j)
                                                        (cdr (assoc j (entget e))))
                                                 '(10 11)))))
             (if (not (apply 'or (mapcar 'zerop (list i ang))))
                   (progn
                         (entmakex
                               (list (cons 0 "ARC")
                                     (cons 10 (mapcar
                                                 (function
                                                       (lambda (a b) (/ (+ a b) 2.)))
                                                 (car se)
                                                 (cadr se)))
                                     '(40 . 150)
                                     (cons 50 (if   (equal
                                                       ang
                                                       (/ pi  2.0)  0.1)
                                                      (* pi 1.5)
                                                      (/ pi 2.0)))
                                     (cons 51 Ang)
                                     ))
                         (entdel e)
                         (ssdel e ss)
                         (ssadd (entlast) ss)
                         )
                   )
             )

 

I have no idea what happens here but it does the job. Thank you so much for the help. I have to get to reading now so i will understand what the code does there.

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