Author Topic: OSNAP issue with redefined line commands  (Read 1897 times)

0 Members and 1 Guest are viewing this topic.

ROBBO

  • Bull Frog
  • Posts: 217
OSNAP issue with redefined line commands
« on: December 08, 2014, 10:04:13 AM »
Hi, I have be using redefined pline and line commands for some time without any problems until now. I am using AutoCAD 2014. When my osmode is set to 37 for example and I have a circle with a line running through it - when I use the line or pline command in the lisp below, although the centre is highlighted the new line drawn snaps to the end point of the line as shown in the image below. Any ideas or help would be appreciated. Kr. Robbo.

Lisp Routine:
Code - Auto/Visual Lisp: [Select]
  1. ;;-------------------------------------------------------------------------------
  2. ;;LINE
  3. ;;-------------------------------------------------------------------------------
  4. (command "undefine" "line")
  5. (defun c:line (/ cmdsave)
  6.   (setq cmdsave (getvar "cmdecho"))
  7.   (setvar "cmdecho" 0)
  8.   ;;(princ "\nShouldn't you be using PLINE?")
  9.   (command ".LINE")
  10.   (setvar "cmdecho" cmdsave)
  11.   (princ)
  12. )
  13.  
  14. c:line
  15. ;;-------------------------------------------------------------------------------
  16. (defun c:line () (c:cline))
  17. (defun c:l () (c:cline))
  18. ;;-------------------------------------------------------------------------------
  19. (defun c:cline
  20.                ;; CLine - Continue line
  21.                ;;
  22.                ;; This procedure is ment to be a replacement for the line command.
  23.                ;; Although it uses the defualt line command for its core opperation
  24.                ;; it changes the current layer to that of an entity selected.
  25.                ;; If an object is not detected, the current layer is used.
  26.                ;;
  27.                ;; UPDATE: See revisions. I removed the selection of an xref.
  28.                ;;
  29.                ;; By: John Kaul
  30.                ;; Date: 05.14.06
  31.                ;;
  32.                ;; Revison log: 0.1
  33.                ;; 0.2 -- Removed xrefs from becoming ``objects''.
  34.                ;; 0.3 -- Cleaned up a variable left declaired.
  35.                ;; 0.4 -- Fixed a major boo-boo when I changed
  36.                ;; to a diff error trap. (04.30.07)
  37.                (/
  38.                 ;; variables
  39.                 lay x
  40.                 ;; procedures...
  41.                 vl-put-activelayer getpointobj vl-put-objlayercurrent awesh0t
  42.                )
  43.   (
  44.    (lambda ()
  45.      ;; get the point from the user.
  46.      (while (not (setq x (getpoint "\nShouldn't you be using PLINE?\nSelect Point: ")))
  47.        (princ "\nYou did not select a point, please try again. ")
  48.      )
  49.      x
  50.    )
  51.   )
  52.   ;; if we've came this far in the routine...
  53.   ;; set up error handler.
  54.   ;;
  55.   ;; NOTE: Leave as seperate proced for now.
  56.   (defun awesh0t (s)
  57.     (setq *error* olderr
  58.           olderr  nil
  59.     )
  60.     (setvar 'clayer lay)
  61.     (princ)
  62.   )
  63.   (setq olderr  *error*
  64.         *error* awesh0t
  65.   )
  66.   ;; and some other routines we will need.
  67.   (defun vl-put-activelayer (name / x)
  68.     ;; (setq obj (getpointobj pnt))
  69.     (cond
  70.       (name
  71.        (and
  72.          (vla-put-activelayer x (vla-add (vla-get-layers x) name))
  73.        )
  74.       )
  75.     )
  76.   )
  77.   (defun getpointobj (pt / obj pt)
  78.     (setvar "LASTPOINT" pt)
  79.     (cond
  80.       ((ssget pt)
  81.        (setq pt (ssname (ssget pt) 0))
  82.        (cond
  83.          ;; disable xref objects from the list of items.
  84.          ;; if we get any further objects to eliminate, redo
  85.          ;; entire lisp.
  86.          ((assoc 2 (entget pt))
  87.           (not (assoc 1 (tblsearch "BLOCK" (cdr (assoc 2 (entget pt))))))
  88.          )
  89.          ;; otherwise just create an object from picked point.
  90.          ((setq obj (vlax-ename->vla-object pt)))
  91.        )
  92.       )
  93.     )
  94.     obj
  95.   )
  96.   (defun vl-put-objlayercurrent (obj)
  97.     (cond (obj (vl-put-activelayer (vlax-get-property obj 'layer))))
  98.   )
  99.   ;; Now that we have support procedures set up, we can now get on with the work.
  100.   (setq lay (getvar 'clayer))
  101.   (vl-put-objlayercurrent (setq obj (getpointobj x)))
  102.   (princ "\n ")
  103.   (command ".line" x)
  104.   ;;LINE UPDATED AND REVISED BY ROBBO@theswamp.org
  105.   (while (eq (getvar 'cmdactive) 1)
  106.     (command pause)
  107.   )
  108.   (awesh0t nil)
  109. )
  110. ;;-------------------------------------------------------------------------------
  111. ;;POLYLINE
  112. ;;-------------------------------------------------------------------------------
  113. (command "undefine" "pline")
  114. (defun c:pline (/ cmdsave)
  115.   (setq cmdsave (getvar "cmdecho"))
  116.   (setvar "cmdecho" 0)
  117.   ;;(princ "\nUse CPLINE to continue polyline")
  118.   (command ".PLINE")
  119.   (setvar "cmdecho" cmdsave)
  120.   (princ)
  121. )
  122.  
  123. c:pline
  124. ;;-------------------------------------------------------------------------------
  125. (defun c:polyline () (c:pline2))
  126. (defun c:pline () (c:pline2))
  127. (defun c:pl () (c:pline2))
  128. (defun c:_pline () (c:pline2))
  129. ;;-------------------------------------------------------------------------------
  130. (defun c:pline2
  131.                 (/ lay x vl-put-activelayer getpointobj vl-put-objlayercurrent awesh0t
  132.                 )
  133.   (
  134.    (lambda ()
  135.      (while (not (setq x (getpoint "\nUse CPLINE to continue polyline.\nSelect Point: ")))
  136.        (princ "\nYou did not select a point, please try again. ")
  137.      )
  138.      x
  139.    )
  140.   )
  141.   (defun awesh0t (s)
  142.     (setq *error* olderr
  143.           olderr  nil
  144.     )
  145.     (setvar 'clayer lay)
  146.     (princ)
  147.   )
  148.   (setq olderr  *error*
  149.         *error* awesh0t
  150.   )
  151.   (defun vl-put-activelayer (name / x)
  152.     ;; (setq obj (getpointobj pnt))
  153.     (cond
  154.       (name
  155.        (and
  156.          (vla-put-activelayer x (vla-add (vla-get-layers x) name))
  157.        )
  158.       )
  159.     )
  160.   )
  161.   (defun getpointobj (pt / obj pt)
  162.     (setvar "LASTPOINT" pt)
  163.     (cond
  164.       ((ssget pt)
  165.        (setq pt (ssname (ssget pt) 0))
  166.        (cond
  167.          ((assoc 2 (entget pt))
  168.           (not (assoc 1 (tblsearch "BLOCK" (cdr (assoc 2 (entget pt))))))
  169.          )
  170.          ((setq obj (vlax-ename->vla-object pt)))
  171.        )
  172.       )
  173.     )
  174.     obj
  175.   )
  176.   (defun vl-put-objlayercurrent (obj)
  177.     (cond (obj (vl-put-activelayer (vlax-get-property obj 'layer))))
  178.   )
  179.   (setq lay (getvar 'clayer))
  180.   (vl-put-objlayercurrent (setq obj (getpointobj x)))
  181.   (princ "\n ")
  182.   (command ".pline" x)
  183.   (while (eq (getvar 'cmdactive) 1)
  184.     (command pause)
  185.   )
  186.   (awesh0t nil)
  187. )
  188. ;;-------------------------------------------------------------------------------

//edit: code reformatted by CAB//
« Last Edit: December 09, 2014, 08:20:13 AM by CAB »
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: OSNAP issue with redefined line commands
« Reply #1 on: December 08, 2014, 12:17:14 PM »
Try replacing
Code: [Select]
(command ".pline" x)With
Code: [Select]
(command "_.pline" "_none" x)
Do you really write code without indentations?? :-o

ROBBO

  • Bull Frog
  • Posts: 217
Re: OSNAP issue with redefined line commands
« Reply #2 on: December 09, 2014, 02:03:02 AM »
Thank you roy_43.

This appears to solve the issue.

Kr. Robbo.
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: OSNAP issue with redefined line commands
« Reply #3 on: December 09, 2014, 05:53:54 AM »
Do you really write code without indentations?? :-o
Might be due to copy-paste issues. I've found that I loose formatting every time I'm forced to use Internet Explorer. Not too difficult to imagine something else also giving troubles.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: OSNAP issue with redefined line commands
« Reply #4 on: December 09, 2014, 08:20:56 AM »
Code reformatted.
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.

ROBBO

  • Bull Frog
  • Posts: 217
Re: OSNAP issue with redefined line commands
« Reply #5 on: December 09, 2014, 08:37:07 AM »
Code reformatted.


CAB, very Kind of you.

Cheers, Robbo.
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)