Lisp needed

Lisp needed

Anonymous
Not applicable
1,010 Views
7 Replies
Message 1 of 8

Lisp needed

Anonymous
Not applicable

in this program is 3 mistake please help me to find them 

 

Thanks!!

 

 

; the program selects the circles and changes their radius by half
(defun C:radius(/ OR_OPEN OR_CLOSE filter ss tent telem tcontent
telemupper n)
; retrieve the selection set containing both
; single and multiline text objects
(setq filter (list '(0 . "CIRCLE") )
ss (ssget "X" filter)
)
; iterate over the selection set
(setq n 0)
(repeat (ssname ss)
(setq tent (entget (sslength ss n)))
(print tent)
(setq telem (assoc 40 tent))
(print telem)
(setq tcontent (cdr telem))
(print tcontent)
(setq razan (/ tcontent 2))
(print razan)
(setq telemupper (cons 10 razan))
(print telemupper)
(setq tent (subst telemupper telem tent))
(print tent);
(entmod tent)
(setq n (1+ n))
)
(princ)
)

0 Likes
Accepted solutions (1)
1,011 Views
7 Replies
Replies (7)
Message 2 of 8

cadffm
Consultant
Consultant
your posting sounds like an exercise or test, are you not sure you're going to find the mistakes? How do you know that there are three?

It sounds curios for me?

Sebastian

Message 3 of 8

Anonymous
Not applicable

yeah is exercise 

it's something with  bad SSGET list value 

 

0 Likes
Message 4 of 8

doaiena
Collaborator
Collaborator

What is the object of this exercise? You want a program, that will reduce all selected circles' radius in half, or you want someone to check out the code you have posted, or you want to learn about how SSGET works? Or you need an entirely different function? Please be more exact with your question, in order to get the best advice possible.

0 Likes
Message 5 of 8

dlanorh
Advisor
Advisor
Accepted solution
(defun C:radius(/ OR_OPEN OR_CLOSE filter ss tent telem tcontent telemupper n)
; retrieve the selection set containing both
; single and multiline text objects
  (setq ss (ssget "X"  '((0 . "CIRCLE"))));<< minor error here, you don't need a filter variable overcomplicated

; iterate over the selection set
  (setq n 0)
  (repeat (sslength ss); was ssname should be sslength
    (setq tent (entget (ssname ss n))); was sslength should be ssname
    (print tent);entity list
    (setq telem (assoc 40 tent))
    (print telem);circle radius assoc
    (setq tcontent (cdr telem))
    (print tcontent);circle radius value
    (setq razan (/ tcontent 2))
    (print razan);half circle radius value
    (setq telemupper (cons 40 razan));No!!! razan is half the radius, (assoc 10) is the centre of the circle.
    (print telemupper)
    (setq tent (subst telemupper telem tent)); why complicate it with extra lines and variables? (setq tent (subst (cons 40 razan) (assoc 40 tent) tent))
    (print tent);
    (entmod tent)
    (setq n (1+ n))
  )
  (princ)
)
;;(repeat (sslength ss)
;;    (setq tent (entget (setq ent (ssname ss n)))
;;          razan (/ (cdr (assoc 40 tent)) 2)
;;          tent (subst (cons 40 razan) (assoc 40 tent) tent)
;;          n (1+ n)
;;    )
;;    (entmod tent)
;;    (entupd ent) ;update entity on screen  
;;)

See above, my 2 cents worth is commented out below

I am not one of the robots you're looking for

0 Likes
Message 6 of 8

doaiena
Collaborator
Collaborator

I would go for this. It seems more compact and easier to read for me.

(repeat (sslength ss)
(setpropertyvalue (ssname ss ctr) "radius" (/ (getpropertyvalue (ssname ss ctr) "radius") 2))
(setq ctr (1+ ctr))
)
Message 7 of 8

dlanorh
Advisor
Advisor

@doaienawrote:

I would go for this. It seems more compact and easier to read for me.

(repeat (sslength ss)
(setpropertyvalue (ssname ss ctr) "radius" (/ (getpropertyvalue (ssname ss ctr) "radius") 2))
(setq ctr (1+ ctr))
)

100% in agreement. Vanilla does my head in nowadays

for me it would be

(ssget "X" '((0 . "CIRCLE")))
(vlax-for obj (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
  (vla-put-radius obj (/ (vla-get-radius obj) 2))
)
(setq ss nil)

I am not one of the robots you're looking for

Message 8 of 8

doaiena
Collaborator
Collaborator

If i have already set somewhere in the lisp: (setq acaddoc (vla-get-activedocument (vlax-get-acad-object)))
Your vl solution is the way to go. Using visual lisp functions in a one-off case /without setting a few variables/, makes them a bit too long and hard to read in some cases.

0 Likes