Author Topic: Lisp to move objects  (Read 6378 times)

0 Members and 1 Guest are viewing this topic.

Anonymous

  • Guest
Lisp to move objects
« on: January 27, 2004, 08:27:18 PM »
Okay, I asked this question on the other forum, but got limitted response.  So I thought I  would try it here.  I need a lisp routine to move all objects within a polyline to a layer that is off.  Does anyone have a lisp that will do this or can someone please write one for me.  The lisp should create the layer then move all objects to this layer and then turn the layer off.  I guess the lisp would have to move any objects touching the polyline as well.  I need this to move survey points so I can do a proposed tin after I draw in a pond.  Is this possible?

Thanks in advance
Scott

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Lisp to move objects
« Reply #1 on: January 27, 2004, 09:11:33 PM »
Moving the objects and changing the layer is the easy part, building a selection set using the pline is another animal. Are these points just standard ACAD point or AECC points?
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Lisp to move objects
« Reply #2 on: January 27, 2004, 10:20:16 PM »
Hello Scott,  Welcome to The Swamp.

I thought you should know something about the comunity that we call The Swamp. First, writing "the code" is never the problem. The only problem is knowing what "you" want. (The design)  So, you have a couple of options here:

1. Tell us that you want to learn how to write code yourself, and we'll teach you.

2. Tell us exactly what you want and we can build it for you. (Within reason of course)

We would love to do either. Teaching/Learning is alot more fun for us, and that is why alot of us are here. (Just writing code is not fun anymore.  --Ive writen all that ive needed, just writing code now is boring to me. I come here to learn/teach. :P )

Later,
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Lisp to move objects
« Reply #3 on: January 27, 2004, 11:19:22 PM »
Quote from: Mark Thomas
building a selection set using the pline is another animal.


While this can be a bit tricky it is not real difficult. For example, using straight lisp, you can select any object or group of objects using

Code: [Select]

;window polygon
;all objects in a window
(ssget "_wp" pline_vertice_list)


or

Code: [Select]

;crossing polygon
;all objects crossed by and in the polygon
(ssget "_cp" pline_vertice_list)


Now to obtain the points, you need to get the DXF code 10 of all of the vertices. If you are using LWPolylines then this is a snap, if you are using regular polylines then it is a bit more coding.

Either way, you can take your pick.

Code: [Select]

;select a lwpolyline and put the entity data in a list
(setq lwpolyline_data_list (entget (car (entsel "\nSelect lwpolyline: "))))
;as long as there is another point in the data list
(while (setq point (member (assoc 10 lwpolyline_data_list)))
;add the point to the vertice list
(setq pline_vertice_list (append pline_vertice_list (list (cdr (assoc 10 point)))))
;then decrement the list so we don't get the same point twice
(setq lwpolyline_data_list (cdr lwpolyline_data_list))
)


or

Code: [Select]

;select a polyline and put the entity data in a list
(setq pline_data_list (entget (car (entsel "\nSelect polyline: "))))
;as long as we have not reached the end of the complex polyline object
(while (/= (cdr (assoc 0 pline_data_list)) "SEQEND")
;grab the point data of the vertice
(setq pline_vertice_list (append_pline_vertice_list (list (cdr (assoc 10 pline_data_list)))))
;then find the next entry in the complex polyline
(setq pline_data_list (entget (entnext (cdr (assoc -1 pline_data_list)))))


Now, you can select the pline, and select objects within the pline window.

Now you want to create a layer, you can simply entmake one, but instead of using a whole list of the data, lets just create one from an existing layer, like perhaps 0 since we always have one anyway.

Code: [Select]

;grab layer 0 data
(setq layer_list (entget (tblobjname "layer" "0")))
;recreate a list with a text layer
(setq layer_list (subst (cons 2 "NEWLAYERNAME")(assoc 2 layer_list) layer_list))
;now lets turn the layer off
(setq layer_list (subst (cons 62 (- 0 (abs(cdr (assoc 62 layer_list)))))(assoc 62 layer_list) layer_list))
;now lets actually create it
(entmake layer_list)


Of course there are other much simpler ways to create a layer, but by using this method, you become more familiar with HOW to modify the layer tables with pure lisp instead of relying strictly on the "command" interface.

Now I have added a few comments to let you know what happens in each of the different segments as well as giving some idea about how to go about building such a routine as you request.

In fact, I think that since I have made this little bit of code, I will post a module in the "show your stuff" section that will create any layer for you using the data you want as default.

Good luck
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp to move objects
« Reply #4 on: January 27, 2004, 11:32:46 PM »
K

You make it look so easy.

I'm looking for you other post.

CAB
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.

daron

  • Guest
Lisp to move objects
« Reply #5 on: January 28, 2004, 12:09:28 AM »
I might have a function for the objects in a pline selection that I wrote for RonJonP a while back. I'll have a look in the morning. In the mean time, Scott, don't take this the wrong way, but you'll notice there are a few more forums here than at cadalog. So, lisp questions should go in the "VLISP HACKERS" forum. That's what it's for. That's also the place to learn how to do it.

Scott

  • Bull Frog
  • Posts: 244
Lisp to move objects
« Reply #6 on: January 29, 2004, 05:08:57 PM »
Okay, I moved to the "Vlisp Hackers" forum.