Author Topic: Clean up lisp  (Read 392 times)

0 Members and 1 Guest are viewing this topic.

notredave

  • Newt
  • Posts: 137
Clean up lisp
« on: September 07, 2021, 10:39:44 AM »
Good morning all,

I used to use this lisp built into my main lisp that loads when I start autocad but it's not working on release 2020 & 2021. I would type mk and click on a line or pline and it would start a line on correct layer and linetype also with text. It's an old lisp from release 10, lol but it used to work. Also, could mtext be incorporated with this lisp? If someone can make this work with latest autocad, I would greatly appreciate it.

ronjonp, you have helped me plenty of times so you may be excused, lol.

Thank you,
David

CodeDing

  • Newt
  • Posts: 24
Re: Clean up lisp
« Reply #1 on: September 07, 2021, 11:49:36 AM »
notredave,

Why do you have a global "command" definition? Have you defined this function BEFORE calling your MK command? It is not attached.

Code: [Select]
(*command* ...)
Best,
~DD

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9718
Re: Clean up lisp
« Reply #2 on: September 07, 2021, 12:11:12 PM »
I also cannot comment on the code's ability to work or not but I thought I'd share some very old helper routines of mine which may help you.

Code - Auto/Visual Lisp: [Select]
  1. ;;;===================================================================;
  2. ;;; selected-p                                                        ;
  3. ;;;-------------------------------------------------------------------;
  4. ;;; This function will test to see if something is selected on screen ;
  5. ;;;                                                                   ;
  6. ;;; Returns: T or nil                                                 ;
  7. ;;;                                                                   ;
  8. ;;; Author: John Kaul                                                 ;
  9. ;;;                                                                   ;
  10. ;;; Usage: (if (not (selected-p))                                     ;
  11. ;;;          (vlax-ename->vla-object (car (entsel))))                 ;
  12. ;;;===================================================================;
  13. (defun selected-p ()
  14.   (and (cadr (ssgetfirst))))
  15.  
  16. ;;;===================================================================;
  17. ;;; Get-Selected                                                      ;
  18. ;;;-------------------------------------------------------------------;
  19. ;;; This function will offer a way for the programer to get an        ;
  20. ;;; entity or entities already slected on the screen before the       ;
  21. ;;; program took control. This program was intended for use in an     ;
  22. ;;; ActiveX program. I have chosen not to use the "Pickfirst" method  ;
  23. ;;; in accomplishing this task because I wanted a way to do this even ;
  24. ;;; if the "pickfirst" variable was toggled to zero. If no entity is  ;
  25. ;;; currently selected on the screen, this function will prompt the   ;
  26. ;;; end user to select an entity.                                     ;
  27. ;;;                                                                   ;
  28. ;;; Author: John Kaul                                                 ;
  29. ;;;                                                                   ;
  30. ;;; Returns: Either previously selected entity, a selected entity, or ;
  31. ;;;          a list of selected entities.                             ;
  32. ;;;                                                                   ;
  33. ;;; Usage: (vlax-ename->vla-object (get-selected))                    ;
  34. ;;;                                                                   ;
  35. ;;;-------------------------------------------------------------------;
  36. ;;; Version: 1.1 Added the ability to have more then one selected     ;
  37. ;;;              objects on the screen.                               ;
  38. ;;;===================================================================;
  39. (defun get-selected (/ x cntr xlength xlist)
  40.   (setq x (cadr (ssgetfirst)))
  41.   (if x (setq xlength (sslength x)))
  42.   (cond
  43.     ((= xlength 1)
  44.      (setq x (ssname x 0))
  45.      (sssetfirst nil)
  46.      (redraw x 3))
  47.     ((> xlength 1)
  48.      (setq cntr xlength)
  49.      (cond
  50.        ((>= cntr 2)
  51.         (setq cntr (1- xlength))
  52.         (while (>= cntr 0)
  53.                (setq xlist (cons (ssname x cntr) xlist)
  54.                      cntr  (1- cntr)))
  55.         ;; For higlighting entities
  56.         ;; (foreach a xlist (progn (sssetfirst nil) (redraw a 3)))
  57.         )))
  58.     ;; ((= xlength nil)
  59.     ;;  (while (not (setq x (entsel "\nselect object: "))))
  60.     ;;  (setq x (car x))
  61.     ;;  (sssetfirst nil)
  62.     ;;  ;; For higlighting entities
  63.     ;;  ;; (redraw x 3)
  64.     ;;  )
  65.     )
  66.   (if (= nil xlist) x xlist)
  67. )

Code: [Select]
(if (selected-p) (setq ss-list (get-selected)))
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

BIGAL

  • Swamp Rat
  • Posts: 829
  • 30 + years of using Autocad
Re: Clean up lisp
« Reply #3 on: September 07, 2021, 08:32:04 PM »
Maybe this
A man who never made a mistake never made anything

notredave

  • Newt
  • Posts: 137
Re: Clean up lisp
« Reply #4 on: September 08, 2021, 08:01:18 AM »
BIGAL,

Thank you very much for looking into this. I really appreciate it. It's not working when I click on a line or circle, it stays on current layer. Also,
when I load my dp.lsp which contains the lisp you just wrote, it says COMINV in command bar. The old mk.lsp also worked on text. I will post the lisp you just wrote/cleaned up again. BTW, I renamed it back to mk.lsp

Thank you,
David P.

tombu

  • Bull Frog
  • Posts: 246
  • ByLayer=>Not0
Re: Clean up lisp
« Reply #5 on: September 10, 2021, 01:13:04 PM »
Why not just use the ADDSELECTED (Command)?
Creates a new object of the same type and general properties as a selected object, but with different geometric values.
https://help.autodesk.com/view/ACD/2022/ENU/?guid=GUID-771C0F16-58B6-4752-A05D-792FE5D76050
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

notredave

  • Newt
  • Posts: 137
Re: Clean up lisp
« Reply #6 on: September 13, 2021, 02:04:16 PM »
Thank you tombu. I did not know about that command.
David