Author Topic: initget and entsel  (Read 2626 times)

0 Members and 1 Guest are viewing this topic.

DanB

  • Bull Frog
  • Posts: 367
initget and entsel
« on: February 11, 2008, 01:28:58 PM »
Below is a snipet of code I would like some assistance on. I need to do some distance calculations based on some previous parameters (already partially coded) and the following code needing to establish variable "pt3". This variable will either be the center of a selected arc OR a point selected on screen by the user. I would like the arc selection to be used as default, if the user decides to use [Point] option, type "P" or "point" (kword type function?) and then prompt for point. I think the issue is entsel not allowing initget 128 (arbituary values) or am I way off? Any suggestions or guidance would be appreciated.

Code: [Select]
  (if (= pt3 nil)
   (progn
    (initget 128 "Point")
    (setq arc1 (car (entsel "\nSelect Arc or [Point]: ")))
    (cond
     ((setq pt3 (cdr (assoc 10 (entget arc1))))T)   ; pt3 is the arc center point
     ((= arc1 "Point")(setq pt3 (getpoint "\nSelect center point: ")))
    ) ; cond
   
   ) ; progn
  ) ; if

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: initget and entsel
« Reply #1 on: February 11, 2008, 01:42:47 PM »
Maybe this:
Code: [Select]
  (if (= pt3 nil)
   (progn
    (initget 128 "Point")
    (setq arc1 (entsel "\nSelect Arc or [Point]: "))
    (cond
     ((= arc1 "Point")(setq pt3 (getpoint "\nSelect center point: ")))
     ((listp arc1)
      (setq pt3 (cdr (assoc 10 (entget (car arc1)))))T)   ; pt3 is the arc center point
    ) ; cond
   
   ) ; progn
  ) ; if
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

DanB

  • Bull Frog
  • Posts: 367
Re: initget and entsel
« Reply #2 on: February 11, 2008, 02:01:36 PM »
Well I wasn't too far off base  :-) Was my error mainly in the order of my cond statements and/or the addition of listp? For curiousity I did try and comment out the "(listp arc1)" and was still able to pass, is this not a good idea?

Thanks for the help.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: initget and entsel
« Reply #3 on: February 11, 2008, 02:28:03 PM »
Your problem was the (car because the "Point" entry is not a list, it is a string & causes an error.
Code: [Select]
(setq arc1 [color=red](car[/color] (entsel "\nSelect Arc or [Point]: ")))I would use something like this:
Code: [Select]
  (if (null pt3)
    (while
      (cond
        ((not (or
                (initget 128 "Point")
                (setq arc1 (entsel "\nSelect Arc or [Point]: "))
              )
         )
         (prompt "\nNull response not allowed, try again.")
         t          ; stay in loop
        )
        ((= arc1 "Point")
         (initget 1)
         (if (listp (setq pt3 (getpoint "\nSelect center point: ")))
           nil      ; exit loop
           (princ "\nInvalid response, Try again.") ; stay in loop
         )
        )
        ((= (cdr (assoc 0 (setq elst (entget (car arc1))))) "ARC")
         (setq pt3 (cdr (assoc 10 elst))) ; pt3 is the arc center point
         nil        ; exit loop
        )
        ((princ "\nThe Object selected is not an Arc, Try again.")
         t          ; stay in loop
        )
      )             ; cond

    )               ; progn
  )                 ; if
« Last Edit: February 11, 2008, 02:43:03 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

DanB

  • Bull Frog
  • Posts: 367
Re: initget and entsel
« Reply #4 on: February 11, 2008, 02:33:47 PM »
That was my next step, to test for proper selection of an arc entity. Thanks for that one too.

Adesu

  • Guest
Re: initget and entsel
« Reply #5 on: February 11, 2008, 06:56:16 PM »
Hi DanB,
it's code is more popular
Code: [Select]
(if
  (= pt3 nil)
  (progn
    (setq arc1 (car (entsel "\nSelect Arc or [Point]: ")))
    (if (= arc1 nil)(setq arc1 "Point"))
    (bla...bla...