Results 1 to 5 of 5

Thread: Object selection using lisp

  1. #1
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    385
    Login to Give a bone
    0

    Cool Object selection using lisp

    Hey everyone,
    I wrote a lisp that works OK however there has to be a better way of selecting then what I have done. Ive used last and previous, throughout my lisp,to build my selection. Can someone tell me an easier/better way to do this?
    Thank you all in advance,
    Andre

    Code:
    (defun c:reduct (/ currlay rdpt1 sz1 sz2)
      (setq currlay (getvar "Clayer"))
      (setq redpt1 (getpoint "\nSelect insertion point of reducer: "))
      (setq sz1 (getdist "\nEnter width of old duct: "))
      (setq sz2 (getdist "\nEnter width of new duct: "))
      (setvar "clayer" "0")
      (command "line" redpt1 (strcat "@0," (rtos sz1)) "")
      (command "move" "last" "" (list 0 0)(list 0 0))
      (setvar "clayer" "Duct")
      (command "line" "" (strcat "@" (rtos (* sz1 1.10))"," (rtos(- sz2 sz1))) "")
      (command "move" "previous" "last" "" (list 0 0)(list 0 0))
      (setvar "clayer" "0")
      (command "line" "" (strcat "@0," (rtos (* sz2 -1))) "")
      (command "move" "previous" "last" "" (list 0 0)(list 0 0))
      (setvar "clayer" "Duct")
      (command "pline" "" redpt1 "")
    [ Moderator Action = ON ] What are [ CODE ] tags... [ Moderator Action = OFF ]
    Last edited by Opie; 2006-10-24 at 05:20 PM. Reason: [CODE] tags added, see Moderator Action

  2. #2
    All AUGI, all the time Avatart's Avatar
    Join Date
    2004-06
    Location
    Upsidedown in dreamtown
    Posts
    928
    Login to Give a bone
    0

    Default Re: Object selection using lisp

    Quote Originally Posted by ReachAndre
    Hey everyone,
    I wrote a lisp that works OK however there has to be a better way of selecting then what I have done. Ive used last and previous, throughout my lisp,to build my selection. Can someone tell me an easier/better way to do this?
    Thank you all in advance,
    Andre
    I would generally do it through creating a selection set, using the SSGET function. See the help system in the VLIDE for more info.
    Last edited by Opie; 2006-10-24 at 05:21 PM. Reason: fixed quote tag

  3. #3
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Object selection using lisp

    Hi Andre, maybe your code is broken, but I can not see the reason why you need to do "previous" and "last" you can skip all those lines, but if I assume that you want the whole duct in previous you can try this modified code.
    Code:
    (defun c:reduct (/ currlay rdpt1 sz1 sz2 SelSet )
      (setq currlay (getvar "CLAYER" ) )
      (setq redpt1 (getpoint "\nSelect insertion point of reducer: " ) )
      (setq sz1 (getdist "\nEnter width of old duct: " ) )
      (setq sz2 (getdist "\nEnter width of new duct: " ) )
      (setq SelSet (ssadd) ) ;; Create a placeholder
      (setvar "CLAYER" "0" )
      (command "line" redpt1 (strcat "@0," (rtos sz1 )) "" )
      (setq SelSet (ssadd  (entlast) SelSet )) ;; Add last created object to SelSet
      (setvar "CLAYER" "Duct" ) ; <- will bomb if the layer do not exist
      (command "line" "" (strcat "@" (rtos (* sz1 1.10 ) ) "," (rtos(- sz2 sz1 ))) "" )
      (setq SelSet (ssadd  (entlast) SelSet )) ;; Add last created object to SelSet
      (setvar "CLAYER" "0" )
      (command "line" "" (strcat "@0," (rtos (* sz2 -1 ))) "" )
      (setq SelSet (ssadd  (entlast) SelSet )) ;; Add last created object to SelSet
      (setvar "CLAYER" "Duct" )
      (command "pline" "" redpt1 "" )
      (setq SelSet (ssadd  (entlast) SelSet )) ;; Add last created object to SelSet
      (command "select" SelSet "" ) ;; Activate SelSet in previous
      (princ)
    )
    ;;; Now you can try
    ;;; Command: COPY Select objects: p
    When you use "last" it is the last created object that you can see in the screen ( it is pan and zoom dependent )
    when you use (entlast) it really is the last created object in the database.

    : ) Happy Computing !

    kennet
    Last edited by kennet.sjoberg; 2006-10-24 at 05:46 PM. Reason: added layer comment

  4. #4
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    385
    Login to Give a bone
    0

    Default Re: Object selection using lisp

    OK everyone I have fixed my code so that it does the following:
    adds "makes" layer "Duct" to prevent bombing.
    Also Allows me to rotate all of my new object.
    Thanks to everyone for all your help.

    Code:
    (defun c:reduct (/ currlay redpt1 sz1 sz2 SelSet )
      (setq currlay (getvar "CLAYER" ) )
      (setq redpt1 (getpoint "\nSelect insertion point of reducer: " ) )
      (setq sz1 (getdist "\nEnter width of old duct: " ) )
      (setq sz2 (getdist "\nEnter width of new duct: " ) )
      (setq SelSet (ssadd) ) ;; Create a placeholder
      (command "-layer" "make" "duct" "color" "blue" "duct" "")
      (setvar "CLAYER" "0" )
      (command "line" redpt1 (strcat "@0," (rtos sz1 )) "" )
      (setq SelSet (ssadd  (entlast) SelSet )) ;; Add last created object to SelSet
      (setvar "CLAYER" "Duct" ) ; <- will bomb if the layer do not exist
      (command "line" "" (strcat "@" (rtos (* sz1 1.10 ) ) "," (rtos(- sz2 sz1 ))) "" )
      (setq SelSet (ssadd  (entlast) SelSet )) ;; Add last created object to SelSet
      (setvar "CLAYER" "0" )
      (command "line" "" (strcat "@0," (rtos (* sz2 -1 ))) "" )
      (setq SelSet (ssadd  (entlast) SelSet )) ;; Add last created object to SelSet
      (setvar "CLAYER" "Duct" )
      (command "pline" "" redpt1 "" )
      (setq SelSet (ssadd  (entlast) SelSet )) ;; Add last created object to SelSet
      (command "line" redpt1 (strcat "@" (rtos (* sz1 1.10 ) ) ",0") "")
      (command "erase" (entlast) "")
      (setvar "clayer" "duct")
      (command "line" "" (strcat "@" (rtos (/ sz1 2)) ",0") "")
      (setq SelSet (ssadd  (entlast) SelSet )) ;; Add last created object to SelSet
      (command "copy" (entlast) "" redpt1 (strcat "@0," (rtos sz2)))
      (setq SelSet (ssadd  (entlast) SelSet )) ;; Add last created object to SelSet
      (command "select" SelSet "" ) ;; Activate SelSet in previous
      (command "rotate" SelSet "" redpt1 pause)
      (princ)
    )
    [ Moderator Action = ON ] What are [ CODE ] tags... [ Moderator Action = OFF ]
    Last edited by Opie; 2006-10-25 at 08:13 PM. Reason: [CODE] tags added, see Moderator Action

  5. #5
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Object selection using lisp

    Quote Originally Posted by ReachAndre
    OK everyone I have fixed my code so that it does the following:
    adds "makes" layer "Duct" to prevent bombing.
    Also Allows me to rotate all of my new object.
    Thanks to everyone for all your help.
    Great Andre, I just added some secure lines to your code
    Code:
    (defun c:reduct (/ currlay redpt1 sz1 sz2 SelSet )
      (if ; adding a check to find out if some indata is missing
        (and
          (setq currlay (getvar "CLAYER" ) )
          (setq redpt1 (getpoint "\nSelect insertion point of reducer: " ) )
          (setq sz1 (getdist "\nEnter width of old duct: " ) )
          (setq sz2 (getdist "\nEnter width of new duct: " ) )
        )
        (progn ; no indata is missing, run the progn
          (setq SelSet (ssadd) )
          (if (not (tblsearch "LAYER" "duct" )) ; check if layer duct is present
            (command "-layer" "make" "duct" "color" "blue" "duct" "") ; if not create the layer
            ( ) ; the layer exist, do nothing
          )
          (setvar "CLAYER" "0" )
          (command "line" redpt1 (strcat "@0," (rtos sz1 )) "" )
          (setq SelSet (ssadd  (entlast) SelSet ) )
          (setvar "CLAYER" "Duct" )
          (command "line" "" (strcat "@" (rtos (* sz1 1.10 ) ) "," (rtos(- sz2 sz1 ))) "" )
          (setq SelSet (ssadd  (entlast) SelSet ) )
          (setvar "CLAYER" "0" )
          (command "line" "" (strcat "@0," (rtos (* sz2 -1 ))) "" )
          (setq SelSet (ssadd  (entlast) SelSet ) )
          (setvar "CLAYER" "Duct" )
          (command "pline" "" redpt1 "" )
          (setq SelSet (ssadd  (entlast) SelSet ) )
          (command "line" redpt1 (strcat "@" (rtos (* sz1 1.10 ) ) ",0") "")
          (command "erase" (entlast) "") ; <-- WHY create then erase ? ? ?
          (setvar "clayer" "duct" )
          (command "line" "" (strcat "@" (rtos (/ sz1 2 )) ",0" ) "" )
          (setq SelSet (ssadd  (entlast) SelSet ) )
          (command "copy" (entlast) "" redpt1 (strcat "@0," (rtos sz2 )) )
          (setq SelSet (ssadd  (entlast) SelSet ) )
    ;;;   (command "select" SelSet "" ) ; I suppose you do not need this line anymore
          (command "rotate" SelSet "" redpt1 pause )
        )
        (princ ". .missing indata" ) ; some indata is missing
      )
      (princ)
    )
    : ) Happy Computing !

    everyone

Similar Threads

  1. Replies: 3
    Last Post: 2014-09-16, 06:29 PM
  2. Quantification Object Selection
    By Wish List System in forum NavisWorks - Wish List
    Replies: 0
    Last Post: 2013-11-15, 03:38 PM
  3. Lisp to add an MText object that contains an object property
    By sheila.bjerreskov717262 in forum AutoLISP
    Replies: 7
    Last Post: 2013-07-22, 05:58 PM
  4. Object Selection
    By dipen1979 in forum AutoCAD Customization
    Replies: 4
    Last Post: 2010-04-23, 03:49 AM
  5. OLE Object will not allow selection
    By jasontirone in forum AutoCAD General
    Replies: 1
    Last Post: 2005-01-21, 07:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •