Using variables with logic operators

Using variables with logic operators

Anonymous
Not applicable
1,764 Views
14 Replies
Message 1 of 15

Using variables with logic operators

Anonymous
Not applicable

I have a situation where i am using a dcl file to delete tabs from a template drawing that is copied into the project directory & renamed. The user will select from a box whether or not the drawing will have an architectural demolition roof plan or a demolition ceiling plan. If those selection are not made the routine will delete those tabs. The prolem i am running into is if one of the selections is made & the other one is not. Here is a sample of my code.

 

(if (and (demoroof)(not demorcp))
(PROGN
(command "layout" "d" "DM-102.00")
(command "layout" "R" "DM-103.00" "DM-102.00")
);END PROGN demoroof not demorcp
)

 

when i was degugging it in the ide it was telling me

that

 

 ; warning: local variable used as function: DEMOROOF
; error: too few arguments: (IF (AND ( ... ) ( ... )))

 

so i changed it to this:

 

(if (and (= demoroof)(= not demorcp))
(PROGN
(command "layout" "d" "DM-102.00")
(command "layout" "R" "DM-103.00" "DM-102.00")
);END PROGN demoroof not demorcp
)

 

This code seems to work if both the selections are not made.

(if (not demorcp)(command "layout" "d" "DM-102.00"))
(if (not demoroof)(command "layout" "d" "DM-103.00"))
)

 

How can i use the operators to make it so if the user selects the demo roof but they do not select the demo ceiling the routine will delete the "DM-102.00" tab & rename the "DM-103.00" tab to "DM-102.00. Perhaps my syntax is not correct but it seems like if i only have one selection the code is fine but if i have two selections it is telling me that i am using the variable as a function. When i change that it is telling me either i have too few arguments or too many. I guess i need some help on how to properly code the operators such as "and" & "or".

0 Likes
Accepted solutions (1)
1,765 Views
14 Replies
Replies (14)
Message 2 of 15

Kent1Cooper
Consultant
Consultant

Remove the parentheses around (demoroof) in the (if) test:

 

