Author Topic: Hop Lisp question  (Read 8495 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
Hop Lisp question
« on: October 05, 2004, 01:42:33 PM »
I've put together this lisp (with help from others). My question is: Why is the arc endpoint  inconsistent when there is another pline in the path of the break selection.
If there is nothing in the way, the lisp works perfect.

1. Pick pline to extract plwid and layer.
2. Select breakpoints.
3. Polyline Arc is drawn from break point 1 using center method (center point used is the midpoint between break point 1 and 2) and end at break point 2.
4. Arc is pedit joined to adjacent plines by using a crossing window from pt1 to pt2.


Thanks,

Ron



Code: [Select]
(defun c:hop (/    csnaps pwid  ent   b  c w     col
     PT1   X1  Y1 Z1    PT2   x2  y2 z2    xmid
     ymid  zmid  mpt clay  pbox  ap  onerr
    )

(command ".undo" "begin")

  (defun errhand (err)
    (if (/= err "Function cancelled")
      (princ (strcat "\nError: " err))
    )
    (command ".layer" "set" clayer "")
    (setvar 'osmode csnaps)
    (setvar 'plinewid pwid)
    (setvar 'pickbox pbox)
    (setvar 'aperture ap)
    (setq *error* onerr)
    (princ)
  )

  (setq csnaps (getvar 'osmode)
      clay   (getvar 'clayer)
      pwid   (getvar 'plinewid)
pbox   (getvar 'pickbox)
ap     (getvar 'aperture)
  )

  (setq onerr *error*)
  (setvar 'osmode 0)
  (setvar 'osmode 512)
  (setvar 'pickbox 8)
  (setvar 'aperture 8)
  (setq *error* errhand)
(princ "\n **Don't zoom in too close for selection for best results**")
(setq ent (entsel "\nSelect Polyline to Hop.."))
  (if (= (cdr (assoc 0 (entget (car ent)))) "LWPOLYLINE")
    (progn
      (setq b (car ent))
      (setq c (entget b))
      (setq w (cdr (assoc 40 c))) ;get polyline width
      (setq col (cdr (assoc 8 c))) ;get polyline layer        
    )
  )
  (setq onerr *error*)
  (setvar 'clayer col)  
  (setvar 'plinewid w)
  (setq *error* errhand)

;Marks Code to get midpoint between 2 points

  (initget 1)
  (setq PT1 (getpoint "\nFirst Break point...: "))
  (setq X1 (car PT1))
  (setq Y1 (cadr PT1))
  (setq Z1 (caddr PT1))
  (initget 1)
  (setq PT2 (getpoint PT1 "\nSecond Break point...: "))
  (setq X2 (car PT2))
  (setq Y2 (cadr PT2))
  (setq Z2 (caddr PT2))
  (setq XMID (/ (+ X1 X2) 2))
  (setq YMID (/ (+ Y1 Y2) 2))
  (setq ZMID (/ (+ Z1 Z2) 2))
  (setq MPT (list XMID YMID ZMID))

;break line and insert arc polyline between break
  (command ".break" ent "f" pt2 pt1)
  (command ".pline" pt1 "arc" "ce" mpt pt2 "")
  (command ".pedit" "last" "join" ent "cr" pt1 pt2 "" "")
  (command ".undo" "end")

;return user settings

  (setvar 'clayer clay)  
  (setvar 'osmode csnaps)
  (setvar 'plinewid pwid)
  (setvar 'pickbox pbox)
  (setvar 'aperture ap)
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Hop Lisp question
« Reply #1 on: October 05, 2004, 01:47:44 PM »
turn osnaps off when adding objects with a command.
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.

ronjonp

  • Needs a day job
  • Posts: 7529
Hop Lisp question
« Reply #2 on: October 05, 2004, 01:52:49 PM »
Thanks CAB  :D . That was an easy fix! It's those little things that drive drive you crazy!

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

daron

  • Guest
Hop Lisp question
« Reply #3 on: October 06, 2004, 08:21:32 AM »
One "module" you might try using is Se7en's ToggleSnaps function. I've gotten in the habit of using it. I like it because, if a user is hitting escape and does it fast or repeatedly enough, (s)he can even cancel the error trap, thus disabling proper resetting of variables. If this happens, all you have to do is hit F3 and your osnaps are turned back on.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Hop Lisp question
« Reply #4 on: October 06, 2004, 08:48:35 AM »
What Daron said :)
Code: [Select]
;;;===================================================================;
;;; SetOsnaps                                                         ;
;;;-------------------------------------------------------------------;
;;; This function accepts a integer of 1 or 0 (on or off) to set the  ;
;;; end users osnap value to enabled or disabled.                     ;
;;;                                                                   ;
;;; Argument: 1 = Enable the users osnaps                             ;
;;;           0 = Disable the users osnaps                            ;
;;;                                                                   ;
;;; Usage: (SetOsnap 1) or (SetOsnap 0)                               ;
;;;                                                                   ;
;;; Author: John Kaul                                                 ;
;;;===================================================================;
(defun SetOsnaps (value)
  (cond
    ((= value 1); set ON
     (if (>= (getvar "osmode") 15359)
         (setvar "osmode" (boole 6 (getvar "osmode") 16384))
     )
    )
    ((= value 0); set OFF
     (if  (<= (getvar "osmode") 15359)
       (setvar "osmode" (boole 6 (getvar "osmode") 16384))
     )
    )
  )
  (princ)
)
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.

whdjr

  • Guest
Hop Lisp question
« Reply #5 on: October 06, 2004, 09:03:30 AM »
CAB,

Am I missing something or are your setvar statements exactly the same?

whdjr

  • Guest
Hop Lisp question
« Reply #6 on: October 06, 2004, 09:08:36 AM »
Could it be as simple as:
Code: [Select]
(defun c:toggle ()
  (setvar "osmode" (boole 6 (getvar "osmode") 16384))
)

SMadsen

  • Guest
Hop Lisp question
« Reply #7 on: October 06, 2004, 09:17:04 AM »
The thing that puzzles me is how do you provide an argument to a command? :D

Will, your eyes are not fooling you. It could be as simple as your C:TOGGLE but Se7en's routine is acting on a wish that says: if OSNAP is already turned off then don't turn it back on if you wish it to be off.

IMHO, the value to check should be 16383 because the QUICK osnap (1024) is just as valid as the rest.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Hop Lisp question
« Reply #8 on: October 06, 2004, 09:20:37 AM »
Quote from: whdjr
CAB,

Am I missing something or are your setvar statements exactly the same?

Actually they are John's and yes they are the same.
Here is the toggle I use
Code: [Select]
(defun C:ostoggle ()
  (cond
    ((= (getvar "osmode") 0) ;none set so set
     (setvar "osmode" 175); On & set to my favorite
    )

    ;;  Already set so toggle
    ((setvar "osmode" (boole 6 (getvar "osmode") 16384))
    )
   
  ) ; end cond
  (princ)
) ; end defun



But you do NOT want to toggle, you want to force ON or OFF
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.

SMadsen

  • Guest
Hop Lisp question
« Reply #9 on: October 06, 2004, 09:23:49 AM »
CAB, did you put the "c:" into Se7en's function??

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Hop Lisp question
« Reply #10 on: October 06, 2004, 09:30:55 AM »
Quote from: SMadsen
CAB, did you put the "c:" into Se7en's function??
I may have, but I don't see it there now. :)
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.

SMadsen

  • Guest
Hop Lisp question
« Reply #11 on: October 06, 2004, 09:39:35 AM »
<Homer mode> Why, you little ...!! </Homer mode>

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
Hop Lisp question
« Reply #12 on: October 06, 2004, 09:57:53 AM »
Actualy those conditions differ by one thing; the logical test in the IF statement. the code looks redundant, but half of the code is never itterated thru because of the conditional test. -ie if the test evaluates to nil (or not true) then the lines of code in that block is never evaluated at all.

But if it makes you feel better, you can re-write that procedure to have a "localised" helper.

Check this out:
Code: [Select]
(defun SetOsnaps (value)
  (defun SetOsnaps-helper (test)
    (if (test (getvar "osmode") 16383)
      (setvar "osmode" (boole 6 (getvar "osmode") 16384))))
  (cond
    ((= value 1); set OFF
                  (SetOsnaps-helper >=))
    ((= value 0); set OFF
                  (SetOsnaps-helper <=))
    )
  (princ)
  )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
Hop Lisp question
« Reply #13 on: October 06, 2004, 09:58:42 AM »
Oh by the way, i changed the value Stig.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SMadsen

  • Guest
Hop Lisp question
« Reply #14 on: October 06, 2004, 10:05:37 AM »
.. or with a little AND/OR exercise:

Code: [Select]
(defun SetOsnaps (value / osm)
  (setq osm (getvar "OSMODE"))
  (if (or (and (= value 1) (> osm 16383))
          (and (= value 0) (<= osm 16383))
      )
    (setvar "osmode" (boole 6 (getvar "osmode") 16384))
  )
)


John, yes I noticed you changed it :)

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
Hop Lisp question
« Reply #15 on: October 06, 2004, 10:24:03 AM »
Nice!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SMadsen

  • Guest
Hop Lisp question
« Reply #16 on: October 06, 2004, 10:53:31 AM »
If it weren't for a small glitch .. changed (>= osm 16383) to (> osm 16383).
Otherwise it turns off osnaps when you ask it to turn it on and all osnaps are already on at once.

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
Hop Lisp question
« Reply #17 on: October 06, 2004, 11:02:00 AM »
Oh, well to tell ya the truth; i didnt get past the "or-and" before i said that so. I guess ill have to take that "Nice!" comment back and go with a "*eh*" or a "*sigh* I guess its ok" comment.  Sorry Stig, its the little things that got ya.

:P
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org