initget for ssget?

Discussion in 'AutoCAD' started by Allen Johnson, Aug 19, 2004.

  1. I'd like to have an initget option for the ssget function, but it doesn't appear to be possible.
    Does anyone know of a method?

    Current function:
    (defun c:jp( / sset) ;; Sets fuzz factor and keeps it as a global
    (setq ss (ssget '((0 . "LINE,ARC,LWPOLYLINE"))))
    (setq jp_ffac (getdefault "fuzz factor" (if jp_ffac jp_ffac 4) 2))
    (if ss (command "pedit" "m" ss "" "y" "j" "j" "b" jp_ffac "X"))
    (princ)
    )

    Produces:

    Command: JP
    Select objects: Specify opposite corner: 4 found
    Select objects: Enter fuzz factor <4.0000>:
    pedit Select polyline or [Multiple]: m
    Select objects: 4 found
    .....

    In the code above, rather than asking for the fuzz factor after the ssget, I'd like it to be an
    option when the command starts:

    Command: jp
    Select Objects or [F]uzz to set fuzz factor (= 4.0000): F
    Enter fuzz factor <4.0000>: 6.00
    Select Objects of [F]uzz to set fuzz factor (= 6.0000): Specify opposite corner: 3 found

    Any ideas?
     
    Allen Johnson, Aug 19, 2004
    #1
  2. So just move the statement above the (ssget).

    --
    R. Robert Bell


    I'd like to have an initget option for the ssget function, but it doesn't
    appear to be possible.
    Does anyone know of a method?

    Current function:
    (defun c:jp( / sset) ;; Sets fuzz factor and keeps it as a global
    (setq ss (ssget '((0 . "LINE,ARC,LWPOLYLINE"))))
    (setq jp_ffac (getdefault "fuzz factor" (if jp_ffac jp_ffac 4) 2))
    (if ss (command "pedit" "m" ss "" "y" "j" "j" "b" jp_ffac "X"))
    (princ)
    )

    Produces:

    Command: JP
    Select objects: Specify opposite corner: 4 found
    Select objects: Enter fuzz factor <4.0000>:
    pedit Select polyline or [Multiple]: m
    Select objects: 4 found
    .....

    In the code above, rather than asking for the fuzz factor after the ssget,
    I'd like it to be an
    option when the command starts:

    Command: jp
    Select Objects or [F]uzz to set fuzz factor (= 4.0000): F
    Enter fuzz factor <4.0000>: 6.00
    Select Objects of [F]uzz to set fuzz factor (= 6.0000): Specify opposite
    corner: 3 found

    Any ideas?
     
    R. Robert Bell, Aug 19, 2004
    #2
  3. So just move the statement above the (ssget).

    But, if I don't want to change the fuzz, I still have to waste a step in keying enter, rather than
    just starting the object selection.
    Sort of like the Trim command allows you to select the object to trim or key in one of the available
    options:


    Command: tr TRIM
    Current settings: Projection=UCS, Edge=Extend
    Select cutting edges ...
    Select objects: 1 found
    Select object to trim or shift-select to extend or [Project/Edge/Undo]:

    However, I'm sure the trim command uses the (entsel) method, so that the routine can respond to the
    pick point. Unfortunately, the (ssget) methods don't appear to allow for entering other keys than
    the standard

    Expects a point or
    Window/Last/Crossing/BOX/ALL/Fence/WPolygon/CPolygon/Group/Add/Remove/Multiple/Previous/Undo/AUto/SI
    ngle

    options.
     
    Allen Johnson, Aug 20, 2004
    #3
  4. In case anyone is interested, here's what I finally came up with:

    (defun c:jp (/ objfilter ss pss pp np en i)

    ;; Sets fuzz factor and keeps it as a global
    (if (not jp_ffac)
    (setq jp_ffac 4.0)
    )

    ;; A method to be able to add options to the ssget function.
    ;; First have the user select a point, but use the initget function
    ;; to allow the user to enter an option (Fuzz in this case). If the
    ;; user selects the option, ask for the fuzz distance, else check to
    ;; see if there is an object at the point. If so, create a preliminary
    ;; selection set (pss) containing the object. If nothing is at that point,
    ;; then ask for the next point. Depending on the direction of that point,
    ;; create the preliminary selection set by either a crossing or enclosed
    ;; window. If there's anything in the pss, highlight the objects selected.
    ;; Next use the standard (ssget) to continue selection (ss). After any
    ;; additional objects are selected, append the preliminary selection set
    ;; to the standard set.

    (setq objfilter "LINE,ARC,LWPOLYLINE"
    pp "Fuzz"
    )

    ;; Get the first point
    (initget pp)
    (while (= pp "Fuzz")
    (setq
    pp (getpoint
    (strcat "Select objects or [F]uzz to enter fuzz factor <"
    (rtos jp_ffac)
    ">: "
    )
    )
    )
    (cond ((= pp "Fuzz")
    (setq np (getdist (strcat "Enter fuzz factor <" (rtos jp_ffac) ">:"))
    jp_ffac (if np
    np
    jp_ffac
    )
    )
    )
    )

    )

    ;; create the preliminary selection set (pss)...
    (cond
    ;; no point returned, don't do anything
    ((= pp nil)
    )
    ;; point picked has an object under it, so add it to pss
    ((setq en (nentselp pp))
    (setq pss (ssadd))
    ;; check to see if the object selected matches the filter list...
    (if (wcmatch (cdr (assoc 0 (entget (car en)))) objfilter)
    (ssadd (car en) pss)
    )
    )
    ;; no object under point so create a windowed selection set
    ((= (type pp) 'LIST)
    (setq np (getcorner pp "Other Corner: ")

    )
    (setq pss (ssget
    (if (< (car (mapcar '- np pp)) 0)
    "C"
    "W"
    )
    np
    pp
    (list (cons 0 objfilter))
    )
    )
    )
    )
    ;; highlight any objects in pss
    (setq i 0)
    (if pss
    (repeat (sslength pss)
    (redraw (ssname pss i) 3)
    (setq i (1+ i))
    )
    )

    (if pp
    ;; i.e. not nil..
    ;; create the standard selection set...
    (setq ss (ssget (list (cons 0 objfilter))))
    )

    ;; create a new selection set, if empty
    (if (not ss) (setq ss (ssadd)))

    (setq i 0)
    ;; append the preliminary selection set to the standard set
    (if pss
    (repeat (sslength pss)
    (ssadd (ssname pss i) ss)
    (setq i (1+ i))
    )
    )

    (setq pp (getvar "Peditaccept"))
    (setvar "Peditaccept" 1)
    (if (not (zerop (sslength ss)))
    (command "pedit" "m" ss "" "j" "j" "b" jp_ffac "X")
    )
    (setvar "Peditaccept" pp)
    (princ)
    )
     
    Allen Johnson, Aug 20, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.