Jump to content

Recommended Posts

Posted

I'm sure there's a lot of way to filter selection sets

 

But how would you do write it if its the other way around?

say i have a thousand layer (exag of course) and my routine is transfering modified entities to exisitng layers and it will loop to process the selection again but i dont want the modified entities to be included on the next run and the next after that

 

is there a better way to do this?

 

(setq str_fnd (SSGET "X" '((0 . "TEXT,MTEXT")))
T_CNT 0
 )
(if (setq done_sel (ssget "x" '((8 . "Layer_*"))))
(foreach d_sel (vl-remove-if 'listp
               (mapcar 'cadr(ssnamex done_sel)))
   (ssdel d_sel str_fnd)
    )
 )

 

:)

Posted

Why does it loop to process the selection again?

Posted

Do you mean how to use a NOT filter?

 

(ssget "_X" '((0 . "TEXT,MTEXT") (-4 . "<NOT") (8 . "Layer_*") (-4 . "NOT>")))

Or

 

(ssget "_X" '((0 . "TEXT,MTEXT") (8 . "~Layer_*")))

Am I close?

Posted (edited)

Thanks both.

 

I guess you're right Lee Mac the NOT filter

But here's what i'm trying to do Allan, the conditions are:

There are thousands (literally) of text/mtext on a file, the goal is, the code will read from a txt file. that has a name and and category to go with it.

Not every item on the list is on the drawing file. (i can handle that) and there are twp or more items on the drawing with the same name as the one on the list but diffrerrent category.

and there are names on the list that repeats but with different category (updated)

e.g. "Wanton" category "1" at first pass it finds "wanton" and set it to category "1", (via layer change) and then stops. loop back and select the objects again, this time not including the category "1" layer because its already processed

as the code reads thru the text file it sees wanton but category "2" but wanton is not part of the selection anymore and to make it worse there are two wanton on the drawing and change the second wanton that to category "2" then it stops. and what if there is only one wanton but the list at the far end has another wanton name with an updated category (3)

the way i would set it up is one pass on the list and select the text/mtext process the selection based on the current item on the list. find it and stops then proceed with the next item what do you guys suggest?

:)

 

you think its better to processs the drawing entity one at a time and read the list over and over again?

BTW its a one time thing only... i havent really started the code, still trying to figure out the best and most efficient way to do it

Edited by pBe
Add Commnets
Posted (edited)

Okeedokee.

To settle the issue with the "list guys" I ask them to update their list to and remove superseeded items. they ended up with 1 name and 1 category. which made it easier.

So.. here's what i got

 

(defun PBE:rid_file (/ file_to_process file_open)
  (setq file_to_process (getfiled "Select source file" "D:\\" "txt" 16))
  (setq file_open (open file_to_process "r") Not_found_lst nil)
;;  read file  
(while
 (setq sx (read-line file_open))
;;  parse the string
  (setq list_bldg (substr sx 1 (-(strlen sx) 2)))
  (cond
    ((while (setq position (vl-string-search "-" sx))
(setq sx (substr sx (+ position 2))
)
     )
     (setq position (vl-string-search "\t" sx)
    category (substr sx (+ position 2))
    sx      (substr sx 1 position)
     )
    )
  )
(if category  
(PBE:FindString sx category)
  )(setq Found_flag nil)
)
(close file_open)
(if Not_found_lst (progn
 (princ "\nBuilding list not on BaseMap:")(princ)
 (foreach g Not_found_lst
   (print g)
  )
)
 )
 (princ)
 )
(defun PBE:FindString (sx category / str_fnd T_CNT done_sel to ent_to)
(vl-load-com)
(setq str_fnd (ssget "_X" '((0 . "TEXT,MTEXT") (-4 . "<NOT") (8 . "Cate*") (-4 . "NOT>")))
T_CNT 0
 )
 (while (< t_cnt (sslength str_fnd))
   (setq to (ssname str_fnd T_CNT)
  ent_to (entget to))
;(print (cdr (assoc 1 ent_to)))(princ)
(if (and to
  (= (cdr (assoc 1 ent_to)) sx)
    )
  (progn
    (setq Found_flag 'T)
    (setq typ (cdr (assoc 0 ent_to))
   pt  (cdr (assoc 10 ent_to))
   str (cdr (assoc 1 ent_to))
   ht  (cdr (assoc 40 ent_to))
   rt  (cdr (assoc 50 ent_to))
   jt  (cdr (assoc 71 ent_to))
   sst (cdr (assoc 7 ent_to))
    )
    (entdel to)
    (if (eq category "A")
      (setq c42 329215
     c44 3935927
     c45 1.50
     lyr "Category_A"
      )
      (setq c42 16715535
     c44 3935927
     c45 1.50
     lyr "Category_B"
      )
    )
    (PBE:MText lyr pt str ht rt jt sst)
    (setq T_CNT (sslength str_fnd))
  )    ;progn
)    ;if
(setq T_CNT (1+ T_CNT))
    )
   (if (not Found_flag)(progn
    ;(princ (strcat "\nBuilding Number " list_bldg " Not found:"))
    (setq Not_found_lst (cons list_bldg Not_found_lst) list_bldg nil)
  (princ)
  );progn
   );if
 )
;; credit to Lee Mac  ;;
(defun PBE:MText (lyr pt str ht rt jt sst)
 (entmakex (list (cons 0 "MTEXT")
   (cons 100 "AcDbEntity")
   (cons 100 "AcDbMText")
   (cons 10 pt)
   (cons 1 str)
   (cons 8 lyr)
   (cons 40 ht)
   (cons 50 rt)
   (cons 71 jt)
   (cons 7 sst)
   '(90 . 1)
   '(63 . 1)
   (cons 421 c42)
   (cons 45 c45)
   (cons 441 c44)
    )
 )
 (if (= typ "TEXT")
   (progn
     (setq nct     (entlast)
    ent_mod (entget nct)
     )
     (entmod (subst (cons 71 7) (assoc 71 ent_mod) ent_mod))
   )
 )(setq category nil sx nil)
 (princ)
)

 

The text file format is this:

D01-26-BL-Market B (space as "\t" )

 

It worked though. like i said its a one time thing only,

 

No error handler (as usual)

Any comments will be appreciated... :)

Edited by pBe

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