Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Active Member
Posts: 6
Registered: ‎01-03-2013
Message 1 of 13 (406 Views)

Line from origin to object centers

406 Views, 12 Replies
01-03-2013 07:43 AM

Does anyone know of a LISP routine which will draw lines from the center/insertion point of multiple objects to 0,0,0 ?

*Expert Elite*
Posts: 2,427
Registered: ‎11-24-2009
Message 2 of 13 (395 Views)

Re: Line from origin to object centers

01-03-2013 09:24 AM in reply to: greenj1

greenj1 wrote:

Does anyone know of a LISP routine which will draw lines from the center/insertion point of multiple objects to 0,0,0 ?

May i ask as to whats the purpose of this exercise? just curious is all

Active Member
Posts: 6
Registered: ‎01-03-2013
Message 3 of 13 (393 Views)

Re: Line from origin to object centers

01-03-2013 09:30 AM in reply to: pbejse

I have a number of objects surrounding a sphere (thousands) which I would like to create lines from to the center of the sphere (co-ords 0,0,0) and then sweep the lines to create cylinders which I will boolean from the sphere.

Hope that makes sense. Any suggestions ?

*Expert Elite*
Posts: 2,667
Registered: ‎12-17-2004
Message 4 of 13 (379 Views)

Re: Line from origin to object centers

01-03-2013 09:56 AM in reply to: greenj1

greenj1, wrote:
I have a number of objects surrounding a sphere (thousands) which I would like to create lines from to the center of the sphere
(co-ords 0,0,0) and then sweep the lines to create cylinders which I will boolean from the sphere.
...

Objects are circles?

Henrique

Mentor
Posts: 173
Registered: ‎11-20-2011
Message 5 of 13 (369 Views)

Re: Line from origin to object centers

01-03-2013 10:27 AM in reply to: hmsilva

Here is my quick and dirty version of it.

(defun c:test (/ esel cp)
(setq esel (entsel "\nSelect circle: ")
cp (cdr (assoc 10 (entget (car esel))))
)
(command "line" cp "0,0,0" "")
(princ)
)

*Expert Elite*
Posts: 5,255
Registered: ‎09-13-2004
Message 6 of 13 (348 Views)

Re: Line from origin to object centers

01-03-2013 01:09 PM in reply to: greenj1

greenj1 wrote:

I have a number of objects surrounding a sphere (thousands) which I would like to create lines from to the center of the sphere (co-ords 0,0,0) and then sweep the lines to create cylinders which I will boolean from the sphere.

....

Based on these assumptions:

1.  The objects could be of multiple types but all with insertion or insertion-like points [below assumes Circles, Points, and Blocks, but you could include Text/Mtext or some other things, and/or remove one or more types];

2.  They might be in various orientations/coordinate systems [since they surround a sphere];

3.  You can select them collectively somehow [via window(s) or something], and want to do that rather than pick one at a time;

4.  You want the Lines on the current Layer;

then the following seems to do the Lines portion of what I think you're asking, in limited testing:

(setq ss (ssget '((0 . "CIRCLE,POINT,INSERT"))))
(repeat (sslength ss)
(setq ent (ssname ss 0))
(entmake
(list
'(0 . "LINE")
(cons 10 (trans (cdr (assoc 10 (entget ent))) ent 0))

;;; (trans) needed for Circles/Blocks when not in WCS
'(11 0.0 0.0 0.0)
); list
); entmake
(ssdel ent ss)
); repeat

Kent Cooper
Active Member
Posts: 6
Registered: ‎01-03-2013
Message 7 of 13 (319 Views)

Re: Line from origin to object centers

01-04-2013 01:38 AM in reply to: Kent1Cooper

Kent you are the man ! Perfect.

One last question. Would it be possible for the lines to go to 0,0 but stay relative to their z co-ordinates ?

I may need to keep the booleans horizontal for a cleaner print (I am 3D printing this model) as the resolution in the Z is far higher than x,y.

*Expert Elite*
Posts: 5,255
Registered: ‎09-13-2004
Message 8 of 13 (297 Views)

Re: Line from origin to object centers

01-04-2013 05:47 AM in reply to: greenj1

greenj1 wrote:

.... Would it be possible for the lines to go to 0,0 but stay relative to their z co-ordinates ?

....

If I understand what you're asking correctly [run Lines from the object point to 0,0 in XY but with both Line ends at the Z coordinate of the object point, in the WCS], this does that:

(setq ss (ssget '((0 . "CIRCLE,POINT,INSERT"))))
(repeat (sslength ss)
(setq
ent (ssname ss 0)
dxf10 (cons 10 (trans (cdr (assoc 10 (entget ent))) ent 0)); object point, in WCS
;;; (trans) needed for Circles/Blocks when not in WCS
); setq
(entmake
(list
'(0 . "LINE")
dxf10
(list 11 0.0 0.0 (cadddr dxf10)); use Z coordinate of object point
); list
); entmake
(ssdel ent ss)
); repeat

Kent Cooper
Mentor
Posts: 838
Registered: ‎12-26-2005
Message 9 of 13 (295 Views)

Re: Line from origin to object centers

01-04-2013 06:02 AM in reply to: greenj1

Try a mod of Kent's, and, note that circles with a x,y of 0,0 make the '0 length' LINEs:

(defun KC_liner ( / ss rq p00 cp ncp )
(setq p00 '(11 0.0 0.0 0.0)   rq 0
ss (ssget "x" '((0 . "CIRCLE,POINT,INSERT")))

' remove the "X"  to manually select the circle entities
(repeat (sslength ss)
(setq ent (ssname ss 0)  rq (1+ rq)
; (trans) needed for Circles/Blocks when not in WCS
cp (trans (cdr (assoc 10 (entget ent))) ent 0)
ncp (list (car cp) (cadr cp) 0.0) )
(entmake (list '(0 . "LINE") (cons 10 ncp) p00 ) ); entmake
(ssdel ent ss)
;;(p_"rq")(W_"  1")
); repeat
rq )

S
Active Member
Posts: 6
Registered: ‎01-03-2013
Message 10 of 13 (279 Views)

Re: Line from origin to object centers

01-04-2013 11:31 AM in reply to: greenj1

Kent once again thankyou, this works perfectly on the circles I have tested it on.

However my circles have to be converted into 3D polylines. The lisp does not seem to work on them !

I assumed they would have an inserition point or centre and it would work the same way.

Any suggestions ?

You are not logged in.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.