Jump to content

what's wrong in my code ((syntax error)).any ideas?


Recommended Posts

Posted (edited)

T = [((sqrtA) + 1)^ 2) - A] * [ L/( 4*(sqrtA)]

A= Area of a polyline

L= Perimetr of a polyline

T= tolerance

 

I try to print the area and the perimetr but i have (syntax error) with

the print of T and the (10% * Area)

 

The (10% * Area) is safety factor that why is important because

 

if (10% * Area) > T the the tolerance is the T

and

if (10% * Area)

-------------------------------------------------------------

(defun c:ktim ( / a l i s )
   (if (setq s
           (ssget
              '(   (0 . "CIRCLE,ELLIPSE,*POLYLINE,SPLINE")
                   (-4 . "<NOT")
                       (-4 . "<AND")
                           (0 . "POLYLINE") (-4 . "&") (70 . 80)
                       (-4 . "AND>")
                   (-4 . "NOT>")
               )
           )
       )
       (progn
           (setq a 0.0)
           (repeat (setq i (sslength s))
               (setq a (+ a (vlax-curve-getarea (ssname s (setq i (1- i))))))
           )


      (progn
           (setq l 0.0)
           (repeat (setq i (sslength s))
               (setq e (ssname s (setq i (1- i)))
                     l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
               )
           )
           (princ "\nTotal Length: ")
           (princ (rtos l 2 2))
       )

       (princ "\nTotal Area: ")
           (princ (rtos a 2 2))
)
(princ "\n Tolerance: ")
           (princ (rtos (/ (* (- (* (+ (sqrt a) 1) (+ (sqrt a) 1) ) a) l) (* (sqrt a) 4) 2 2))
)
(princ "\n 10 % Area : ")
           (princ (rtos (* a 0.1) 2 2))
)

   )
   (princ)
)
(vl-load-com) (princ)

Edited by SLW210
Add Code Tags!!
  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

  • BlackBox

    10

  • marko_ribar

    2

  • ReMark

    1

  • lyky

    1

Top Posters In This Topic

Posted

Syntax errors in lisp programs are often a result of incorrect placement or number of parentheses. Have you checked your code for such a likelihood?

Posted (edited)

(defun c:ktim ( / a l i s e )
 (if (setq s
       (ssget
        '( (0 . "CIRCLE,ELLIPSE,*POLYLINE,SPLINE")
           (-4 . "<NOT")
           (-4 . "<AND")
           (0 . "POLYLINE") (-4 . "&") (70 . [highlight]8[/highlight])
           (-4 . "AND>")
           (-4 . "NOT>")
         )
       )
     )
     (progn
       (setq a 0.0)
       (repeat (setq i (sslength s))
         (setq a (+ a (vlax-curve-getarea (ssname s (setq i (1- i))))))
       )
       (setq l 0.0)
       (repeat (setq i (sslength s))
         (setq e (ssname s (setq i (1- i)))
               l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
         )
       )
     )
 )
 
 (princ "\nTotal Length: ")
 (princ (rtos l 2 2))

 (princ "\nTotal Area: ")
 (princ (rtos a 2 2))

 (princ "\nTolerance: ")
 (princ (rtos (/ (* (- (* (+ (sqrt a) 1) (+ (sqrt a) 1) ) a) l) (* (sqrt a) 4)[highlight])[/highlight] 2 2))

 (princ "\n10 % Area : ")
 (princ (rtos (* a 0.1) 2 2))

 (princ)
)

(vl-load-com) (princ)

You missed ) - see highlighted... And also you had extra ) after (princ...)

You also had invalid DXF 70 for 3dpolyline - it should be (70 . 8)

Edited by marko_ribar
You also had invalid DXF 70 for 3dpolyline - it should be (70 . 8)
Posted

I *think* this is what you're after:

