Jump to content

Recommended Posts

Posted

;; If the selection set (txt) can be obtained and it holds more than one item ;;then we will use

(if (< 1 (sslength txt))

(do this)

)

 

;;what if selection set (txt) don't have any entity.

 

(if (= nil (sslength txt))  ;;but it is not working plz suggest right way

(do this)

)

Posted (edited)

Try this

 

(if (/= txt nil)
(Progn ; if more than 1 line of code
(do this)
)
)

Edited by BIGAL
Posted

What are you trying to do ? and post your complete example cause to have a condition with the sslength function is not the proper way in general .

Posted

This code is selecting the closed polylines if they have more than one Text,Mtext inside.

But if i like to select the closed polylines which have no Text,Mtext inside.

 

(defun c:mtpl ( / app ent grp idx lst mni mxa out sel tmp txt )
   (if (setq sel (ssget "_X" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))))
       (progn
           (repeat (setq idx (sslength sel))
               (setq ent (ssname sel (setq idx (1- idx)))
                     lst (cons (cons ent (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent)))) lst)
               )
           )
           (setq tmp (apply 'append (mapcar 'cdr lst))
                 mni (car tmp)
                 mxa (car tmp)
           )
           (foreach pnt (cdr tmp)
               (setq mni (mapcar 'min mni pnt)
                     mxa (mapcar 'max mxa pnt)
               )
           )
           (setq app (vlax-get-acad-object)
                 out (ssadd)
           )
           (vla-zoomwindow app (vlax-3D-point mni) (vlax-3D-point mxa))
           (foreach grp lst
               (if
                   (and
                       (setq txt (ssget "_wp" (mapcar '(lambda ( p ) (trans p (car grp) 1)) (cdr grp)) '((0 . "TEXT,MTEXT"))))
                       (< 1 (sslength txt))     
                   )
                   (ssadd (car grp) out)
               )
              (setq txt nil)
               (gc)
           )
           (sssetfirst nil out)
       )
   )

   (princ)
)
(vl-load-com) (princ)

Posted
This code is selecting the closed polylines if they have more than one Text,Mtext inside.

But if i like to select the closed polylines which have no Text,Mtext inside.

 

 

Replace this part .

 

(foreach grp lst
               (if (not (setq txt (ssget "_wp" (mapcar '(lambda ( p ) (trans p (car grp) 1)) (cdr grp)) '((0 . "TEXT,MTEXT"))))    )
                   (ssadd (car grp) out)
               )
              (setq txt nil)
               (gc)
           )

Posted

Now it is selecting all the polylines

(defun c:mtpl ( / app ent grp idx lst mni mxa out sel tmp txt )
   (if (setq sel (ssget "_X" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))))
       (progn
           (repeat (setq idx (sslength sel))
               (setq ent (ssname sel (setq idx (1- idx)))
                     lst (cons (cons ent (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent)))) lst)
               )
           )
           (setq tmp (apply 'append (mapcar 'cdr lst))
                 mni (car tmp)
                 mxa (car tmp)
           )
           (foreach pnt (cdr tmp)
               (setq mni (mapcar 'min mni pnt)
                     mxa (mapcar 'max mxa pnt)
               )
           )
           (setq app (vlax-get-acad-object)
                 out (ssadd)
           )
           (vla-zoomwindow app (vlax-3D-point mni) (vlax-3D-point mxa))
           (foreach grp lst
               (if (not (setq txt (ssget "_wp" (mapcar '(lambda ( p ) (trans p (car grp) 1)) (cdr grp)) '((0 . "TEXT,MTEXT"))))
                       
                   )
                   (ssadd (car grp) out)
               )
              (setq txt nil)
               (gc)
           )
           (sssetfirst nil out)
       )
   )

   (princ)
)
(vl-load-com) (princ)

Posted

But if i like to select the closed polylines which have no Text,Mtext inside.

 

Now it is selecting all the polylines

 

Settle your goal first and after that post your question ;)

Posted

i only like to select polyline which don't have text inside. that's it.

Posted
i only like to select polyline which don't have text inside. that's it.

So my modification and your rearrangement on the routine should do the trick in posts # 6 & 7 , otherwise upload the drawing you are testing the codes on .

Posted

Thanks Tharwat! Its working fine now.

but why (/= txt nil) was not working.

Posted
Thanks Tharwat! Its working fine now.

 

It was ;)

 

but why (/= txt nil) was not working.

 

That means does not equal to nil , so it has a value which is not nil ;)

Posted

Thanks It is working fine now.

Posted
Thanks It is working fine now.

 

Happy to hear that . You're welcome .

Posted

I was thinking that instead of selecting, can we change the property of polyline like color and LW.

Posted
I was thinking that instead of selecting, can we change the property of polyline like color and LW.

Yes you can , by iterating through each entity in the selection set and update any property you want by adding / appending it to the DXF codes .

Posted

Or may do the same for entire selection set by calling CHPROP command:

(if (setq selSet (ssget))
(command "_CHPROP" selSet "" "_C" 2 "")   ;change color to yellow
)

Posted

Thanks MSasu this way i know but in my below code if i like to change the color of polylines which have no text inside.

 

(defun c:mtpl ( / app ent grp idx lst mni mxa out sel tmp txt )
   (if (setq sel (ssget "_X" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))))
       (progn
           (repeat (setq idx (sslength sel))
               (setq ent (ssname sel (setq idx (1- idx)))
                     lst (cons (cons ent (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent)))) lst)
               )
           )
           (setq tmp (apply 'append (mapcar 'cdr lst))
                 mni (car tmp)
                 mxa (car tmp)
           )
           (foreach pnt (cdr tmp)
               (setq mni (mapcar 'min mni pnt)
                     mxa (mapcar 'max mxa pnt)
               )
           )
           (setq app (vlax-get-acad-object)
                 out (ssadd)
           )
           (vla-zoomwindow app (vlax-3D-point mni) (vlax-3D-point mxa))
           (foreach grp lst
               (if (not (setq txt (ssget "_wp" (mapcar '(lambda ( p ) (trans p (car grp) 1)) (cdr grp)) '((0 . "TEXT,MTEXT"))))
                       
                   )
                   (ssadd (car grp) out)
               )
              (setq txt nil)
               (gc)
           )
           (sssetfirst nil out)
       )
   )

   (princ)
)
(vl-load-com) (princ)

Posted
This code is selecting the closed polylines if they have more than one Text,Mtext inside.

But if i like to select the closed polylines which have no Text,Mtext inside.

 

A tip for future posts: when posting code that is not your own, it is common etiquette to indicate the original author/source, otherwise the posted code is assumed to be your own. Please familiarise yourself with the Code Posting Guidlines applicable to all code posted on this forum.

Posted

A 3rd way seeing your using VL why not use gets & puts for color and linetype etc

 

(vla-put-color ent 0) 
  (vla-put-linetype ent "Bylayer") 
  (vla-put-lineweight ent aclnwtbyblock)

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