Can't change color of object

Can't change color of object

Anonymous
Not applicable
1,213 Views
8 Replies
Message 1 of 9

Can't change color of object

Anonymous
Not applicable

I try to change the color of circle but it looks like the if statement never reaches

I tried with different values for minim and maxim,same result..

 

(setq radiusN (cdr (assoc 40 edata))) ; radius

(setq avgN (/ (- maxim minim) 2))
(cond
((<= radiusN avgN )
(princ "here! 1")
(command "_.ChProp" edata "" "_C" 7 "")
)
( (> radiusN avgN)
(princ "here! 2")
(command "_.ChProp" edata "" "_C" 2 "")


)

)

 

Is there any way to rewrite the loop?

0 Likes
Accepted solutions (1)
1,214 Views
8 Replies
Replies (8)
Message 2 of 9

j.palmeL29YX
Mentor
Mentor

@Anonymousschrieb:

(command "_.ChProp" edata "" "_C" 7 "")



(command ...) doesn't understand edata as element to modify.

Try instead of edata this: (cdr (assoc -1 edata))

 

Code snip:

(command "_.ChProp" (cdr (assoc -1 edata)) "" "_C" 7 "")

 

HTH

cadder

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 3 of 9

Anonymous
Not applicable

I get the same results ,I think the problem is setting avgN and radiusN

 

(setq avgN (/ (+ maxim minim) 2))

(setq radiusN (cdr (assoc 40 edata)))

because (>= radiusN avgN )  never returns true.

0 Likes
Message 4 of 9

j.palmeL29YX
Mentor
Mentor

@Anonymousschrieb:

because (>= radiusN avgN )  never returns true.


We need more of your code. Where are maxim and minim and edata coming from?

Did you check the value of this variables?

 

Maybe this will do what you want:


(defun c:test ()
  (setq edata (entget (car (entsel "}nPick circle: "))))
  (setq    maxim 50
    minim 20
  )

  (setq radiusN (cdr (assoc 40 edata)))    ; radius
  (setq avgN (/ (- maxim minim) 2.))  ; avgN must be a real number, therefore 2.0
  (cond
    ((<= radiusN avgN)
     (princ "here! 1")
     (command "_.ChProp" (cdr (assoc -1 edata)) "" "_C" 7 "")
    )
    ((> radiusN avgN)
     (princ "here! 2")
     (command "_.ChProp" (cdr (assoc -1 edata)) "" "_C" 2 "")
    )
  )
)

 

cadder

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 5 of 9

Anonymous
Not applicable

They are inputs 

(setq minim (getint "Minimum radius:\n"))
(setq maxim (getint "Maximum radius:\n"))

 

0 Likes
Message 6 of 9

Anonymous
Not applicable

Your code looks like it works but mine still doesn't work.

Here is the full code

(defun C:circleChanger ( / objectsset center edata eid etype translategroup minim maxim ang colorN)

; ask the user to select a set of objects
(setq objectsset (ssget))

(initget 1)
(setq center (getpoint "Center of the action :\n"))
;(initget 1)
(setq minim (getint "Minimum radius:\n"))
(setq maxim (getint "Maximum radius:\n"))

;(command "_.ChProp" objectsset "" "_C" 3 "")


; iterate over the selection set
(setq slen (sslength objectsset)
ix 0)
(setq avgN (/ (+ maxim minim) 2.))
(while (< ix slen)
(setq edata (entget (ssname objectsset ix))
eid (cdr (assoc -1 edata))
etype (cdr (assoc 0 edata))
)

(if (/= etype "CIRCLE") ; not a circle
(progn
(princ "Warning! [")
(princ eid)
(princ "] was not a [CIRCLE], but a [")
(princ etype)
(princ "]; skipped.\n")

) ; then - progn
(progn
(setq translategroup (assoc 10 edata)
edata (subst (cons 10 center) translategroup edata)
)

;(command "_.ChProp" ss "" "_C" usercol "")
;(setvar "hpscale" (cdr (assoc 41 edata))); SCALE
; (setvar "hpang" (cdr (assoc 52 edata))); ANGLE
(setq radiusN (cdr (assoc 40 edata))) ; radius
; (setq radius (cdr (assoc 39 Ent))


(cond
((<= radiusN avgN)
(princ "here! 1")
(command "_.ChProp" (cdr (assoc -1 edata)) "" "_C" 1 "")
)
((> radiusN avgN)
(princ "here! 2")
(command "_.ChProp" (cdr (assoc -1 edata)) "" "_C" 2 "")
)
)

; (princ radiusN)
; (princ avgN)

(setq ang 0)
(repeat 6
(command "PLINE"
(polar center ang (/ radiusN 2 (cos (/ pi 6))))
(polar center (+ ang (/ pi 6)) radiusN)
(polar center (+ ang (/ pi 3)) (/ radiusN 2 (cos (/ pi 6))))
""
)
(setq ang (+ ang (/ pi 3)))
)

 

(entmod edata)
)
)
(setq ix (1+ ix))
) ; while

(princ) ; don't return anything
)

0 Likes
Message 7 of 9

j.palmeL29YX
Mentor
Mentor

I did not yet check your code in detail. At first I did run it and got the attached result.

Isn't it what you want?

https://autode.sk/2HSMUDq

 

If this is not the expected, tell us what you want to get.

 

cadder

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 8 of 9

Anonymous
Not applicable

That is what I want but my code also creates stars in each circle,the stars work but the color don't .

0 Likes
Message 9 of 9

j.palmeL29YX
Mentor
Mentor
Accepted solution

I added some lines (italic) in the repeat loop. 

And substituted the (command "pline" ...)  with (command "_pline" ...) . Becauso of this lapsus the stars were not drawn in my german AutoCad.

 

   ...

    (repeat    6
      (command
        "_PLINE"
        (polar center ang (/ radiusN 2 (cos (/ pi 6))))
        (polar center (+ ang (/ pi 6)) radiusN)
        (polar center (+ ang (/ pi 3)) (/ radiusN 2 (cos (/ pi 6))))
        ""
      )

      (cond
        ((<= radiusN avgN)
                    ;(princ "here! 1")
         (command "_.ChProp" "l" "" "_C" 1 "")
        )
        ((> radiusN avgN)
                    ;(princ "here! 2")
         (command "_.ChProp" "l" "" "_C" 2 "")
        )
      )
      (setq ang (+ ang (/ pi 3)))
    )
    (entmod edata)
      )
    )
    (setq ix (1+ ix))
  )                    ; while
  (princ)                ; don't return anything
)

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature