Jump to content

Recommended Posts

Posted (edited)

Hello everyone, I hope you all healty and feeling hapy. Many greeting to you from capital of the Turkey 🇹🇷

 

I've a problem about syntax of my lisp that can print perimeter and area to attribute (Especially Room Tag). I tried many times to fix this error but I never find a solution about my problem. 

Thank you 

That's my lisp;

;;;;;;
;;;;;;;
(defun AREA_PERIMETER_SEC ()
  (prompt "\nSelect a closed POLYLINE")
  (setq sonobje (car (entsel)))
  (if sonobje
    (progn
      (setq silobje sonobje)
      (redraw silobje 3)
      (command "area" "e" sonobje)
                    ;(alert "Bulunan alan.")
  (setq alan (/ (getvar "area") 10000))
      (setq cevre (/ (getvar "perimeter") 100))
      (print)-
      (prompt (strcat "Bulunan alan ve cevre: "
          (rtos alan 2 2)
          "m²  "
          (rtos cevre 2 2)
          "mt. "
          )
      )
    )                    ;progn
    (progn (alert "Kapali alan bulunamadi.Tekrar deneyin.")
           (exit)
    )
  )                    ;if
)

;;;;-----MAIN PROGRAM-----
(defun DEGIS (ss es-alan es-cevre / ye-alan ye-cevre)
  (setq ye-alan (cons 1 (rtos alan 2 2)))
  (setq ye-cevre (cons 1 (rtos cevre 2 2)))
  (entmod
    (subst ye-alan
           es-alan
           (entget (entnext (entnext (entnext ss)))
       )
    )
  )
  (entmod
    (subst ye-cevre
           es-cevre
           (entget
             (entnext
               (entnext (entnext (entnext ss)))
         )
           )
    )
  )
  (entupd ss)
  (print)
  (prompt (strcat "Onceki alan ve cevre: "
                  (cdr es-alan)
          "m²   "
          "mt. "
      )
  )
  (print)
  (prompt (strcat "Yazilan alan ve cevre: "
          (cdr ye-alan)
          "m²   "
          (cdr ye-cevre)
          "mt. "
          )
  )
  (princ)
)
(defun C:RAPT ()                ; (/ obje x)
  (setq objeler nil
        silobje nil
  )
  ;;(prompt "\nHesaplanacak alani,")
  (initget "Orta Ciz Sec")

  (setq sec (AREA_PERIMETER_SEC))
  (setq
    ss (car
     (entsel "\nChoose the ROOM NUMBER to be CHANGED")
       )
  )
  (setq x 0)
  (if ss
    (progn
      (setq obje (substr (strcase (cdr (assoc 2 (entget ss)))) 1 7))
      (setq es-alan
             (assoc
           1
           (entget
                 (entnext (entnext (entnext ss)))
           )
             )
      )
      (setq es-cevre
             (assoc
               1
               (entget (entnext
                     (entnext
                           (entnext (entnext ss))
             )
               )
           )
             )
      )
      (if (= obje "MTAG")
    (DEGIS ss es-alan es-cevre)
      )                    ;if
    )                    ;progn
  )                    ;if
(command "")
)
(princ)()

RAPT.lsp

Edited by CADTutor
Moved script into code block
Posted

So that's quite long LISP, without me running it, where do you think the problem is? How far through the LISP does it get before it stops working? I'll often put in a (princ "OK") line - moving it each step, if the routine prints "OK" in the command line, then all is well to that point, move the princ line - there are more efficient ways to debug a LISP but that's just my way

 

 

Posted

@Steven P thanks for your response dear. Can you give me a sample about you tell me ( princ "OK" )? Actually if you can show me your way on my lisp then I'll understand better.

 

thank you so much.

Posted (edited)

So I copied your code to notepad and changed it slightly so some of the commands are written on one line and not over several - just makes it easier for me to read

 

In your first function Area_perimeter_sec I added a 'princ' at the end as an example of what I mean to use it as error checking... if it prints in the command line "Area Perimeter SEC OK!' then that LISP ran OK, and you know your problem is after that in your RAPT code. It does that OK. You can take this line out now.

 

So the next thing to look at is ss.. what are you expecting from "Choose the ROOM NUMBER to be CHANGED".. do you want the user to select an object like a line, a block or some text? or even to enter in the keyboard a number.. you see  after that you are asking for (assoc 2 (entget ss)).. which is where my CAD is having an error if I select a number. See the (princ....) line I added in here.

 

 

(defun AREA_PERIMETER_SEC ( / )
  (prompt "\nSelect a closed POLYLINE")
  (setq sonobje (car (entsel)))
  (if sonobje
    (progn
      (setq silobje sonobje)
      (redraw silobje 3)
      (command "area" "e" sonobje)
      (setq alan (/ (getvar "area") 10000))
      (setq cevre (/ (getvar "perimeter") 100))
      (prompt (strcat "Bulunan alan ve cevre: " (rtos alan 2 2) "m²  " (rtos cevre 2 2) "mt. " ))
    ) ;progn
    (progn (alert "Kapali alan bulunamadi.Tekrar deneyin.")
           (exit)
    ) ;progn
  ) ;if

(princ "Area Perimeter SEC OK!\n")(princ)

)

