Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Line from origin to object centers

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
greenj1
1183 Views, 12 Replies

Line from origin to object centers

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

Tags (3)
12 REPLIES 12
Message 2 of 13
pbejse
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 🙂

 

 

Message 3 of 13
greenj1
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 ?

 

Message 4 of 13
hmsilva
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

EESignature

Message 5 of 13
smaher12
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)
)

Message 6 of 13
Kent1Cooper
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, AIA
Message 7 of 13
greenj1
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.

 

Many thanks for your help 🙂

Message 8 of 13
Kent1Cooper
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, AIA
Message 9 of 13
stevor
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
Message 10 of 13
greenj1
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 ?

Message 11 of 13
Kent1Cooper
in reply to: greenj1


@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?

Kent Cooper, AIA
Message 12 of 13
greenj1
in reply to: Kent1Cooper

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.

Message 13 of 13
greenj1
in reply to: greenj1

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 ! 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost