IF CONDITION

IF CONDITION

muhamed_ragab92
Enthusiast Enthusiast
4,618 Views
26 Replies
Message 1 of 27

IF CONDITION

muhamed_ragab92
Enthusiast
Enthusiast

I WANT TO KNOW , HOW CAN I MAKE IF CONDITION TO COMPARE BETWEEN TWO ISSUES AND SELECT THE RESULT IN TEXT ? I KNOW SOME FEATURE FOR CTRL+F BUT I CANT MAKE IF CONDITION 

0 Likes
Accepted solutions (1)
4,619 Views
26 Replies
Replies (26)
Message 2 of 27

Kent1Cooper
Consultant
Consultant

@muhamed_ragab92 wrote:

I WANT TO KNOW , HOW CAN I MAKE IF CONDITION TO COMPARE BETWEEN TWO ISSUES AND SELECT THE RESULT IN TEXT ? I KNOW SOME FEATURE FOR CTRL+F BUT I CANT MAKE IF CONDITION 


I'm not sure exactly what you mean.  Ctrl+F toggles running Object Snap on or off, and has nothing to do with (if) tests or Text.  What does it mean to "select the result in text?"  The word "select" is usually about picking already-drawn objects in the drawing.  Do you mean to draw  some Text in the drawing as the result of the (if) test?

 

An (if) function doesn't "compare between two issues," but performs a test, and if it returns anything other than nil, does what is called for by its 'then' expression, or if it returns nil, its 'else' expression.  But the test it performs could include two test within it, with an (and) function -- if test 1 and  test 2 both  return something other than nil can be combined into one 'test' expression.  But it's still not really "comparing" the issues, but checking each one by itself.

 

Of, if you mean you want the User to select between two [or more] choices or options by entering text  [typing something] to make the choice, this is how that is usually done:

 

(initget "Yes No")

(setq option (getkword "\nDo you want to do this [Yes/No] <N>: "))

(if (= option "Yes")

  (... do whatever it is ...); 'then' expression

  (... do something else ...); 'else' expression

); end if

 

The User can either type in the Y or N [upper- or lower-case] or the whole words, or in newer versions pick the option inside the prompt, and (getkword) will return the whole word.

 

If you include more than two options, (cond) would be a better function than (if) for doing what is wanted for the option the User choses.

 

Some more explanation of what the conditions are that you want to compare, and how Text fits in, would be helpful.

Kent Cooper, AIA
Message 3 of 27

muhamed_ragab92
Enthusiast
Enthusiast

first i'd really to thank you for your answer and i record a video to explain what i want - and ctrl+f which means when use it at text for functions

here's the link of video

 

 

0 Likes
Message 4 of 27

Scottu2
Advocate
Advocate

Kent1cooper,

 

Based on the video, it looks like muhamed_ragab92 needs a lisp routine that

1. Selects a source object to determine the amp rating of the circuit breaker, then

2. Selects a target object to replace the existing text with a pre-determined Cable size on the incoming line side.

 

If 160A use Cable 3x95

if 250A use Cable 3x150

if 1000A use Cable 3x240

 

0 Likes
Message 5 of 27

muhamed_ragab92
Enthusiast
Enthusiast
Yes exactly thats what i need it and can i edit in it
0 Likes
Message 6 of 27

roland.r71
Collaborator
Collaborator

It looks to me as if he's trying to create a conditional field (hence: CTRL+F).

So, he should be looking into DIESEL expressions.

 

The next example shows a different name (or default text) based on the user logged on.

However, that's as far as my own understanding of DIESEL goes, so i can't say IF and/or how to do it for the given case.

 

%<\AcDiesel 
$(if,$(eq,$(getvar,loginname),"Jeff"),"jeff[at]cadstudio.cz",
$(if,$(eq,$(getvar,loginname),"John"),"john[at]cadstudio.cz",
$(if,$(eq,$(getvar,loginname),"Mary"),"mary[at]cadstudio.cz",
"cannot detect e-mail address")))
>%

source: http://www.cadforum.cz/cadforum_en/conditional-text-fields-in-autocad-tip10239

Perhaps using a lisp to set the text, without using fields and stuff might be better, but i'll leave that to the experts 😛

0 Likes
Message 7 of 27

Scottu2
Advocate
Advocate

roland.r71,

 

I thought it was something complex using the dialog boxes and fields, but i believe it was used to express the logic concept via coding.

 

0 Likes
Message 8 of 27

Scottu2
Advocate
Advocate

Mahumad.ragab92,

Try this routine...

