Author Topic: Multiple entity selection and another question  (Read 5703 times)

0 Members and 1 Guest are viewing this topic.

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Multiple entity selection and another question
« on: February 06, 2004, 01:39:45 PM »
This lisp takes a line that represents a steel beam and changes it to a polyline, makes the width 1.5", and changes the layer to "STR" and the linetype to "CENTER" instead of the center2 that STR is set to.  Problem, because I'm a n00b, is that I can only select 1 line per time I use the lisp.  I haven't gotten into how to select more than 1 entity without knowing exactly how many will be selected.  I've come across multiple selection like this before, but forgot where I saw it at.  I'm guessing that in order to do this, all items would be added to a list, then the routine would loop thru all items in the list.  Wrong?

The second question has to do with an "IF" statement.  What if one of the lines selected is already a polyline?  Is there a way to make it skip the first part of the "PEDIT" command and just adjust the width?

If I ask too much, just let me know.  I hate being a pain about things I could read up on, but don't have the time (and sometimes patience) for.   :twisted:

Code: [Select]

;;-----------------------------------------------
;;              STEELBEAM.lsp
;;        Created by Dominic Cesare
;;               02/05/2004
;;-----------------------------------------------
;;======================
;;    Start of Routine
;;======================

(defun c:STEELBEAM()


;;;--------  Select Object to change  -----------

(setq BEAM (entsel "\nSelect object to change : "))



;;;--------  Changing BEAM to a Polyline  -------

(command "PEDIT" BEAM "Y" "W" "1.5" "")
(setq BEAM (entlast))



;;;--------  Changing BEAM linetype  ------------

(command "CHANGE" BEAM "" "P" "LA" "STR" "LT" "CENTER" "")



;;;--------  Ending Routine Cleanly  ------------

(princ)

)
(princ)

;;======================
;;    End of Routine
;;======================

Craig

  • Guest
Multiple entity selection and another question
« Reply #1 on: February 06, 2004, 02:01:48 PM »
"entsel" only offers you one pick where "ssget" lets you pick multiple items.
I hope this is what your after for the first question. See if this will work for you.

Code: [Select]
;;-----------------------------------------------
;;              STEELBEAM.lsp
;;        Created by Dominic Cesare
;;               02/05/2004
;;-----------------------------------------------
;;======================
;;    Start of Routine
;;======================

(defun c:STEELBEAM()


;;;--------  Select Object to change  -----------
(prompt "\nSelect object to change : ");;;<------Changed
(setq BEAM (ssget));;;<------Changed



;;;--------  Changing BEAM to a Polyline  -------

(command "PEDIT" "m" BEAM "" "W" "1.5" "");;;<------Changed
;;(setq BEAM (entlast))



;;;--------  Changing BEAM linetype  ------------

(command "CHANGE" BEAM "" "P" "LA" "STR" "LT" "CENTER" "")



;;;--------  Ending Routine Cleanly  ------------

(princ)

)
(princ)

;;======================
;;    End of Routine
;;======================

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Multiple entity selection and another question
« Reply #2 on: February 06, 2004, 03:09:32 PM »
Had to add one "" into this line after the BEAM
Code: [Select]

(command "PEDIT" "m" BEAM "" "" "W" "1.5" "")


Then it worked fine.  The problem now is when it changes them to polylines, they become new entities, which is why I had this after it changed them to polylines...
Code: [Select]

(command "PEDIT" BEAM "Y" "W" "1.5" "")
(setq BEAM (entlast))


I had to reset BEAM to the newly created polyline.  Any way to select the multiple newly created polylines?

CADaver

  • Guest
Multiple entity selection and another question
« Reply #3 on: February 06, 2004, 03:13:51 PM »
Reverse the command order.  Do the CHANGE first, then do the PEDIT.

Craig

  • Guest
Multiple entity selection and another question
« Reply #4 on: February 06, 2004, 03:21:54 PM »
Dominic,

Email me your beam that your changing and might be able to create you a routine that can do all this selecting for you by just once click.
craigb@integdev.com

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Multiple entity selection and another question
« Reply #5 on: February 06, 2004, 03:44:10 PM »
HUZZAH!!!  Thanks CADaver...had a minor brain fart...shoulda thought of that one myself...mental note~~~>changes first... :twisted:

Craig...our company does all 2D construction drawings, so our "beams" are really just polylines.  It all works the way I want it to now, except for the "What if one of the lines selected is already a polyline? Is there a way to make it skip the first part of the "PEDIT" command and just adjust the width?"  Still gotta think about that one.

