Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

simple if or condition code

19 REPLIES 19
SOLVED
Reply
Message 1 of 20
E.S.7.9
1024 Views, 19 Replies

simple if or condition code

hi ,

 

i have an attribute blocks and this att block has two tag values , is there a simple code for tochange 1st tag values automaticly according to  2nd values ?

 

for example :

 

1st tag (50x50) - 2nd tag ( 100 )    ==> 50x50-100

 

if i enter 201 valuse to 2nd tag then 1 st tag has to change as 100x100

if i enter 501 valuse to 2nd tag then 1 st tag has to change as 150x510

 

 

i attached a jpg file for explain much better

 

thank you

19 REPLIES 19
Message 2 of 20
pbejse
in reply to: E.S.7.9


@E.S.7.9 wrote:

hi ,

 

i have an attribute blocks and this att block has two tag values , is there a simple code for tochange 1st tag values automaticly according to  2nd values ?

 

for example :

 

1st tag (50x50) - 2nd tag ( 100 )    ==> 50x50-100

 

if i enter 201 valuse to 2nd tag then 1 st tag has to change as 100x100

if i enter 501 valuse to 2nd tag then 1 st tag has to change as 150x510

 

 

i attached a jpg file for explain much better

 

thank you


It's easy really, it would be nice if you paste the actual block

 

Message 3 of 20
BlackBox_
in reply to: E.S.7.9

You could implement a small contingent of Visual LISP Reactors, such that when the ObjectModified event is raised for an AcDbAttributeReference with the primary (trigger) tag string, your code stores that Object's OwnerId (the parent AcDbBlockReference), and its current value... Then when either the CommandCancelled, CommandEnded, or CommandFailed event is raised for EATTEDIT modify the secondary AcDbAttributeReference by digging down from the the previously stored OwnerId (the parent AcDbBlockReference).

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 4 of 20
alanjt_
in reply to: BlackBox_

I wonder if you can put object fields within a diesel expression field.

Message 5 of 20
alanjt_
in reply to: alanjt_

(defun c:test (/ ss i atts val new1)
  (if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1) (2 . "BlockName"))))
    (repeat (setq i (sslength ss))
      (setq atts (vlax-invoke (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'GetAttributes)
            val  (atoi (vla-get-textstring (cadr atts)))
      )
      (if (setq new1 (cond ((<= 0. val 200.) "50x50")
                           ((<= 201. val 500.) "100x100")
                           ((<= 501. val 750.) "150x150")
                     )
          )
        (vla-put-textstring (car atts) new1)
      )
    )
  )
  (princ)
)
(vl-load-com)
(princ)

 Block name in filter is up to you to change.

Message 6 of 20
E.S.7.9
in reply to: pbejse

i atached a file about att blocks... if you can write me example codes , it would be nice too ..

 

😃 thank you

Message 7 of 20
E.S.7.9
in reply to: alanjt_

ank you alanjt

 

