Jump to content

If statement by entity


Happy Hobbit

Recommended Posts

I wonder if this is even possible?

 

I'd like to crate an if statement to go inside an existing lisp that makes a decision based on entity type.

 

Something along the lines of:

 

(if (equal (0 . "text"))
(WRITE: DEBURR ALL EDGES & CORNERS)
(if
((equal (0 . "mtext"))
(WRITE: DEBURR ALL\\P EDGES & CORNERS)
))
)

 

The lisp I wish to insert it into is this:

 

(defun C:TRDB ;Text Replace for Complete text/mtext strings to "DEBURR ALL EDGES & CORNERS"
 (/ tss tdata)
 (setq tss (ssget (list (cons 1 "*"))))
 (repeat (sslength tss)
   (setq
     tdata (entget (ssname tss 0))
     tdata (subst (cons 1 "DEBURR ALL EDGES & CORNERS") (assoc 1 tdata) tdata)
   ); end setq
   (entmod tdata)
   (ssdel (ssname tss 0) tss)
 ); end repeat
)

 

The difference is the addition of \\p into the mtext option

 

Thanking you in anticipation

 

- Harry

Link to comment
Share on other sites

Hi Harry

 

I didn't understand you post clearly.... but i have given a try for what i understood

 

(defun C:TRDB (/ tss tdata i)
 (if (setq tss (ssget '(0 . "TEXT,MTEXT")))
				[color="red"];set filter list as per your requirement[/color]
   (repeat (setq i (sslength tss))
     (setq tdata (entget (ssname tss (setq i (1- i)))))
     (entmod
(subst
  (cons
    1
    (cond
      ((equal (cdr (assoc 0 tdata)) "TEXT")
       (strcat "DEBURR ALL EDGES & CORNERS")
      )
      ((equal (cdr (assoc 0 tdata)) "MTEXT")
       (strcat "DEBURR ALL\\P EDGES & CORNERS")
      )
    )
  )
  (assoc 1 tdata)
  tdata
)				;end subst
     )					;end entmod
   )					;end repeat
 )					;end if
 (princ)
)

Edited by satishrajdev
Link to comment
Share on other sites

A little more concise:

(defun c:trdb ( / e i s )
   (if (setq s (ssget '((0 . "TEXT,MTEXT"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i)))))
           (entmod 
               (subst 
                   (cons  1 (if (= "TEXT" (cdr (assoc 0 e))) "DEBURR ALL EDGES & CORNERS" "DEBURR ALL\\P EDGES & CORNERS")) 
                   (assoc 1 e)
                   e
               )
           )
       )
   )
   (princ)
)

Edited by Lee Mac
Link to comment
Share on other sites

Hello Satishrajdev

 

You obviously understood well enough to do a perfect reply

 

Thank you for your code, it's very good.

 

I'd never have got:

 

(equal (cdr (assoc 0 tdata)) "TEXT")

 

Any chance of explaining it to me?

 

I can see that it's a cond(itional) statement checking if the entity is equal to "TEXT" but I don't really understand:

 

 (cdr (assoc 0 tdata)) 

 

- Harry

Link to comment
Share on other sites

Satishrajdev, if multiple entities are selected I get:

 

; error: bad argument type: lselsetp nil

 

Using Debug it's on line:

 

(repeat (sslength tss)

 

 

Lee, with your lisp I get DEBURR ALL\P EDGES & CORNERS on text items (one back slash), although it works perfectly on mtext

 

Am I doing something wrong?

Link to comment
Share on other sites

Lee, with your lisp I get DEBURR ALL\P EDGES & CORNERS on text items (one back slash), although it works perfectly on mtext

 

Am I doing something wrong?

 

Apologies - I had referenced variable 'e' before it was defined - I have now corrected the above code.

Link to comment
Share on other sites

That's spot on Lee

 

I must admit I was convinced it was my mistake, I've never known a bug in you code before, although I bet you have...

 

Sometimes debugging drives me nuts

 

Thank you

 

- Harry

Link to comment
Share on other sites

That's spot on Lee

 

I must admit I was convinced it was my mistake, I've never known a bug in you code before, although I bet you have...

 

Sometimes debugging drives me nuts

 

Thank you

 

- Harry

 

You're most welcome Harry.

 

I should probably avoid typing the code straight into the forum post box without testing anything (Blind Coding) :oops:

 

Lee

Link to comment
Share on other sites

(assoc 0 "text")
The 0 is the dxf code which in this case is equal to the object type.

some examples

10 is start point

11 end

8 is layer name

40 is height

note these numbers can have different meaning depending on the object.

google dxf codes

Link to comment
Share on other sites

Satishrajdev, if multiple entities are selected I get:

 

; error: bad argument type: lselsetp nil

 

Using Debug it's on line:

 

(repeat (sslength tss)

 

 

Sorry, I was in hurry while leaving the office so didnt check the code properly...

I have updated my code.

 

 

Any chance of explaining it to me?

 

- Harry

 

DXF Code 0 shows which kind of entity it is... You can extract object type from Code 0

You can learn about DXf codes here http://docs.autodesk.com/ACD/2011/ENU/filesDXF/WSfacf1429558a55de185c428100849a0ab7-5df0.htm

Link to comment
Share on other sites

The 0 is the dxf code which in this case is equal to the object type.

some examples

10 is start point

11 end

8 is layer name

40 is height

note these numbers can have different meaning depending on the object.

google dxf codes

 

I see now !

 

Thanks for that Bigal & Satishrajdev

Link to comment
Share on other sites

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...