Jump to content

Recommended Posts

Posted

Please bear with me, I'm still really green on this.

 

I'm trying to create a selection set that will choose only text and mtext. However it doesn't seem to be working for me. Is this correct?

 

setq Tchg (ssget '((-4 . "<AND")(0 . "MTEXT")(0 . "TEXT")))

 

This is the complete code I've written, it's meant to just change text sizes that are selected, sort of a dummied down match prop command, as THAT particular command can sometimes do TOO much.

 

(defun c:tchg ()
 (setq CMD-ECHO (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 (defun GetText ()
   (setq en1 (car (entsel "\nChoose text entity to match with: ")))
   (setq OLDENT (entget en1))
   (setq ENTCHANGE (assoc 40 OLDENT))
   (setq ENTCHANGE (cdr ENTCHANGE))
 )

 ;;End get text

 (defun GetChange ()
   (prompt "\nSelect all text entities you wish to change: ")
   (setq Tchg (ssget '((-4 . "<AND")(0 . "MTEXT")(0 . "TEXT")))
   )
 )
 (GetText)
				;(GetSize)
 (GetChange)
 (repeat (setq n (sslength Tchg))
   (setq chg (ssname tchg (setq n (1- n))))
   (setq Tval (cdr (assoc 40 (setq ts (entget chg)))))
   (entmod (subst (cons 40 entchange) (assoc 40 ts) ts))
 )
 (setvar "cmdecho" CMD-ECHO)
)

 

Later at some point I might try to get it to include multileaders too, but I'll start with the simple stuff first.

 

Silvercloak

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • Silvercloak

    6

  • MSasu

    5

  • irneb

    4

  • David Bethel

    3

Top Posters In This Topic

Posted (edited)

You forgot to close the logical construction:

 

(ssget '((-4 . "<OR") (0 . "MTEXT")(0 . "TEXT") [color=red](-4 . "OR>")[/color]))

 

But you may simplify that as:

 

(ssget '((0 . "MTEXT,TEXT")))

Regards,

Mircea

Edited by MSasu
code fixed
Posted

Thank you, THAT was something they failed to teach me in class. Excellent.

Posted

One other question that just occured to me. Is it possible to tell it to select by using either pick point OR crossing window or Window?

 

Silvercloak

Posted

Please check the help of SSGET function for available selection methods and combinations; also for filters with wild-characters check the WCMATCH function.

 

Regards,

Mircea

Posted
Please check the help of SSGET function for available selection methods and combinations; also for filters with wild-characters check the WCMATCH function.

 

Regards,

Mircea

 

Thank you, I read through that, but I'm still confused. Shouldn't this

(setq Tchg (ssget "w"'((0 . "MTEXT, TEXT")))

allow the user to create a window and select only text and mtext?

 

Silvercloak

Posted

You should supply the points:

 

(if (and (setq point1st (getpoint "\First corner: "))
        (setq point2nd (getcorner point1st "\nOther corner: ")))
(ssget "_W" point1st point2nd '((0 . "MTEXT, TEXT")))
)

Regards,

Mircea

Posted
You should supply the points:

 

(if (and (setq point1st (getpoint "\First corner: ")
              point2nd (getcorner point1st "\nOther corner: ")))
(ssget "_W" point1st point2nd '((0 . "MTEXT, TEXT")))
)

 

Regards,

Mircea

 

Thanks, I was kind of hoping that by leaving it without points, it would allow the user to click on either a point or blank space and then proceed with a crossing window or regular window. I'm discovering that AutoLISP is far less intuitive than I had hoped.

 

Silvercloak

Posted

If will call the function without a method - you may supply filter(s) or not - then the user will be allowed to use any of AutoCAD's standard selections method (i.e. pick, window, crossing, fence).

I suggest you to follow some of the many tutorials available on SSGET function.

 

Regards,

Mircea

Posted

I definitely will, thanks Mircea, it appears SSGET is more complex than it appears at first glance :)

Posted

Did you try an OR filter ?



(setq Tchg (ssget '((-4 . "<OR")(0 . "MTEXT")(0 . "TEXT")))

 

=David

Posted
Did you try an OR filter ?



(setq Tchg (ssget '((-4 . "<OR")(0 . "MTEXT")(0 . "TEXT")))

 

=David

I also noticed that. The "

 

Anyhow, you don't need the "" grouping in most cases (other than this one :shock:) - it's already implied as such. It's only necessary when you have one or more OR's and portions thereof you want to have as AND's.

Posted

What ab. "". I really have difficulties understanding XOR... Can someone explain with some example?...

 

M.R.

Posted (edited)
I also noticed that. The "

 

Anyhow, you don't need the "" grouping in most cases (other than this one :shock:) - it's already implied as such. It's only necessary when you have one or more OR's and portions thereof you want to have as AND's.

 

The AND test is normally used for 2 unique DXF group values,

(-4 ". <AND") (0 . "CIRCLE) (40 . 1.0) (-4 . "AND>")

 

You can also group AND filters within OR tests

 

All of the logical filters (AND,OR,XOR,NOT) must be in balanced pairs

 

Wildcards can get to be confusing when you start trying to combine "~" with "*" and "," sequences.

Edited by David Bethel
Posted

The usual difficulty when working with and/or/xor is that most people (or rather most languages including English) doesn't define those words exactly as logical comparison defines them. Usually when people say "OR" what they mean is XOR (or Exclusive Or) - i.e. it's either the one or the other - not both. Logic Comp defines OR as "Any of the operands - even just one, but also more than one".

 

Then you get to the AND ... which also sometimes gets confusing. Since people sometimes misuse the word in conversation - you end up with situations like these. In Logic Comp AND means "All the operands - not just some".

 

The way lisp (and most other programming languages) work on these is the following:

 

AND:

 

  1. Check if next operand returns True (or not nil in the case of Lisp).
  2. If the test is positive, continue. Else return False/Nil.
  3. If there's any more operands repeat from 1, else return True.

OR:

  1. Check if next operand returns True (or not nil in the case of Lisp).
  2. If the test is positive, return True. Else continue.
  3. If there's any more operands, repeat from 1. Else return False/Nil.

NOT: Basically an invert toggle. If the operand (only one - doesn't work on more) is False/Nil return True. If the operand is True/NotNil return False/Nil.

 

XOR: This is how most people understand the word OR when spoken - i.e. as in "Either OR".

Though Lisp doesn't have a XOR function, you can make one quite easily. The principle behind it would be to combine OR, NOT & AND. E.g.:

(defun XOR (v1 v2 /)
 (and (or v1 v2) (not (and v1 v2)))
)

Thus it returns an AND of an OR & (NOT) AND. I.e. True only if OR returns true, but AND returns FALSE - otherwise return False/Nil.

Most other languages have built-in XOR functions/operators, but usually they'd be implemented similarly - just already done for you.

Posted
Wildcards can get to be confusing when you start trying to combine "~" with "*" and "," sequences.
Not as confusing as when you try to use Regular Expressions :? ... but yes, you need your wits about you to understand what's going on.
Posted

Three more variations of a possible XOR function, for fun:

 

(defun XOR ( a b )
   (or (and a (not b)) (and b (not a)))
)

(defun XOR ( a b )
   (and (or (not a) (not b)) (or a b))
)

(defun XOR ( a b )
   (or (not (or (not a) b)) (not (or a (not b))))
)

 

Nice explanation Irne :thumbsup:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...