Author Topic: Convert lisp from single selection use to selection set iteration  (Read 2200 times)

0 Members and 1 Guest are viewing this topic.

cgeorg13

  • Guest
Hello,

I've only been learning about lisps for the past month or so and from having a huge interest in AutoCAD and also in writing code I've absolutely fallen in love with the usefulness of lisp routines. From not having any prior experience to how to write lisp files I began extremely small (basically using it for strings of commands) but as I delved in further I started realizing all the capabilities.

So, enough for the background, I have been working on this file that reads into extended data (not sure if this is the correct terminology) but it is the data attached to the lines and blocks brought in through mapimport from shape files. This portion of the lisp is working nearly perfectly, at least I haven't been able to break it, but the whole reason I built this is to reduce the redundancy of clicking the lines/blocks/etc. and changing the linetype/color/layer by hand.

Now the only issue I have is that i have to run the lisp and click on every single line for it to work since I had/have no idea how to work with selectionsets to iterating through lists.

TLDR: To get to the point, I would like to have my lisp run on each individual entity of a selection set but I do not know how to pass the entity from the list to the routine properly with parameters (if thats even what i'm supposed to use).

ymg

  • Guest
Re: Convert lisp from single selection use to selection set iteration
« Reply #1 on: August 10, 2015, 03:03:10 PM »
cgeorg,

Your question is a bit too generic as it is.

Maybe if you post your code along with an example drawing.

ymg

cgeorg13

  • Guest
Re: Convert lisp from single selection use to selection set iteration
« Reply #2 on: August 10, 2015, 03:11:38 PM »
I was wondering if that was the case.

Attached is the lisp routine that I have built. I know there are plenty of thing that could be improved and any hints/tips are more than appreciated but my main goal is to allow this to be run on multiple lines using another lisp routine that builds a selection set and converts that selectionset into a list and then iterates through the list sending individual entities to be modified using the attached routine.

Thanks for any help!

EDIT: I forgot to mention that some of the code included in this routine have been gathered from around the interweb so I do not claim all of it as my own in any way! As you could probably tell since there is some list iteration methods used in it that i found worked for the specific use
« Last Edit: August 10, 2015, 03:24:03 PM by cgeorg13 »

cgeorg13

  • Guest
Re: Convert lisp from single selection use to selection set iteration
« Reply #3 on: August 10, 2015, 03:40:28 PM »
I am now attaching an example drawing that the lisp will be used for so that you can see it in action.

ymg

  • Guest
Re: Convert lisp from single selection use to selection set iteration
« Reply #4 on: August 10, 2015, 03:41:26 PM »
cgeorg,

I've not looked at the drawing yet, but I believe
simply wrapping your code in a repeat loop should work.

Code: [Select]
(setq ss (ssget '((0 . "INSERT"))))
  ;(setq ent (car (entsel "select object")))
  (repeat (setq i (sslength ss))
      (setq  ent (ssname ss (setq i (1- i))))

You may have to change the selection set filter to something
else than insert.

You will also need  to close the parentheses of the repeat loop
at the end of your main program

ymg

cgeorg13

  • Guest
Re: Convert lisp from single selection use to selection set iteration
« Reply #5 on: August 10, 2015, 03:46:15 PM »
Why does it always seem so much easier when its written out than when I'm thinking about it! haha thank you so much ymg I do believe that should work.

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Convert lisp from single selection use to selection set iteration
« Reply #6 on: August 10, 2015, 04:31:07 PM »
My tutorial on Selection Set Processing may help you - it gives a general overview of various methods of iterating over a selection set.

cgeorg13

  • Guest
Re: Convert lisp from single selection use to selection set iteration
« Reply #7 on: August 11, 2015, 06:58:49 AM »
Thanks a lot Lee Mac, your site has been the main reason for my progression on this routine, I'm hoping that sooner or later I'll be able to understand some of your more advanced routines easier and be able to incorporate what you do into my own routines.

You're a real inspiration!

Thanks a lot!

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Convert lisp from single selection use to selection set iteration
« Reply #8 on: August 11, 2015, 06:04:40 PM »
That's very kind of you to say! - I'm delighted to have inspired others in the process of learning & sharing something that I very much enjoy  :-)