(defun c:ktim (/ a l i s)
 (if (setq s
            (ssget
              '((0 . "CIRCLE,ELLIPSE,*POLYLINE,SPLINE")
                (-4 . "<NOT")
                (-4 . "<AND")
                (0 . "POLYLINE")
                (-4 . "&")
                (70 . 80)
                (-4 . "AND>")
                (-4 . "NOT>")
               )
            )
     )
   (progn
     (setq a 0.0)
     (repeat (setq i (sslength s))
       (setq a (+ a (vlax-curve-getarea (ssname s (setq i (1- i))))))
     )

;;;      (progn
     (setq l 0.0)
     (repeat (setq i (sslength s))
       (setq e (ssname s (setq i (1- i)))
             l (+ l
                  (vlax-curve-getdistatparam e (vlax-curve-getendparam e))
               )
       )
     )
     (princ "\nTotal Length: ")
     (princ (rtos l 2 2))
;;;      )

     (princ "\nTotal Area: ")
     (princ (rtos a 2 2))
;;;    )
     (princ "\n Tolerance: ")
     (princ
       (rtos (/ (* (- (* (+ (sqrt a) 1) (+ (sqrt a) 1)) a) l)
                (* (sqrt a) 4)
                2
                2
             )
       )
     )
     (princ "\n 10 % Area : ")
     (princ (rtos (* a 0.1) 2 2))
   )

 )
 (princ)
)
(vl-load-com)
(princ)

 

:unsure: *not sure*

Posted

You missed ) - see highlighted... And also you had extra ) after (princ...)

 

... Kind of hard to evaluate all of those PRINC calls, if the PROGN call never happens (due to s = Nil). :thumbsup:

Posted (edited)

Has revised, here you go:

(defun c:ktim ( / A E I L S)
(vl-load-com)
(setq s
           (ssget
              '(   (0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE") 
                   (-4 . "<NOT")
                       (-4 . "<AND")
                           (0 . "POLYLINE") (-4 . "&") (70 . 80)
                       (-4 . "AND>")
                   (-4 . "NOT>")
               )
           )
       )
(if (/= s nil)
(progn (setq l 0.0 a 0.0 i 0)
(while (< i (sslength s)) (progn
               (setq e (ssname s i)
                     l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
                     a (+ a (vlax-curve-getarea e)))) (setq i (1+ i)))

           (princ "\nTotal Length: ")
           (princ (rtos l 2))
 
           (princ "\nTotal Area: ")
           (princ (rtos a 2))

           (princ "\n Tolerance: ")
           (princ (rtos (/ (* (- (* (+ (sqrt a) 1) (+ (sqrt a) 1) ) a) l) (* (sqrt a) 4) 2 2)))
 
           (princ "\n 10 % Area : ")
           (princ (rtos (* a 0.1) 2 2))
       )) (princ))

Edited by lyky
Posted (edited)

i neeed something more if it is posible

 

if the scale 1: 1000 we have this T = [((sqrtA) + 1)^ 2) - A] * [ L/( 4*(sqrtA)]

if the scale 1: 5000 we have this T = [((sqrtA) + 4)^ 2) - A] * [ L/( 4*(sqrtA)]

and for the two cases we have

 

if (10% * Area) > T the the tolerance is the T

and

if (10% * Area)

Edited by prodromosm
Posted

nice job but the calculation is wrong, any ideas ????????????

Posted (edited)

Really stabbing in the dark here (not sure I understand fully what you're trying to do), but building on my earlier code revision, give this a try:

 

(defun c:ktim (/ cannoscale tval a l i s)
 (if (and
       (setq tval (cond ((= "1\" = 10000'"
                            (setq cannoscale (getvar 'cannoscale))
                         )
                         2
                        )
                        ((= "1\" = 50000'" cannoscale)
                         4
                        )
                  )
       )
       (setq s
              (ssget
                '((0 . "CIRCLE,ELLIPSE,*POLYLINE,SPLINE")
                  (-4 . "<NOT")
                  (-4 . "<AND")
                  (0 . "POLYLINE")
                  (-4 . "&")
                  (70 . 80)
                  (-4 . "AND>")
                  (-4 . "NOT>")
                 )
              )
       )
     )
   (progn
     (setq a 0.0)
     (repeat (setq i (sslength s))
       (setq a (+ a (vlax-curve-getarea (ssname s (setq i (1- i))))))
     )

;;;      (progn
     (setq l 0.0)
     (repeat (setq i (sslength s))
       (setq e (ssname s (setq i (1- i)))
             l (+ l
                  (vlax-curve-getdistatparam e (vlax-curve-getendparam e))
               )
       )
     )
     (princ "\nTotal Length: ")
     (princ (rtos l 2 2))
;;;      )

     (princ "\nTotal Area: ")
     (princ (rtos a 2 2))
;;;    )

     ;;if the scale 1: 1000 we have this T = [((sqrtA) + 1)^ 2) - A] * [ L/( 4*(sqrtA)]
     ;;if the scale 1: 5000 we have this T = [((sqrtA) + 1)^ 4) - A] * [ L/( 4*(sqrtA)]
     (princ "\n Tolerance: ")
     (princ
       (rtos
         (* (- (* (+ 1 (sqrt a)) tval) a) (/ l (* (sqrt a) 4)))
         2
         2
       )
;;;        (rtos (/ (* (- (* (+ (sqrt a) 1) (+ (sqrt a) 1)) a) l)
;;;                 (* (sqrt a) 4)
;;;                 2
;;;                 2
;;;              )
;;;        )
     )
     (princ "\n 10 % Area : ")
     (princ (rtos (* a 0.1) 2 2))
   )
   (cond (tval (prompt "\n** invalid selection ** "))
         ((prompt "\n** Scale must be \"1:1000\" or \"1:5000\" ** "))
   )
 )
 (princ)
)

 

** Note - This code assumes that your drawing's annotation scale is equal to the desired scale of either 1:1000, or 1:5000.

Edited by BlackBox
Posted

OP changed formulas at 05:14 pm... But I think that now can finish the code right...

 

Cheers, Black Box...

Posted

Cheers, Black Box...

 

Cheers, Marko :beer:

Posted

Command: (LOAD "C:/Users/Prodromos/Desktop/ktimtel.lsp") C:KTIM

Command: ktim

** Scale must be "1:1000" or "1:5000"

Command:

 

!!!!!!!!!!!!!!!!!!!!!!!!!!

Posted (edited)

a) if the scale 1: 1000 we have this T = [((sqrtA) + 1)^ 2) - A] * [ L/( 4*(sqrtA)]

b) if the scale 1: 5000 we have this T = [((sqrtA) + 4)^ 2) - A] * [ L/( 4*(sqrtA)]

 

something is wrong here because

for A=266.50sqm and L=66.18 m calculate a) T=8.526 and the correct is T = 34.10

