WCMATCH *.25 help

WCMATCH *.25 help

Village_Idiot
Contributor Contributor
307 Views
8 Replies
Message 1 of 9

WCMATCH *.25 help

Village_Idiot
Contributor
Contributor

Trying to check for blocks that are not on .25 grid.  Having trouble with wild card.  What am I doing wrong? 

 

(defun c:ShowOffGrid (/ blkss idx blkent blkvx blkloc)
  (setq blkss(ssget "X" '((0 . "INSERT"))))
  (repeat (setq idx (sslength blkss))
          (setq blkent (ssname blkss (setq idx (1- idx)))
                blkvx (vlax-ename->vla-object blkent)
                blkloc (vlax-safearray->list (vlax-variant-value(vlax-get-property blkvx 'insertionPoint)))
          )
    (cond
      ((not(wcmatch (rtos (car blkloc) 2) "*.0, *`.25, *`.5, *`.75" ))
      (ssdel blkent blkss)
      )
      ((not(wcmatch (rtos (cadr blkloc) 2) "*`.0, *`.25, *`.5, *`.75" ))
      (ssdel blkent blkss)
      )
    )
  
  )
  (sssetfirst nil blkss)
  (princ)
)

(princ "\n----------ShowOffGrid Loaded---------")
(princ)

 

0 Likes
Accepted solutions (1)
308 Views
8 Replies
Replies (8)
Message 2 of 9

BlackBox_
Advisor
Advisor
Accepted solution
(defun c:ShowOffGrid (/ blkss idx blkent blkvx blkloc x y grid)
  (if
    (setq blkss
           (ssget "_X"
                   (list '(0 . "INSERT") (cons 410 (getvar 'ctab)))
            )
    )
     (progn
       (repeat (setq idx (sslength blkss))
         (setq blkent (ssname blkss (setq idx (1- idx))))
         (setq blkvx (vlax-ename->vla-object blkent))
         (setq blkloc (vlax-get blkvx 'insertionPoint))
         
         (setq x
                (substr
                  (setq x (rtos (car blkloc) 2 2))
                  (+ (vl-string-search "." x)
                     2
                  )
                )
         )         
         (setq y (substr
                   (setq y (rtos (cadr blkloc) 2 2))
                   (+ (vl-string-search
                        "."
                        y
                      )
                      2
                   )
                 )
         )
         (if
           (and
             (wcmatch x (setq grid "00,25,50,75"))
             (wcmatch y grid)
           )
            (ssdel blkent blkss)
         )
       )
       (sssetfirst nil blkss)
     )
     (prompt "\n** Nothing selected ** \n")
  )
  (princ)
)


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 3 of 9

Village_Idiot
Contributor
Contributor

Thanks @BlackBox_ !  

 

... and my brain was broken when I put the (not (wcmatch in.  I even had to look at it a bit now to make sure I understood.  I must be more tired then I realize.  lol

 

Thanks again.

0 Likes
Message 4 of 9

Kent1Cooper
Consultant
Consultant

@Village_Idiot wrote:

Trying to check for blocks that are not on .25 grid.  ,,,.


I think there's an easier way to check for that, without involving text strings or wildcards or spelling out all four multiples of 0.25.  For any given point [such as a Block's insertion point]:

 

(if

  (and

    (= (rem TheXCoordinate 0.25) 0)

    (= (rem TheYCoordinate 0.25) 0)

  ); and

  (then -- it's on the grid)

  (else -- it's not)

); if

Kent Cooper, AIA
0 Likes
Message 5 of 9

komondormrex
Mentor
Mentor

even shorter one

same as kc's
0 Likes
Message 6 of 9

BlackBox_
Advisor
Advisor

@Kent1Cooper is correct - I think I got stuck on trying to give OP back something like they started with, so they could see how to do it, that I overlooked this. Thanks!

 

@Village_Idiot - here's what that might look like - just be mindful that REM is precise, so *.250000000001 is 'off grid' regardless of your units precision when a selected block displays coordinates in properties pane after selection:

(defun c:ShowOffGrid (/ blkss idx blkent pt)
  (if
    (setq blkss
           (ssget "_X"
                   (list '(0 . "INSERT") (cons 410 (getvar 'ctab)))
            )
    )
     (progn
       (repeat (setq idx (sslength blkss))
         (setq blkent (ssname blkss (setq idx (1- idx))))
         (if
           (and
             (=
               (rem (car (setq pt (cdr (assoc 10 (entget blkent))))) 0.25)
                0
             )
             (= (rem (cadr pt) 0.25) 0)
           )
           (ssdel blkent blkss)
         )
       )
       (sssetfirst nil blkss)
     )
     (prompt "\n** Nothing selected ** \n")
  )
  (princ)
)

 

Cheers


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant

Or, even more concisely, since the (=) function can take more than two arguments:

(if

  (= (rem TheXCoordinate 0.25) (rem TheYCoordinate 0.25) 0)

  (then -- it's on the grid)

  (else -- it's not)

); if

Kent Cooper, AIA
0 Likes
Message 8 of 9

Village_Idiot
Contributor
Contributor

Thank you all for sharing. "rem" is a new on for me.

0 Likes
Message 9 of 9

Sea-Haven
Mentor
Mentor

The 0.000001 problem maybe.

 

rem 123.2500000001 0.25)
1.00001784630877e-10

 

(equal (REM 123.25000001 0.25) 0.0 1e-06)
T
0 Likes