Jump to content

Recommended Posts

Posted

Hi everyone, I wanted to know if anyone could help me know where my problem is with this routine. What I am trying to do is select a polyline by entering its elevation but I think I am already stuck 😫. I am a beginner and I know what I could do using qselect but I would like to do it with lisp because I think the method is faster. any help i would appreciate 😁

 

(defun c:pk ()
(setq a (ssget "_X" '((0 . "LWPOLYLINE"))))
 (setq n (sslength a))
 (setq index 0)
 (setq b1 (vlax-ename->vla-object(ssname a index)))
 (setq p (getstring "Elev:"))
 (command "._select" (wcmatch (rtos(vla-get-elevation b1)) "p"))
      
)

Posted (edited)
35 minutes ago, Nario said:

Hi everyone, I wanted to know if anyone could help me know where my problem is with this routine. What I am trying to do is select a polyline by entering its elevation but I think I am already stuck 😫. I am a beginner and I know what I could do using qselect but I would like to do it with lisp because I think the method is faster. any help i would appreciate 😁

 


(defun c:pk ()
(setq a (ssget "_X" '((0 . "LWPOLYLINE"))))
 (setq n (sslength a))
 (setq index 0)
 (setq b1 (vlax-ename->vla-object(ssname a index)))
 (setq p (getstring "Elev:"))
 (command "._select" (wcmatch (rtos(vla-get-elevation b1)) "p"))
      
)

 

 

Edited by Nario
Posted (edited)
3 hours ago, Nario said:

Hi everyone, I wanted to know if anyone could help me know where my problem is with this routine. What I am trying to do is select a polyline by entering its elevation but I think I am already stuck 😫. I am a beginner and I know what I could do using qselect but I would like to do it with lisp because I think the method is faster. any help i would appreciate 😁

 

 

 

 

similar qselect? eg: elevation is 10.0

(sssetfirst nil (ssget "_X" '((0 . "LWPOLYLINE") (38 . 10.0))))

check this useful link ->  rational operators 

 

Edited by hanhphuc
syntax color
Posted

Consider the following code & comments:

(defun c:pk ( / z ) ;; Define function, declare local variables
    ;; Prompt the user to specify an elevation.
    ;; Use 'getreal' to ensure a numerical value is obtained.
    (if ;; If the following returns a non-nil value
        (setq z (getreal "\nSpecify elevation: "))
        (sssetfirst ;; Highlight the following selection set
            nil ;; This argument was never properly implemented
            (ssget ;; Attempt to obtain a selection set
                "_X" ;; Search entire database
                (list ;; Construct the following filter list
                   '(0 . "LWPOLYLINE") ;; Entity type
                   '(-4 . ">=") ;; For some tolerance
                    (cons 38 (- z 1e-3)) ;; Elevation lower bound
                   '(-4 . "<=") ;; For some tolerance
                    (cons 38 (+ z 1e-3)) ;; Elevation upper bound
                ) ;; end list
            ) ;; end ssget
        ) ;; end sssetfirst
        ;; Else the user dismissed the prompt:
        (princ "\nUser cancelled.")
    ) ;; end if
    (princ) ;; Return a null symbol to the command-line
) ;; end defun

 

  • Like 1
Posted (edited)

Nice explanation lee, it could be simply changed to Pick pline and level is = z. Then question, pick another, enter level or accept.

 

image.png.e0996fc1307c343c31083ead889164ff.png

Edited by BIGAL
Posted
8 hours ago, Lee Mac said:

Consider the following code & comments:


(defun c:pk ( / z ) ;; Define function, declare local variables
...
                   '(-4 . ">=") ;; For some tolerance
                    (cons 38 (- z 1e-3)) ;; Elevation lower bound
                   '(-4 . "<=") ;; For some tolerance
                    (cons 38 (+ z 1e-3)) ;; Elevation upper bound
...
) ;; end defun

 

 

more precise :thumbsup:

Posted

Thank you all for your answers and Lee Mac you are a rockstar. I still have a lot to study and practice and the page of rational operators of Lee Mac will be very useful. Many times I know the ingredients but I don't know the recipe (in other words i know what elements should be on lisp file but dont know how to use it) for that reason I must study hard and practice. Thanks

  • 3 years later...
Posted

I know that this is an old thread, but how would I go about doing this but it automatically selecting all elevations from +10 to +2000? I am really struggling with the "amending to previous selection" I think. If you run this one after another it wont add to the previous selection.

 

Thanks in advance! I am new to trying to accomplish writing my own code 

Posted
4 hours ago, dylanphillips said:

I know that this is an old thread, but how would I go about doing this but it automatically selecting all elevations from +10 to +2000? I am really struggling with the "amending to previous selection" I think. If you run this one after another it wont add to the previous selection.

 

Thanks in advance! I am new to trying to accomplish writing my own code 

 

Consider the following code -

(defun c:pk ( / zma zmi ) 
    (if (and (setq zmi (getreal "\nSpecify elevation lower bound (inclusive): "))
             (setq zma (getreal "\nSpecify elevation upper bound (inclusive): "))
        )
        (progn
            (if (< zma zmi) (mapcar 'set '(zmi zma) (list zma zmi)))
            (sssetfirst nil
                (ssget "_X"
                    (list 
                       '(000 . "LWPOLYLINE")
                       '(-04 . ">=")
                        (cons 038 (- zmi 1e-3))
                       '(-04 . "<=")
                        (cons 038 (+ zma 1e-3))
                    )
                )
            )
        )
    )
    (princ)
)

 

  • Like 2
Posted
15 hours ago, Lee Mac said:

 

Consider the following code -

(defun c:pk ( / zma zmi ) 
    (if (and (setq zmi (getreal "\nSpecify elevation lower bound (inclusive): "))
             (setq zma (getreal "\nSpecify elevation upper bound (inclusive): "))
        )
        (progn
            (if (< zma zmi) (mapcar 'set '(zmi zma) (list zma zmi)))
            (sssetfirst nil
                (ssget "_X"
                    (list 
                       '(000 . "LWPOLYLINE")
                       '(-04 . ">=")
                        (cons 038 (- zmi 1e-3))
                       '(-04 . "<=")
                        (cons 038 (+ zma 1e-3))
                    )
                )
            )
        )
    )
    (princ)
)

 

 

Thank you for such a quick response Lee Mac. I'm sorry I left out the most important part of this, I am only wanting to select the 10's. so I would want to select 10, 20, 30, etc. That is why I am struggling with the amending. I have been trying to do it with a while loop, but I am not sure where to put the while loop to keep the current ones selected. If that makes any sense. Here is what I have, although I know it has issues

 

(defun c:ELEVSEL ( / z ) ;; Define function, declare local variables
    (setq z 10)
    (while (<= z 2000) ; Ending z
          (sssetfirst ;; Highlight the following selection set
            nil ;; This argument was never properly implemented
            (ssget ;; Attempt to obtain a selection set
                "_X" ;; Search entire database
                (list ;; Construct the following filter list
                   '(0 . "LWPOLYLINE") ;; Entity type
                   '(-4 . ">=") ;; For some tolerance
                    (cons 38 (- z 1e-3)) ;; Elevation lower bound
                   '(-4 . "<=") ;; For some tolerance
                    (cons 38 (+ z 1e-3)) ;; Elevation upper bound
                ) ;; end list
            ) ;; end ssget
          ) ;; end sssetfirst
      (setq z (+ z 10)) ; Increment z by 10
    ) ;; end while
        ;; Else the user dismissed the prompt:
        (princ "\nUser cancelled.")
    (princ) ;; Return a null symbol to the command-line
) ;; end defun

 

Again, thank you so much for all of your help!!!!

Posted

Something like this ?

(defun c:Test (/ int sel ent add get )
  ;;----------------------------------------------------;;
  ;;	Author : Tharwat Al Choufi			;;
  ;; website: https://autolispprograms.wordpress.com	;;
  ;;----------------------------------------------------;;
  (and (setq int -1 add (ssadd)
             sel (ssget "_X" (list (cons 410 (getvar CTAB)) '(0 . "LWPOLYLINE") '(-04 . ">=") (cons 38 10)))
             )
       (while (setq int (1+ int) ent (ssname sel int))
         (and (setq get (entget ent))
              (zerop (rem (cdr (assoc 38 get)) 10))
              (ssadd ent add)
              )
         )
       )
  (sssetfirst nil add)
  (princ)
  )

 

Posted (edited)
2 hours ago, Tharwat said:

Something like this ?

(defun c:Test (/ int sel ent add get )
  ;;----------------------------------------------------;;
  ;;	Author : Tharwat Al Choufi			;;
  ;; website: https://autolispprograms.wordpress.com	;;
  ;;----------------------------------------------------;;
  (and (setq int -1 add (ssadd)
             sel (ssget "_X" (list (cons 410 (getvar CTAB)) '(0 . "LWPOLYLINE") '(-04 . ">=") (cons 38 10)))
             )
       (while (setq int (1+ int) ent (ssname sel int))
         (and (setq get (entget ent))
              (zerop (rem (cdr (assoc 38 get)) 10))
              (ssadd ent add)
              )
         )
       )
  (sssetfirst nil add)
  (princ)
  )

 

 

Thanks for the quick response again! I am honestly not sure exactly what you have done here, it is way over my head honestly...but I am getting this error whenever I try to run it:

 ; error: bad argument type: (or stringp symbolp): nil

 

 

Essentially I am wanting to select all polylines with elevations ending in zeros (or every 10) in the range of 10 to 2000 to put them on a different layer. So it would select 10, 20,30,40,50,60,70,80,90,100,110,etc all the way to 2000. In the past I have done this with a filter, which I have posted below, but I just want to do this with a lisp. I shortened my filter so that you can see everything, but I had it going from 10 -> 2000. Thanks in advance again! 

filter.PNG

Edited by dylanphillips
Posted (edited)

Oops , the elevation value has to be decimal  and the I forgot to quote the system variable, so try this instead and let me know.

(defun c:Test (/ int sel ent add )
  ;;----------------------------------------------------;;
  ;;	Author : Tharwat Al Choufi			;;
  ;; website: https://autolispprograms.wordpress.com	;;
  ;;----------------------------------------------------;;
  (and (setq int -1 add (ssadd)
             sel (ssget "_X" (list (cons 410 (getvar 'CTAB)) '(0 . "LWPOLYLINE") '(-04 . ">=") '(38 . 10.0)))
             )
       (while (setq int (1+ int) ent (ssname sel int))
         (and (zerop (rem (cdr (assoc 38 (entget ent))) 10.0))
              (ssadd ent add)
              )
         )
       )
  (sssetfirst nil add)
  (princ)
  )

 

Edited by Tharwat
Posted
8 minutes ago, Tharwat said:

Oops , the elevation value has to be decimal  and the I forgot to quote the system variable, so try this instead and let me know.

(defun c:Test (/ int sel ent add )
  ;;----------------------------------------------------;;
  ;;	Author : Tharwat Al Choufi			;;
  ;; website: https://autolispprograms.wordpress.com	;;
  ;;----------------------------------------------------;;
  (and (setq int -1 add (ssadd)
             sel (ssget "_X" (list (cons 410 (getvar 'CTAB)) '(0 . "LWPOLYLINE") '(-04 . ">=") '(38 . 10.0)))
             )
       (while (setq int (1+ int) ent (ssname sel int))
         (and (zerop (rem (cdr (assoc 38 (entget ent))) 10.0))
              (ssadd ent add)
              )
         )
       )
  (sssetfirst nil add)
  (princ)
  )

 

YES!! Thank you so so so much!!! I have been working on this for months! 

Posted
4 minutes ago, dylanphillips said:

YES!! Thank you so so so much!!! I have been working on this for months! 

You are welcome anytime. :) 

Posted (edited)

Nice succinct code above, but just because I wondered if it could be done....

 

This filters the lines during the selection set selection rather than afterwards - in a round about way. Was curious if it could be done similar to above (the key being create the selection set command as a text string, it can be generated with formulas, loops, calculations and so on, remember numbers need to be strings), then an "(eval (read" line. Could be useful in other places too where you want several unique selections in a selection set, might be quite versatile - if long winded

 

Like the DyllanPhillips example code, no selection set variable generated but this can easily be added

 

 

(defun c:test ( / Z MyCommand)
  (setq Z 10) ; lower limit
  (setq UL 2000) ; upper limit

  (setq MyCommand ;; create ssget command as text string. Allows for loops, while, foreach....
    "(ssget \"_X\" (list '(0 . \"LWPOLYLINE\") '(-4 . \"<OR\") "
  ) ; end strcat, end setq

(while (<= Z UL) ; loop - could be a foreach (if list of unique elevations, other calculations
  (setq MyCommand (strcat MyCommand
    "'(-4 . \"<AND\") '( -4 . \">=\") '( 38 . "
    (rtos (- Z 1e-3)) ") " ;; Elevation lower bound
    "'( -4 . \"<=\") '( 38 . "
    (rtos (+ Z 1e-3)) ") " ;; Elevation upper bound
    "'(-4 . \"AND>\") "
  )) ; end strcat, end setq
  (setq Z (+ Z 10))
) ; end while

  (setq MyCommand (strcat MyCommand
    "'(-4 . \"OR>\") ))"
  )) ; end strcat, end setq

(sssetfirst nil 
  (eval (read MyCommand))
)

  (princ)
)

 

Edited by Steven P

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