;;;;-----MAIN PROGRAM-----
(defun DEGIS (ss es-alan es-cevre / ye-alan ye-cevre)
  (setq ye-alan (cons 1 (rtos alan 2 2)))
  (setq ye-cevre (cons 1 (rtos cevre 2 2)))
  (entmod (subst ye-alan es-alan (entget (entnext (entnext (entnext ss))))))
  (entmod (subst ye-cevre es-cevre (entget (entnext (entnext (entnext (entnext ss)))))))
  (entupd ss)
  (print)
  (prompt (strcat "Onceki alan ve cevre: " (cdr es-alan) "m² " "mt. "))
  (print)
  (prompt (strcat "Yazilan alan ve cevre: " (cdr ye-alan) "m² " (cdr ye-cevre) "mt. " ))
  (princ)
)

(defun C:RAPT ( / )                ; (/ obje x)
  (setq objeler nil
        silobje nil
  )
;;  (initget "Orta Ciz Sec") ;;Not needed?
  (setq sec (AREA_PERIMETER_SEC)) ;;returns 'nil'
  (setq ss (car (entsel "\nChoose the ROOM NUMBER to be CHANGED")))
  (setq x 0)
  (if ss
    (progn

(princ "\n")
(princ (cdr (assoc 2 (entget ss))))
(princ "\n")

      (setq obje (substr (strcase (cdr (assoc 2 (entget ss)))) 1 7))  ;;what are you trying to get here?

(princ "Obje: ")(princ obje)

      (setq es-alan (assoc 1 (entget (entnext (entnext (entnext ss))))))
      (setq es-cevre (assoc 1 (entget (entnext (entnext (entnext (entnext ss)))))))
      (if (= obje "MTAG")
        (DEGIS ss es-alan es-cevre)
      )                    ;if
    )                    ;progn
  )                    ;if
;;(command "")
(princ)
)

 

Edited by Steven P
Posted

@Steven P Firstly, I'd like to thank you for your help. Actually I never give up after I post it this question and I was continuning to fix syntax error of my lisp. And I found some problems these are you told me. Now my lisp is working without problem. thank you so much again.

 

now I've a problem about my another autolisp. I'm using that lisp to create and change layer swift. here is my code for this lisp, I want to create a layer with name, color and lineweight that I define in lisp code line. I can create layers with name and color but I can't define a lineweight for each of them. This is what I want to do;

 

I'm working a construction company and we're preparing approximate cost for constructions and buildings. this is a automatic layer creater lisp is I'm using already. I want to improve my speed of work
;;;;General Legend and for preparing quantity takeoff
(DEFUN C:1 ()
 
(setq a(command "LAYER" "M" "____00-AF-GENERAL_LEGEND " "C" "231" "" ""))
)
 
(DEFUN C:2 ()

(setq b(command "LAYER" "M" "____00-AF-ROOM_AREA_AND_PERIMETER_DRAWER " "C" "20" "" ""))
)


;;;;FOR INTERIOR WALL

(DEFUN C:101 ()

(command "LAYER" "M" "____00-AF-10_CM_INTERIOR_WALL " "C" "30" "" "")
)

(DEFUN C:151 ()

(command "LAYER" "M" "____00-AF-15_CM_INTERIOR_WALL " "C" "11" "" "")
)

(DEFUN C:201 ()

(command "LAYER" "M" "____00-AF-20_CM_INTERIOR_WALL " "C" "241" "" "")
)

(DEFUN C:251 ()

(command "LAYER" "M" "____00-AF-25_CM_INTERIOR_WALL " "C" "211" "" "")
)

(DEFUN C:301 ()

(command "LAYER" "M" "____00-AF-30_CM_INTERIOR_WALL " "C" "230" "" "")
)

 

I want to add a lineweight each of my line with color and name.

 

Posted (edited)

NO need for setq a & setq b

 

You may want to use -layer as this avoids the dialouge box.

 

Type at command line -layer M etc and "LW" follow prompts same as color.

 

Edited by BIGAL
Posted

@BIGALthanks for your response. could you explain me about what you're talking about in a command line.

for example;

 

(DEFUN C:1 ()

 

(command "LAYER" "M" "____00-AF-10_CM_INTERIOR_WALL_LAYER " "LW" "0.50" "C" "231" "" ""))

)

 

Is it correct or not?

Posted

Try this line, missed a "" after the LW

 

(command "-LAYER" "M" "____00-AF-10_CM_INTERIOR_WALL_LAYER" "LW" "0.50" "" "C" "231" "" "")

 

Posted

It's working now, thank you again for your help, May Allah Bless and protect you from all bad consequences 🤲

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