(if (and demoroof (not demorcp))

 

A left parenthesis needs to be followed immediately by a function name, not a variable name.

Kent Cooper, AIA
0 Likes
Message 3 of 15

Anonymous
Not applicable

it still says that demorcp is used as a function

 

.
; warning: local variable used as function: DEMORCP
; Check done.

 

(if (and demoroof (not demorcp))
(PROGN
(command "layout" "d" "DM-102.00")
(command "layout" "R" "DM-103.00" "DM-102.00")
);END PROGN demoroof not demorcp
)

0 Likes
Message 4 of 15

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

it still says that demorcp is used as a function

.... 

(if (and demoroof (not demorcp))
....


It doesn't look like it's being used as a function in that code snippet.  What is being put into the demoroof and/or demorcp variables?  Are they just T or nil, or is there more to it than that?  [I'm not versed in DCL stuff, so if you post that part of your code, others will probably do better at evaluating whether that's the source of the problem.]

Kent Cooper, AIA
0 Likes
Message 5 of 15

Anonymous
Not applicable

Thanks Kent. We use (3) programs to start our projects. The one i'm having trouble with is the update cover routine. I have to change the extension to txt to upload it here. The user selects options & based on those selections the lisp routine is supposed to delete or rename tabs. The aera in question is where im am defining "ARCADE IN LINE (NYC)" & then under that i am defining "cellaroneflr". I will upload the dcl files in a later post since i giess i can only upload (3) files at one time

0 Likes
Message 6 of 15

hmsilva
Mentor
Mentor

Hi sovby,

as Kent Cooper had suggested in previous posts, at your UpdateCover

  (command "layout" "d" "DM-102.00")
   (command "layout" "R" "DM-103.00" "DM-102.00")
   );END PROGN demoroof not demorcp
    );END if demoroof not demorcp
 
   (if (and demoroof(demorcp))
  (PROGN   
   (command "layout" "d" "DM-102.00")
   (command "layout" "d" "DM-103.00")
   );END PROGN demoroof not demorcp


Henrique

EESignature

0 Likes
Message 7 of 15

Anonymous
Not applicable

Right, but i need to somehow say:

 

if demoroof is selected but demorcp is not selected then do this. It is still seeing demorcp as a function. Sorry, i'm having a little trouble on how to write this out.


@hmsilva wrote:

Hi sovby,

as Kent Cooper had suggested in previous posts, at your UpdateCover

  (command "layout" "d" "DM-102.00")
   (command "layout" "R" "DM-103.00" "DM-102.00")
   );END PROGN demoroof not demorcp
    );END if demoroof not demorcp
 
   (if (and demoroof(demorcp))
  (PROGN   
   (command "layout" "d" "DM-102.00")
   (command "layout" "d" "DM-103.00")
   );END PROGN demoroof not demorcp


Henrique


 

0 Likes
Message 8 of 15

hmsilva
Mentor
Mentor
Accepted solution

I was just searching the 'warning: local variable used as function: DEMORCP' error...

 

To test 'if demoroof is selected but demorcp is not selected then do this'

 

  (if (and demoroof(not demorcp));; testing a valid demoroof  and a not valid demorcp
  (PROGN   
   (command "layout" "d" "DM-102.00")
   (command "layout" "R" "DM-103.00" "DM-102.00")
   );END PROGN demoroof not demorcp
    );END if demoroof not demorcp
 
   (if (and demoroof demorcp);; testing a valid demoroof  and a valid demorcp
  (PROGN   
   (command "layout" "d" "DM-102.00")
   (command "layout" "d" "DM-103.00")
   );END PROGN demoroof not demorcp
);END if demoroof demorcp

 

Henrique

EESignature

0 Likes
Message 9 of 15

Kent1Cooper
Consultant
Consultant

Some of the comments in that area of the code seem to be copied/pasted without editing for what they really are about.  Would this be right?:

 

  (if (and demoroof (not demorcp))
    (PROGN   
      (command "layout" "d" "DM-102.00")
      (command "layout" "R" "DM-103.00" "DM-102.00")
    );END PROGN demoroof not demorcp
  );END if demoroof not demorcp
  
  (if (and demoroof demorcp); removed parentheses around demorcp, as hmsilva did
    (PROGN   
      (command "layout" "d" "DM-102.00"); but do you really want to delete layout?
      (command "layout" "d" "DM-103.00"); but do you really want to delete layout?
    );END PROGN demoroof and demorcp
  );END if demoroof demorcp
 
I would think if both were set as the (if) test above asks, you wouldn't delete either.  Should that second group be instead:

 

  (if (and (not demoroof) (not demorcp))neither one, rather than both

    (PROGN   
      (command "layout" "d" "DM-102.00"); delete layout
      (command "layout" "d" "DM-103.00"); delete layout
    );END PROGN neither demoroof nor demorcp
  );END if neither demoroof nor demorcp

Kent Cooper, AIA
0 Likes
Message 10 of 15

Anonymous
Not applicable

It worked, Thanks everyone. I may have mispoken when i said i wanted to test if both items were valid. Actually the 2nd test is if both things are invalid. The first test is if demoroof is valid but demo rcp is invalid. I think this syntax is similar to what i had before but there is not a space in between (and demoroof(not demorcp). Here is what i ended up with. Now i should be able to have an option that says (if (and demorcp(not demoroof)) so that if they selet demorcp but not demoroof it will work.

(if (and demoroof(not demorcp));; testing a valid demoroof and a not valid demorcp
(PROGN
(command "layout" "d" "DM-102.00")
(command "layout" "R" "DM-103.00" "DM-102.00")
);END PROGN
);END if
(if (and (not demoroof)(not demorcp));; testing a valid demoroof and a valid demorcp
(PROGN
(command "layout" "d" "DM-102.00")
(command "layout" "d" "DM-103.00")
);END PROGN
);END if

0 Likes
Message 11 of 15

Anonymous
Not applicable

@Kent1Cooper wrote:

Some of the comments in that area of the code seem to be copied/pasted without editing for what they really are about.  Would this be right?:

 

  (if (and demoroof (not demorcp))
    (PROGN   
      (command "layout" "d" "DM-102.00")
      (command "layout" "R" "DM-103.00" "DM-102.00")
    );END PROGN demoroof not demorcp
  );END if demoroof not demorcp
  
  (if (and demoroof demorcp); removed parentheses around demorcp, as hmsilva did
    (PROGN   
      (command "layout" "d" "DM-102.00"); but do you really want to delete layout?
      (command "layout" "d" "DM-103.00"); but do you really want to delete layout?
    );END PROGN demoroof and demorcp
  );END if demoroof demorcp
 
I would think if both were set as the (if) test above asks, you wouldn't delete either.  Should that second group be instead:

 

  (if (and (not demoroof) (not demorcp))neither one, rather than both

    (PROGN   
      (command "layout" "d" "DM-102.00"); delete layout
      (command "layout" "d" "DM-103.00"); delete layout
    );END PROGN neither demoroof nor demorcp
  );END if neither demoroof nor demorcp


You are probably right. I was copying comments around. It seemed to work when i took the space out of between the two variables as in (and demoroof(not demorcp)). Otherwise it was telling me that i was trying to use the variable as a function. Yes, i do want to delete those two layouts if both of the variables are false because that would be when those items are unselected in the dcl. I think i had those backwards, i wanted those to be false. if the demoroof is selected but the demorcp is not selected i want to delete "DM-102.00" (which is the demorcp) & rename "DM-103.00" (demoroof) to DM-102.00 because i want the number sequence to not have a gap in it.

0 Likes
Message 12 of 15

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... I think this syntax is similar to what i had before but there is not a space in between (and demoroof(not demorcp). ....


Spaces between code elements, other than between elements that aren't wrapped in control characters like parentheses or quotes [such as the space you need between and & demoroof above] are ignored in AutoLISP code.  You don't even need them between things like command names and subsequent input -- this, for example, successfully draws a Line from 0,0 to 1,1, without any spaces at all in it:

(command"line""0,0""1,1""")

 

But I use them anyway, in places such as that Line command, and where you left one out above, because I find it so much easier to read the code with the elements separated.  And I use them for varying levels of indentation [see my previous Reply -- you can also use Tabs], which also greatly improves readability and understanding of the hierarchy of things, when [for example] parentheses pairs that do not occur in the same line have their closing right parenthesis in the same horizontal position as their opening left parenthesis, and subsidiary arguments are indented farther than the function names that they're arguments to [see all the samples in the AutoLISP Reference].  In any case, whether or not you include the space you mention is of no functional consequence.  This would also work:

 

(       and       demoroof        (         not        demorcp      )       )

 

Enters/new-lines are also ignored, so you can break up longer functions into multiple lines for better readability, as you already do with many (if) and (progn) functions, e.g. this would also work:

 

(and

  demoroof

  (not demorcp)

)

Kent Cooper, AIA
0 Likes
Message 13 of 15

Anonymous
Not applicable

ok thanks. I would have sworn that i had the same syntax before as the syntax that ended up working except for the space. It seems to work now so thanks for all of the help.

0 Likes
Message 14 of 15

Kent1Cooper
Consultant
Consultant

Just for kicks, another and slightly shorter way to say this:

 

  (if (and (not demoroof) (not demorcp))neither one, rather than both

 

 

would be this:

 

  (if (not (or demoroof demorcp)); neither one

Kent Cooper, AIA
0 Likes
Message 15 of 15

Anonymous
Not applicable

@Kent1Cooper wrote:

Just for kicks, another and slightly shorter way to say this:

 

  (if (and (not demoroof) (not demorcp))neither one, rather than both

 

 

would be this:

 

  (if (not (or demoroof demorcp)); neither one


Thanks  Kent & thanks everyone for the help. This is working great now. It's just a matter of teaking it here & there. I really appreciate everyone's help.

0 Likes