Author Topic: lisp help  (Read 4321 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
lisp help
« on: January 13, 2005, 12:11:26 PM »
I am trying to write a lisp that allows me to pick and object, the layer is extracted from the object and, then use ssget with the layer extracted as a filter for selection. What am I dong wrong?
Code: [Select]

(defun c:ron2 (/ ent entity)
(setq ent (cdr (assoc 8 (entget (car (entsel "\nSelect object to set layer: "))))))
(setq entity (ssget '((8 . ent))))
)


Thanks,

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
lisp help
« Reply #1 on: January 13, 2005, 12:18:45 PM »
try this;
Code: [Select]
(ssget (list (cons 8 ent)))
TheSwamp.org  (serving the CAD community since 2003)

ronjonp

  • Needs a day job
  • Posts: 7529
lisp help
« Reply #2 on: January 13, 2005, 12:23:57 PM »
Thanks Mark :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
lisp help
« Reply #3 on: January 13, 2005, 12:25:13 PM »
Ron, try this:
Code: [Select]

(defun c:ron2 (/ ent entity)
  (if (setq ent (car (entsel "\nSelect object to set layer: ")))
    (progn
      (setq lay (cdr (assoc 8 (entget ent))))
      (setq ss (ssget (list (cons 8 lay))))
      )
    )
  )

Note that I started with the (entsel) and if something is selected continue.....this is because (entget) wail puke without a valid entry. Then I extract the layer, then when you are including a variable in a list you must expilicty create the list (no quoted ' lists) and create (cons) the portion with the variable.

HTH

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
lisp help
« Reply #4 on: January 13, 2005, 12:27:25 PM »
I really need to learn to type faster :(  Oh, and also type correctly....wail=will

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
lisp help
« Reply #5 on: January 13, 2005, 12:48:47 PM »
Quote from: Jeff_M
wail puke

now there's a mental image........ kinda reminds me of ........ never mind.  :D

 * there goes this thread *
TheSwamp.org  (serving the CAD community since 2003)

ronjonp

  • Needs a day job
  • Posts: 7529
lisp help
« Reply #6 on: January 13, 2005, 01:07:47 PM »
Thanks Jeff...I do like that method much better.


Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
lisp help
« Reply #7 on: January 13, 2005, 01:22:01 PM »
Well if you like that method (I like that little bit of error trapping in my code as well.)  You can build your own entget. For instance:
Code: [Select]
;;; Example function for getting an entity
(defun getent ( / sel)
  (while
    (not (setq sel (entsel))))
  sel
  )


That way in your code, if the end user misses his pick then you can be prepaired for it.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ronjonp

  • Needs a day job
  • Posts: 7529
lisp help
« Reply #8 on: January 13, 2005, 06:28:49 PM »
How do I get my selection set to be selected when I exit out of the program? Currently I am using the command _.PSELECT, but it seems if this command has not been run from the properties box first it does not work??



Code: [Select]
(defun c:qs (/ ent lay ss)
  (initget 1 "Block Layer")
  (setq P (getkword
   "\n Filter by (B)lock name or (L)ayer? "
 )
  )
  (if (= P "Block")
    (progn
 (setvar "highlight" 1)
 (setvar "grips" 1)
 (if (setq ent (car (entsel "\nSelect block to set name: ")))
   (progn
      (setq lay (cdr (assoc 2 (entget ent))))
      (setq ss (ssget (list (cons 2 lay))))
      )
   )
(command "_.PSELECT" ss "")
(princ)
)
)
  (if (= P "Layer")
    (progn
 (setvar "highlight" 1)
 (setvar "grips" 1)
 (if (setq ent (car (entsel "\nSelect object to set layer: ")))
    (progn
      (setq lay (cdr (assoc 8 (entget ent))))
      (setq ss (ssget (list (cons 8 lay))))
      )
   )
(command "_.PSELECT" ss "")
(princ)
)
)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
lisp help
« Reply #9 on: January 13, 2005, 08:27:51 PM »
Ron,
I took the liberty (Sorry!) of modifying your code to show how you can do what you want without duplicating yourself. However, the main thing that you need for the selection is to use the (sssetfirst) function, which is at the end of the routine:
Code: [Select]

(defun c:qs (/ ent lay ss fltr prmpt P)
  (initget 1 "Block Layer")
  (setq   P (getkword
       "\n Filter by (B)lock name or (L)ayer? "
     )
  )
  (cond ((= P "Block")(setq prmpt "\nSelect block to set name: "
   fltr 2))
((= P "Layer")(setq prmpt "\nSelect object to set layer: "
   fltr 8))
)
 (if (setq ent (car (entsel prmpt)))
   (progn
      (setq lay (cdr (assoc fltr (entget ent))))
      (if (setq ss (ssget (list (cons fltr lay))))
         (sssetfirst nil ss)
        )
      )
   )
  (princ)
)

ronjonp

  • Needs a day job
  • Posts: 7529
lisp help
« Reply #10 on: January 14, 2005, 09:45:11 AM »
Thanks Jeff  :D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Peter Jamtgaard

  • Guest
lisp help
« Reply #11 on: January 15, 2005, 10:15:25 AM »
This is the one I use

Peter Jamtgaard

Code: [Select]

(defun C:SSLAY (/ LAYER SSLYR)
 (setq LAYER (cdr (assoc 8 (entget (car (entsel))))));.ISOLATE LAYER
 (setq SSLYR (ssget "x" (list (cons 8 LAYER))))
 (princ LAYER)
 (prin1)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
lisp help
« Reply #12 on: January 15, 2005, 11:50:25 AM »
Here is more food for thought.
Code: [Select]
(if (setq ent (entsel "\n**  Select Layer to update or ENTER for all layers."))
  (setq lay (cdr(assoc 8 (entget(car ent)))))
  (setq lay "*")
) ; endif
(prompt (strcat "\n***  Layer filter set to "
          (cond ((= lay "*") "All Layers") (lay))))
(PRINC "\n****  Select objects to use or Press Enter for all.")
(IF (SETQ A (SSGET (LIST (cons 8 lay)))) ; user picked items
    (SETQ A (SSGET "P")) ; previous selection set  ;;  not sure I need this
    (SETQ A (SSGET "X" (LIST (cons 8 lay)))) ; all ddrawing
) ;_ end of if
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.