; Cables - 4/23/2018
; Scott Uyehara
;
;This routine will ask for two entities, source and target:
;  Source Breaker Amps
;  Target Cable Text
;
; scan text for numbers and stop at first letter or end of text
; generate Cabletext result based on Amp value
; substitue old value for new, DXF 1 value
;
(defun c:cables (/ a ed text1 b edb old c1 ltr pren1 pren2 div1 cmdech)
;  global values: txta, textcables
;
;-- stop the UNDO command
(setq cmdech (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "undo" "group")
(command "undo" "end")
(setvar "cmdecho" cmdech)

  ;get source & target
  (setq a (entsel "Select Breaker Amps Text <or Enter>: "))
  (if (= a nil)
    (setq text1 (strcase (getstring "\nEnter Breaker AMPS or S=Spare: ")))
    (progn
      (setq ed (entget (car a)))
      (setq text1 (cdr (assoc 1 ed)))
      )
    );if = a nil

  (setq b (entsel "Select Cable text: "))
  (setq edb (entget (car b)))
  (setq old (assoc 1 edb))
  
  
;filter text string
;rebuild string text1 --> txta
  (setq c1 0)
  (setq txta "")
  (while (<= c1 (strlen text1))
    (setq c1  (+ c1 1))
    (setq ltr (substr text1 c1 1))
    (if (and (>= ltr "0") (<= ltr "9")) (setq txta (strcat txta ltr))); keep it when 0-9
    (if (> ltr "9") (setq c1 (+ 1 (strlen text1))))
  );while
  (prompt "\nAMPs: ")(princ txta)
  
  ;output No Match is nonthing matches
  (setq textcables "NO MATCH")
  (setq pren1 (chr 40))
  (setq pren2 (chr 41))
  (setq div1 (chr 47))
  (if (= txta "150") (setq textcables (strcat "CABLE" pren1 "3x95+50" pren2 "mm2,CU" div1 "XLEP" div1 "PVC")))
  (if (= txta "250") (setq textcables (strcat "CABLE" pren1 "3x150+70" pren2)))
  (if (= txta "630") (setq textcables (strcat "CABLE" pren1 "3x240+120" pren2)))
  (if (= txta "1000") (setq textcables (strcat "CABLE" pren1 "3x240+120" pren2)))
  (if (= txta "S") (setq textcables "SPARE"))
  
  (setq new (cons 1 textcables))
  (setq edb (subst new old edb))
  (entmod edb)
(prompt "\nUse Cables: ")
(prompt textcables)
(princ) 
); defun
0 Likes
Message 9 of 27

muhamed_ragab92
Enthusiast
Enthusiast

its worked but in text only when c.b amp is text not attribute , can we add attribute to the script ?? and i will record video for what done with this routine

0 Likes
Message 10 of 27

muhamed_ragab92
Enthusiast
Enthusiast
Reminder for issue


Sent from my iPhone
0 Likes
Message 11 of 27

Scottu2
Advocate
Advocate

muhamed_ragab92,

Thanks for the reminder.

I tested the code and noticed that the Spare option was not working.

Change the variable txta to text1, (if (= txta "S") (setq textcables "SPARE"))

 

I will adjust the code for attribute detection.

Scott U.

 

0 Likes
Message 12 of 27

muhamed_ragab92
Enthusiast
Enthusiast
Okay thanks


Sent from my iPhone
0 Likes
Message 13 of 27

Scottu2
Advocate
Advocate

muhamed_ragab92,

Try this routine with attribute detection.

Its not tested (due to computer problems), but lets see how it goes.

0 Likes
Message 14 of 27

muhamed_ragab92
Enthusiast
Enthusiast

thanks you , i tried this routine today but the result when select amp c.b 250a or any others is no match at cable 

0 Likes
Message 15 of 27

Scottu2
Advocate
Advocate

muhamed_ragab92,

I made corrections.  See attached files.

 

Also, change the attribute tag names to match your drawing.

Source block with attribute tag "amps"

Target block with attribute tag "linecables"

 

;predefine tag name
(setq tagname "amps")
(setq tagnameB "linecables")

 

Scott

0 Likes
Message 16 of 27

muhamed_ragab92
Enthusiast
Enthusiast

its worked but i modify in the routine in 250A , 630A and 1000A because type of isolation appeared only 150A - and modify tagname to AT to suitable with me , can we add the feature to the lisp which i can select many several of breakers and after that select the texts i know its more advanced in the routine but can we add it? - attached file is screenshot from the result and the modified lisp - thanks  

0 Likes
Message 17 of 27

Scottu2
Advocate
Advocate

muhamed_ragab92,

 

Good,  modified it to work for the other amp values.

 

I see that tagnameB (used for cabletext) was not changed. 

Is that because it is always pain text?

 

As for the advanced feature to select a group of AT breakers and the matting cable text,

Please post a sample drawing.  I may have more questions.

 

0 Likes
Message 18 of 27

muhamed_ragab92
Enthusiast
Enthusiast

yes ,  it is always pain text for me - it's not find on anywhere - i ask if we can add it to select by mouse many of breakers at once and and select after that the pain texts once - convert directly all texts to which write the routine  

0 Likes
Message 19 of 27

Scottu2
Advocate
Advocate

muhamed_ragab92,

Ok.  Thanks great.  Its a little more involved.  I plan to rewrite the code.

 

0 Likes
Message 20 of 27

muhamed_ragab92
Enthusiast
Enthusiast
Thanks , i appreciate that


Sent from my iPhone
0 Likes