Jump to content

Recommended Posts

Posted

Please help me filter all text that is divisible by 5.

 

Thanks in advance:)

Posted

Please help me edit this code that i've written

(defun c:div ()
(setq divi (getdist "Enter divisibility:"))
(setq layer (strcat "div_"(rtos divi 2 2)))
(if (setq ss (ssget "_X" '((0 . "TEXT"))))
(repeat (setq i (sslength ss))
(setq num (getreal (assoc 1 (entget (setq e (ssname ss (setq i (1- i))))))))
)
)
(command "-layer" "m" layer "")
(if
(= (rem num divi ) 0)
(command "_.chprop" e "" "_layer" layer "")
)
(princ)
)

Posted

 

(setq num (getreal (assoc 1 (entget (setq e (ssname ss (setq i (1- i))))))))

 

 

hi rrulep,

getreal normally user prompt.

but i notice it's inside a repeat loop

im using 2007, here's my normal practice:

(setq num (atof (cdr (assoc 1 (entget .....)))))

 

 

:)

Posted

I change it already but still not working.

What might be the error?

Can you try it? then post it back if it is working.

 

Thanks in advance

Posted

hi i didn't change anything, just move (command "layer"....) in the repeat loop.

(defun c:div  (/ divi layer ss num i e dxf)
 (setq divi (getreal "Enter divisibility: ");
 	layer (strcat "div_" (rtos divi 2 2))
       dxf  '((_e _i _val / _en)
 	(setq _en (entget _e))
 	(if (assoc _i _en)
   	(entmod (subst (cons _i _val) (assoc _i _en) _en))
   	(entmod (append _en (list (cons _i _val))))
   	) ; if
 	(princ))
       )
 (if (setq ss (ssget "_X" '((0 . "TEXT"))))
   (repeat (setq i (sslength ss))
     (setq num (atof (cdr (assoc 1 (entget (setq e (ssname ss (setq i (1- i)))))))))
     (command "-layer" "m" layer "")
     (if (= (rem num divi) 0)
;;;(command "_.chprop" e "" "_layer" layer ""); 
       (dxf e 8 layer))));  *dxf code 8 is for Layer
 (princ))

 

*using (command "-layer" ) in code not a good practice, so i replace entmod maybe faster :)

 

;this is just your simple code, you can add error handler, other ssget filter etc..

good luck

Posted
(defun C:test (/ n i   s ss lay )
 (if 
   (setq n (getint "\nEnter divisibility:")
         ss (ssget "_X" '((0 . "TEXT")))
         lay (itoa n)
   )
   (progn
     (if 
       (not (tblsearch "layer" (strcat "Div_" lay)))
         (entmake
           (list 
             '(0 . "LAYER") 
             '(100 . "AcDbSymbolTableRecord") 
             '(100 . "AcDbLayerTableRecord")													               
              (cons 70 0) 
              (cons 2 (strcat "Div_" lay))
           )
         )
     )
  (setq lay (strcat "Div_" lay))
     (repeat (setq i (sslength ss))
       (if 
         (multipleof (atof (cdr (assoc 1 (entget (setq s (ssname ss (setq i (1- i)))))))) n)
         (vla-put-layer (vlax-ename->vla-object s) lay)
	)
     )
)
 )
 (princ)
 )
 (defun multipleof (n x)
 (while (> n x) (setq n (- n x)))
 (if (= n x) t nil)
 )

Posted

A simple check of divide by number is the remainder must be .0 35/5 = 5.0 36/5=5.2 just use the FIX to check if .0

Posted

Filtering texts divisible by 5:

(ssget '((0 . "TEXT") (1 . "*[05]")))

Well, "a5" can be selected and is not divisible by 5... :) so you can add filters like layer, style, height and whatnot.

Also, if the numbers you want to select are in a specific range, say less than 1000, the filter might be: (1 . "##[05],#[05],[05]")

Posted
Filtering texts divisible by 5:

(1 . "##[05],#[05],[05]")

hi good idea stefan. i was thinking (numberp (read str)) to get rid of alphabetic string returns zero if using (atof str)

 

i think zero also can be ignored because it always divisible?

Posted

@hanhphuc

The square brackets matches any single character enclosed.

For example, ##[05] means ##0 OR ##5.

In words, it means "any string containing exactly 3 characters, starting with any 2 numeric characters and ending with 0 or 5"

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