it`s perfect

Message 8 of 20
pbejse
in reply to: E.S.7.9


@E.S.7.9 wrote:

i atached a file about att blocks... if you can write me example codes , it would be nice too ..

 

😃 thank you


Well, I guess dont need to write one now, Alanjt got it covered.

 

FWIW: This code will prompt you for new SIZE  then updates the FLOW value , As Alanjt's code is for existing values.

and this code is TAG dependent. 

 

(defun c:sample ( / _AttFunc new1 attval NewVal)
(defun _AttFunc	(en lst / vals v)
	(mapcar (function
	    (lambda (at)
	      (setq vals (list (vla-get-tagstring at) (vla-get-textstring at)))
	      (if (and lst (setq v (assoc (car vals) lst)))
		(vla-put-textstring at (cadr v))
	      )
	      vals
	    )
	  )
	  (vlax-invoke
	    (if	(eq (type en) 'VLA-OBJECT)
	      en
	      (vlax-ename->vla-object en)
	    )
	    'Getattributes
	  )
	)
	)  
   (if (and 
       (setq new1 nil ss (ssget "_:S:L" '((0 . "INSERT") (66 . 1))))
       (setq Attval (_AttFunc (setq e (ssname ss 0)) nil))
       (vl-every '(lambda (x) (assoc x Attval))
		 '("FLOW" "SIZE"))
       )
     (progn
       (while (null new1)
	 (initget 7)
          (setq NewVal (getint "\nEnter Size value: "))
          (if (<= 0 NewVal 750)
;;; Snip from Alanjt ;;; (setq new1 (cond ((<= 0. NewVal 200.) "50x50") ((<= 201. NewVal 500.) "100x100") ((<= 501. NewVal 750.) "150x150") )
;;; )(princ "\n<<Value out of range>>") )) (_attfunc e (list (list "FLOW" new1)(list "SIZE" (itoa NewVal)))) ) ) (princ) )

 

 HTH

Message 9 of 20
alanjt_
in reply to: pbejse

Cool. I wasn't thinking about prompting the user to update the value, then it would automatically do the updating for the other attribute. Nice thinking. 🙂

Way to give them what they want and need.

Message 10 of 20
pbejse
in reply to: alanjt_


@alanjt_ wrote:

Cool. I wasn't thinking about prompting the user to update the value, then it would automatically do the updating for the other attribute. Nice thinking. 🙂

Way to give them what they want and need.


Thanks Alanjt, in fairness to you never had the chance to see the attachment before you posted your suggested code but still turns out perfect for attributes already edited by the user.

 

Kudos to you Alanjt

 

cheers

Message 11 of 20
3wood
in reply to: E.S.7.9

For ALTEXT users, please use the formula below:

Please note, 2 attribures in the dxf attachment in author's post are swapped position. You need change Altext_att_2 to Altext_att_1 and make chages to attribute No. 2 in that case. 

;;; This is an example formula for ALTEXT.vlx
(defun ALTEXT_FORMULA (/ nb1)
  (if Altext_att_2
    (progn
      (setq nb1 (atof Altext_att_2))
      (cond
        ((<= nb1 200) "50x50")
        ((<= nb1 500) "100x100")
        ((<= nb1 750) "150x150")
        (T nil)
       )
      )
    )
  )

 

Message 12 of 20
E.S.7.9
in reply to: pbejse

pbejse & alanjt  -- thank you guys for your help

Message 13 of 20
E.S.7.9
in reply to: E.S.7.9

hi pbejse

 

i have a  question with this lisp , i wanted to create my list after your cod

 

i putted my values on this lisp ... but it gave me "Requires an integer between 1 and 32767" error ...

 

is that mean i cannot enter values bigger then 32767 ?

 

do you know how can i put bigger values?

 

thank you again

Message 14 of 20
E.S.7.9
in reply to: pbejse

hi pbejse

 

i have a  question with this lisp , i wanted to create my list after your cod

 

i putted my values on this lisp ... but it gave me "Requires an integer between 1 and 32767" error for "enter size value :"

 

when i wanted to use it

 

is that mean i cannot enter values bigger then 32767 ?

 

do you know how can i put bigger values?

 

thank you again

Message 15 of 20
Kent1Cooper
in reply to: E.S.7.9


@E.S.7.9 wrote:
.... 

i putted my values on this lisp ... but it gave me "Requires an integer between 1 and 32767" error ...

....

do you know how can i put bigger values?

....


Try changing this line:

(setq NewVal (getint "\nEnter Size value: "))

to this instead:

(setq NewVal (getreal "\nEnter Size value: "))

 

Some of the category comparisons in suggested routines are using real numbers rather than integers, anyway.

Kent Cooper, AIA
Message 16 of 20
E.S.7.9
in reply to: Kent1Cooper

i tried " getreal " but it has not been succesfully ... or i couldnt made it ...

 

can you write me the lisp code code which is corected by you ?

 

thank you

Message 17 of 20
Kent1Cooper
in reply to: E.S.7.9


@E.S.7.9 wrote:

i tried " getreal " but it has not been succesfully ... or i couldnt made it ...

 

can you write me the lisp code code which is corected by you ?

....


In what way is it not working?  Are you getting the same message about the size of the number?  Is there some other error message?  Is something happening that you don't expect?  Are some things happening but not everything you expect?  Is nothing happening?  Etc....

Kent Cooper, AIA
Message 18 of 20
E.S.7.9
in reply to: Kent1Cooper

it`s giving this error ;

 

Enter Size value: 50000
; error: bad argument type: fixnump: 50000.0

Message 19 of 20
Kent1Cooper
in reply to: E.S.7.9


@E.S.7.9 wrote:

it`s giving this error ;

 

Enter Size value: 50000
; error: bad argument type: fixnump: 50000.0


I had looked at the comparisons it was making in setting the 'new1' variable, but hadn't looked further down at how it was using NewVal again.  The (itoa) function doesn't like real numbers.  Try changing this:

 

       (list "FLOW" new1)(list "SIZE" (itoa NewVal))))

 

to either this, to give (itoa) the kind of argument it wants:

 

       (list "FLOW" new1)(list "SIZE" (itoa (fix NewVal)))))

 

or this, to use a function that can handle a real number, but resulting in no decimal places:

 

       (list "FLOW" new1)(list "SIZE" (rtos NewVal 2 0))))

 

The difference between them won't make any difference if you only enter whole numbers.  But if you were to enter, say, 45678.9, the first one would return "45678" [just lopping off any decimal portion], and the second would return "45679" [rounding].

Kent Cooper, AIA
Message 20 of 20
alanjt_
in reply to: E.S.7.9

For 50,000, this will be fine, but when you get into really large integers, the return isn't going to be what you want. Just part of autocad's limitations.

 

(defun _getint (message / n f)
  (if (setq n (getreal message))
    (if (eq n (setq f (fix n)))
      f
      (progn (princ "\nRequires an integer value.") nil)
    )
  )
)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost