to select object with hatch size

to select object with hatch size

anycganycgJ8A6A
Advocate Advocate
2,210 Views
26 Replies
Message 1 of 27

to select object with hatch size

anycganycgJ8A6A
Advocate
Advocate

Good morning
I need some help, so I posted it.

For example
There are hatches.

1. x size = 300 or y size = 300
     I would like to select only hatches and move them to a new layer

2. If the x size is less than 300 and the y size is less than 300
I would like to select only the hatches and move them to a new layer


I'd like to ask you for some code that's available.

0 Likes
Accepted solutions (1)
2,211 Views
26 Replies
Replies (26)
Message 21 of 27

anycganycgJ8A6A
Advocate
Advocate

pls see my attahed file

0 Likes
Message 22 of 27

ВeekeeCZ
Consultant
Consultant

@anycganycgJ8A6A wrote:

pls see my attahed file


"That did not send the hatches to new layer" because you select wrong distance. If you're selecting X distance from the drawing, it must be horizontal. It's taking a DISTANCE, not a X-projection.

0 Likes
Message 23 of 27

anycganycgJ8A6A
Advocate
Advocate

 

that is    4 same x size  = 317

 

so i  put  x = 317 

 

~~~~

0 Likes
Message 24 of 27

ВeekeeCZ
Consultant
Consultant

@anycganycgJ8A6A wrote:

 

that is    4 same x size  = 317

 

so i  put  x = 317 

 

~~~~


There are NOT. There are 4 objects with x = 317.0092.

Anyway, I added the precision, its set to 0.01, you may change the value.

 

(defun c:HatchbyXY2Layer (/ ss areap ent i lay clay fltx funx flty funy prec)
 
  (if (and (setq ss (ssget "_X" '((0 . "HATCH"))))
           (or (progn
                 (and (setq fltx (getdist "\nFilter by X <no filter>: "))
                      (not (initget "< > = Less More Equal"))
                      (setq funx (getkword "\nSelect typ of comparison [< Less/> More/= Equal]: "))
                      (setq funx (cond ((wcmatch funx "<,Less") <)
                                       ((wcmatch funx ">,More") >)
                                       ((wcmatch funx "=,Equal") equal))))
                 (and (setq flty (getdist "\nFilter by Y <no filter>: "))
                      (not (initget "< > = Less More Equal"))
                      (setq funy (getkword "\nSelect typ of comparison [< Less/> More/= Equal]: "))
                      (setq funy (cond ((wcmatch funy "<,Less") <)
                                       ((wcmatch funy ">,More") >)
                                       ((wcmatch funy "=,Equal") equal)))))
               funx)
           (setq prec 0.01)
           )
    (repeat (setq i (sslength ss))
      (setq ent (ssname ss (setq i (1- i))))
      (vla-GetBoundingBox (vlax-ename->vla-object ent) 'Ptmin 'Ptmax)
      (setq box (cons (vlax-safearray->list PtMin)
                      (vlax-safearray->list PtMax)))
      (if (not (and (or (not fltx)
                        (cond ((equal funx equal)
                               (funx (abs (- (cadr box) (caar box))) fltx prec))
                              (funx (abs (- (cadr box) (caar box))) fltx)))
                    (or (not flty)
                        (cond ((equal funy equal)
                               (funy (abs (- (caddr box) (cadar box))) flty prec))
                              ((funy (abs (- (caddr box) (cadar box))) flty))))
                    ))
        (ssdel ent ss))))
  (if (and ss
           (> (sslength ss) 0)
           (setq lay (lisped (setq clay (getvar 'clayer)))))
    (progn
      (command "_.-LAYER" "_T" lay "_M" lay ""
               "_.CHPROP" ss "" "_La" (getvar 'clayer) "")
      (print (sslength ss)) (princ (strcat " hatches moved to layer '" (getvar 'clayer) "'"))
      (sssetfirst nil ss)
      (setvar 'CLAYER clay)))
  (princ)
)

 

0 Likes
Message 25 of 27

anycganycgJ8A6A
Advocate
Advocate

Thank you very much
I want to ask for more, but
I'm trying to stop here.
Thank you very much
Thank you so much
I hope you have a good day
I'll sleep well tonight because of your kindness.

0 Likes
Message 26 of 27

ВeekeeCZ
Consultant
Consultant
Accepted solution

That's kind of you. You also can hit the "Mark as solution" button to inform other users that issue was solved in that particular message. 

Anyway, found minor bug that I've fixed.

 

(defun c:HatchbyXY2Layer (/ ss areap ent i lay clay fltx funx flty funy prec)
 
  (if (and (setq ss (ssget "_X" '((0 . "HATCH"))))
           (or (progn
                 (and (setq fltx (getdist "\nFilter by X <no filter>: "))
                      (not (initget "< > = Less More Equal"))
                      (setq funx (getkword "\nSelect type of comparison [< Less/> More/= Equal]: "))
                      (setq funx (cond ((wcmatch funx "<,Less") <)
                                       ((wcmatch funx ">,More") >)
                                       ((wcmatch funx "=,Equal") equal))))
                 (and (setq flty (getdist "\nFilter by Y <no filter>: "))
                      (not (initget "< > = Less More Equal"))
                      (setq funy (getkword "\nSelect typ of comparison [< Less/> More/= Equal]: "))
                      (setq funy (cond ((wcmatch funy "<,Less") <)
                                       ((wcmatch funy ">,More") >)
                                       ((wcmatch funy "=,Equal") equal)))))
               funx)
           (setq prec 0.01)
           )
    (repeat (setq i (sslength ss))
      (setq ent (ssname ss (setq i (1- i))))
      (vla-GetBoundingBox (vlax-ename->vla-object ent) 'Ptmin 'Ptmax)
      (setq box (cons (vlax-safearray->list PtMin)
                      (vlax-safearray->list PtMax)))
      (if (not (and (or (not fltx)
                        (cond ((equal funx equal)
                               (funx (abs (- (cadr box) (caar box))) fltx prec))
                              ((funx (abs (- (cadr box) (caar box))) fltx))))
                    (or (not flty)
                        (cond ((equal funy equal)
                               (funy (abs (- (caddr box) (cadar box))) flty prec))
                              ((funy (abs (- (caddr box) (cadar box))) flty))))
                    ))
        (ssdel ent ss))))
  (if (and ss
           (> (sslength ss) 0)
           (setq lay (lisped (setq clay (getvar 'clayer)))))
    (progn
      (command "_.-LAYER" "_T" lay "_M" lay ""
               "_.CHPROP" ss "" "_La" (getvar 'clayer) "")
      (print (sslength ss)) (princ (strcat " hatches moved to layer '" (getvar 'clayer) "'"))
      (sssetfirst nil ss)
      (setvar 'CLAYER clay)))
  (princ)
)
0 Likes
Message 27 of 27

anycganycgJ8A6A
Advocate
Advocate

Thank you very much
You are helping me to the end.
I was really impressed with your efforts.
I wonder if there will be another friendly person like you.
You were really hard.
I'll write code really well

0 Likes