Does anyone know of a LISP routine which will draw lines from the center/insertion point of multiple objects to 0,0,0 ?
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
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 ?
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
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)
)
@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 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.
Many thanks for your help 🙂
@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
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 )
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 ?
@greenj1 wrote: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 ?
No, they don't have a defined center or insertion point, just a string of vertices, and AutoCAD doesn't have any way to know directly whether they all fall on a common circular path. But if they're geometrically regular, a center can be calculated. This:
http://cadtips.cadalyst.com/2d-editing/convert-regular-polygons-circles
contains a method to do that. Appropriate parts could be transferred, but it would make the code a lot longer.
On the other hand, if the conversion to 3DPolylines is done by something that always does it in the same way, e.g. it always makes a regular polygon with the same number of vertices [or even just always an even number of vertices] in each conversion, then we can assume some of what that routine tests for, and a much simpler way could be devised to calculate their centers. Are they regular in some predictable way?
They dont seem to have any common propoerties. They start as circles then I import them into 3ds max and use bend and spherify modifers to turn the 2d layout into a spherical arrangement, then back into CAD where they become 3D polylines.
I guess I need to find an object which will retain a centre point or insertion point whne transfered between the two program. perhapes a point/node. Il see what I can find. Any suggestions welcome. Thanks for your help so far.
I found a MAXscript which placed point at the center of each spline (3d polylines in CAD) and bingo your lisp worked perfectly. Many thanks ! 🙂