Code: [Select]

;;-----------------------------------------------
;;              STEELBEAM.lsp
;;        Created by Dominic Cesare
;;               02/05/2004
;;-----------------------------------------------
;;======================
;;    Start of Routine
;;======================

(defun c:STEELBEAM()


;;;--------  Select Object to change  -----------

(prompt "\nSelect object to change : ")
(setq BEAM (ssget))



;;;--------  Changing BEAM LA & LT  -------------

(command "CHANGE" BEAM "" "P" "LA" "STR" "LT" "CENTER" "")



;;;--------  Changing BEAM to a Polyline  -------

(command "PEDIT" "m" BEAM "" "" "W" "1.5" "")



;;;--------  Ending Routine Cleanly  ------------

(princ)

)
(princ)

;;======================
;;    End of Routine
;;======================

daron

  • Guest
Multiple entity selection and another question
« Reply #6 on: February 06, 2004, 03:45:11 PM »
I don't see how that's going to work with multiple selections. You've now used ssget to get multiple selections, but entlast takes the first item out of the LAST pickset. You need to loop through them to change them all. I really don't think entlast is what you want to use here.
Here is a code snippet that will work. It is by no means complete nor is it the best way to do it.
Code: [Select]

(setq ss (ssget)
      ssl (sslength ss)
      cnt 0)
(command ".layer" "m" "STR" "")
(repeat ssl
     (setq ename (ssname ss cnt)
  elist (entget ename)
  etype (cdr (assoc 0 elist))
  )
     (cond ((or (= etype "LINE") (= etype "ARC"))
   (command ".change" ename "" "P" "LA" "STR" "LT" "CENTER" ""
    ".pedit" ename "y" "W" "1.5" ""
    )
  )
  ((= etype "LWPOLYLINE")
   (command ".change" ename "" "P" "LA" "STR" "LT" "CENTER" ""
    ".pedit" ename "W" "1.5" "")
   )
  )
     (setq cnt (1+ cnt))
     )

Craig

  • Guest
Multiple entity selection and another question
« Reply #7 on: February 06, 2004, 03:55:51 PM »
Well, damn Daron beat me to the punch...I have been working... so I'm not gonna repost basically the same thing. My next suggestion was also to tell you to make it loop through each selected line and test it to see if it is a line on pline. As Daron has done, if it's a line do this, if its a pline do that. You should be able to use what hes given you.

CADaver

  • Guest
Multiple entity selection and another question
« Reply #8 on: February 06, 2004, 04:09:59 PM »
Okay, if you guys are looking to streamline it, why are we bothering with plines, why not just place it on the right layer and give the layer a lineweight?  Or am I missing something?

See if you make it a pline with a width factor, you can't do anything else with it as a refence file.  You're stuck with the weight and linetype.  But if you set the linetype and weight/color in the layer and build the elements on that layer (and BYLAYER) you still have the flexibility of diddling with the weight and linetype of that layer in an XREF.

daron

  • Guest
Multiple entity selection and another question
« Reply #9 on: February 06, 2004, 05:24:16 PM »
Are you asking me? I'm just giving him what he's asking for.  If he wants to learn lisp this way, it's a great way to learn it. I don't care how he does it.

CADaver

  • Guest
Multiple entity selection and another question
« Reply #10 on: February 06, 2004, 06:35:31 PM »
Not you specifically... just asking the um... ether?  :oops:

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Multiple entity selection and another question
« Reply #11 on: February 06, 2004, 06:56:59 PM »
The way we plot in the office is by color, not lineweight, so I'm just making things to do it the way I was showed how to do it when I was hired.  I'm by no means NOT open to suggestion.  I'll take help in any way it's offered.  I appreciate all the help so far.   :twisted:

CADaver

  • Guest
Multiple entity selection and another question
« Reply #12 on: February 07, 2004, 12:39:51 PM »
Quote from: Dommy2Hotty
The way we plot in the office is by color, not lineweight, so I'm just making things to do it the way I was showed how to do it when I was hired.  I'm by no means NOT open to suggestion.  I'll take help in any way it's offered.  I appreciate all the help so far.   :twisted:


Instead of diddling with PLINE width, create a beam layer with a linetype and color that plots to a width that's acceptable, then place your beams on that layer.  Then it doesn't matter if they are plines or lines or whatever.

So your function becomes just a layer change to the BEAM layer.

Keeping things BYLAYER greatly enhaces their flexibility when used as XREFs in other files.