b) T=37.144 and the correct is T = 148.58

here is the code

--------------------------------

(defun c:ktim (/ a l i s)
 (if (setq s
            (ssget
              '((0 . "CIRCLE,ELLIPSE,*POLYLINE,SPLINE")
                (-4 . "<NOT")
                (-4 . "<AND")
                (0 . "POLYLINE")
                (-4 . "&")
                (70 . 80)
                (-4 . "AND>")
                (-4 . "NOT>")
               )
            )
     )
   (progn
     (setq a 0.0)
     (repeat (setq i (sslength s))
       (setq a (+ a (vlax-curve-getarea (ssname s (setq i (1- i))))))
     )

;;;      (progn
     (setq l 0.0)
     (repeat (setq i (sslength s))
       (setq e (ssname s (setq i (1- i)))
             l (+ l
                  (vlax-curve-getdistatparam e (vlax-curve-getendparam e))
               )
       )
     )
(textscr)
     (princ "\nTotal Length: ")
     (princ (rtos l 2 2))
;;;      )

     (princ "\nTotal Area: ")
     (princ (rtos a 2 2))
;;;    )
     (princ "\n Tolerance 1:1000: ")
     (princ
       (rtos (/ (* (- (* (+ (sqrt a) 1) (+ (sqrt a) 1)) a) l)
                (* (sqrt a) 4)
                2
                2
             )
       )
     )
(princ "\n Tolerance 1:5000: ")
     (princ
       (rtos (/ (* (- (* (+ (sqrt a) 4) (+ (sqrt a) 4)) a) l)
                (* (sqrt a) 4)
                2
                2
             )
       )
     )
     (princ "\n 10 % Area : ")
     (princ (rtos (* a 0.1) 2 2))
   )

 )
 (princ)
)
(vl-load-com)
(princ)

Edited by SLW210
Add Code Tags!!
Posted
Command: (LOAD "C:/Users/Prodromos/Desktop/ktimtel.lsp") C:KTIM

Command: ktim

** Scale must be "1:1000" or "1:5000 ** "

Command:

 

!!!!!!!!!!!!!!!!!!!!!!!!!!

 

How are you determining your scale (1:1000 vs. 1:5000)?

 

As I mentioned at the bottom of this post, I could only speculate that you were using Annotative Scale... Perhaps you're using DimScale?

 

In any event, without knowing which scale to check for the two specific values you requested, there's no way to ensure that the calculation is accurate.

 

more information is needed, so that we're not confused.

Posted

Select objects:

 

Total Length: 66.18

Total Area: 266.50

Tolerance 1:1000: 8.526

Tolerance 1:5000: 37.144

10 % Area : 26.65

 

Command:

Posted

Please fix your post(s) to use

 :thumbsup:
Posted

Ohhhhh! You want to see BOTH tolerances. :beer:

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